Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: add read-only option to database #22407

Merged
merged 13 commits into from
Mar 22, 2021
Merged

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Mar 2, 2021

This PR introduces the "Read-Only" database and fixes a few issues in the db commands.

Test cases

MakeChainDatabase

  • importPreimages
  • exportPreimages
  • dump
  • inspect
  • dbStats
  • dbCompact
  • dbGet
  • dbDelete
  • dbPut
  • pruneState
  • verifyState
  • traverseState
  • traverseRawState

MakeChain

  • importChain
  • exportChain

cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
@rjl493456442
Copy link
Member Author

@holiman it's rebased. Please take another look

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@holiman
Copy link
Contributor

holiman commented Mar 15, 2021

This PR also closes #22498

@holiman
Copy link
Contributor

holiman commented Mar 15, 2021

Oh wait

[user@work go-ethereum]$ ./build/bin/geth   --yolov3 snapshot prune-state
INFO [03-15|14:30:05.932] Maximum peer count                       ETH=50 LES=0 total=50
INFO [03-15|14:30:05.933] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [03-15|14:30:05.933] Set global gas cap                       cap=25000000
INFO [03-15|14:30:05.933] Allocated cache and file handles         database=/home/user/.ethereum/yolo-v3/geth/chaindata cache=512.00MiB handles=262144 readonly=true
INFO [03-15|14:30:05.968] Opened ancient database                  database=/home/user/.ethereum/yolo-v3/geth/chaindata/ancient
INFO [03-15|14:30:05.975] Persisted trie from memory database      nodes=365 size=52.16KiB time="850.996µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
CRIT [03-15|14:30:05.976] Failed to store chain config             err="leveldb: read-only mode"

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, previously, func MakeChain(ctx *cli.Context, stack *node.Node, readOnly bool) (chain *core.BlockChain, chainDb ethdb.Database) { existed and took a readOnly boolean. However, it was mostly ignored, just stopped the tx indexing from happening.
As a result, some operations call it with readOnly set to true, snapshot prune-state is one of them. It now fails, because the readOnly is interpreted strictly (correctly).
I guess we need some way to say "I do want to modify the db, but please do not spin up tx indexer/unindexer or snapshot generator/wiper, just the core stuff".

@holiman
Copy link
Contributor

holiman commented Mar 15, 2021

Here are the callers of MakeChain, and whther they set readOnly or not:

pruneState (true) (not ok)
exportChain(true) (ok)
verifyState(true) (ok)
traverseState(true) (ok)
copyDb(false) (ok, but we should remove this command entirely. I'll make a PR)
dump(true) (ok)
importChain(false) (ok)
traverseRawState(true) (ok)

So afaict it's only pruneState which is broken

@rjl493456442
Copy link
Member Author

thanks, I will check the pruner command and fix it

@holiman
Copy link
Contributor

holiman commented Mar 16, 2021

There are several PR's that touch the same things, which maybe should be merged into one?

@rjl493456442
Copy link
Member Author

It's still problematic. The readonly notion should also be passed into the freezer. Otherwise the background migrator will be enabled by default.

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I just need do a bit more testing before I click the approve

@holiman
Copy link
Contributor

holiman commented Mar 19, 2021

./build/bin/geth   --yolov3 dump 0
INFO [03-19|21:17:48.930] Maximum peer count                       ETH=50 LES=0 total=50
INFO [03-19|21:17:48.930] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [03-19|21:17:48.930] Set global gas cap                       cap=25000000
INFO [03-19|21:17:48.931] Allocated cache and file handles         database=/home/user/.ethereum/yolo-v3/geth/chaindata cache=512.00MiB handles=262144 readonly=true
INFO [03-19|21:17:48.943] Opened ancient database                  database=/home/user/.ethereum/yolo-v3/geth/chaindata/ancient readonly=true
INFO [03-19|21:17:48.949] Persisted trie from memory database      nodes=365 size=52.16KiB time="813.222µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
CRIT [03-19|21:17:48.949] Failed to store chain config             err="leveldb: read-only mode"

@rjl493456442
Copy link
Member Author

./build/bin/geth   --yolov3 dump 0
INFO [03-19|21:17:48.930] Maximum peer count                       ETH=50 LES=0 total=50
INFO [03-19|21:17:48.930] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [03-19|21:17:48.930] Set global gas cap                       cap=25000000
INFO [03-19|21:17:48.931] Allocated cache and file handles         database=/home/user/.ethereum/yolo-v3/geth/chaindata cache=512.00MiB handles=262144 readonly=true
INFO [03-19|21:17:48.943] Opened ancient database                  database=/home/user/.ethereum/yolo-v3/geth/chaindata/ancient readonly=true
INFO [03-19|21:17:48.949] Persisted trie from memory database      nodes=365 size=52.16KiB time="813.222µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
CRIT [03-19|21:17:48.949] Failed to store chain config             err="leveldb: read-only mode"

Looks like the datadir is empty, so that the initialization is enabled by default. I think it should be the correct behavior? Previously we have lots of "underlying" database operations. Now the policy is a bit stricter.

@holiman
Copy link
Contributor

holiman commented Mar 20, 2021

It looks like that, yes, but it's not that simple, for some reason:

[user@work go-ethereum]$ ./build/bin/geth --yolov3
INFO [03-20|10:52:46.005] Starting Geth on YOLOv3 testnet... 
INFO [03-20|10:52:46.005] Bumping default cache on mainnet         provided=1024 updated=4096
WARN [03-20|10:52:46.005] Sanitizing cache to Go's GC limits       provided=4096 updated=2584
INFO [03-20|10:52:46.006] Maximum peer count                       ETH=50 LES=0 total=50
INFO [03-20|10:52:46.006] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [03-20|10:52:46.017] Set global gas cap                       cap=25000000
INFO [03-20|10:52:46.017] Allocated trie memory caches             clean=387.00MiB dirty=646.00MiB
INFO [03-20|10:52:46.017] Allocated cache and file handles         database=/home/user/.ethereum/yolo-v3/geth/chaindata cache=1.26GiB handles=262144
INFO [03-20|10:52:46.071] Opened ancient database                  database=/home/user/.ethereum/yolo-v3/geth/chaindata/ancient readonly=false
INFO [03-20|10:52:46.080] Persisted trie from memory database      nodes=365 size=52.16KiB time="617.076µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-20|10:52:46.081] Initialised chain configuration          config="{ChainID: 34180983699157880 Homestead: 0 DAO: <nil> DAOSupport: true EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: <nil>, Berlin: <nil>, YOLO v3: 0, Engine: clique}"
INFO [03-20|10:52:46.088] Initialising Ethereum protocol           network=34180983699157880 dbversion=8
INFO [03-20|10:52:46.097] Loaded most recent local header          number=159976 hash="0b6a18…004cf1" td=319953 age=6d21h8m
INFO [03-20|10:52:46.097] Loaded most recent local full block      number=159976 hash="0b6a18…004cf1" td=319953 age=6d21h8m
INFO [03-20|10:52:46.097] Loaded most recent local fast block      number=159976 hash="0b6a18…004cf1" td=319953 age=6d21h8m
INFO [03-20|10:52:46.097] Loaded last fast-sync pivot marker       number=142523
INFO [03-20|10:52:46.127] Loaded local transaction journal         transactions=0 dropped=0
INFO [03-20|10:52:46.127] Regenerated local transaction journal    transactions=0 accounts=0
WARN [03-20|10:52:46.127] Switch sync mode from fast sync to full sync 
INFO [03-20|10:52:46.129] Starting peer-to-peer node               instance=Geth/v1.10.2-unstable-4ae81351-20210319/linux-amd64/go1.15.5
INFO [03-20|10:52:46.227] New local node record                    seq=130 id=31ff7829b55cb7b7 ip=127.0.0.1 udp=30303 tcp=30303
INFO [03-20|10:52:46.228] IPC endpoint opened                      url=/home/user/.ethereum/yolo-v3/geth.ipc
INFO [03-20|10:52:46.229] Started P2P networking                   self=enode://56fa93217979957d3b70123127566d39321bf4ea5bed54f225ec4e3dd2077b1f2e0fa0cd35ccb965ab0d803050d2f60e9dbeb7cb702cab2c8e42d22ec31bbc22@127.0.0.1:30303
^CINFO [03-20|10:52:46.437] Got interrupt, shutting down... 
INFO [03-20|10:52:46.437] IPC endpoint closed                      url=/home/user/.ethereum/yolo-v3/geth.ipc
INFO [03-20|10:52:46.437] Ethereum protocol stopped 
INFO [03-20|10:52:46.437] Transaction pool stopped 
INFO [03-20|10:52:46.438] Writing cached state to disk             block=159976 hash="0b6a18…004cf1" root="bd763e…650a03"
INFO [03-20|10:52:46.438] Persisted trie from memory database      nodes=0   size=0.00B    time="4.664µs"   gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-20|10:52:46.438] Writing cached state to disk             block=159975 hash="aa5a89…9ea7e1" root="bd763e…650a03"
INFO [03-20|10:52:46.438] Persisted trie from memory database      nodes=0   size=0.00B    time="2.24µs"    gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-20|10:52:46.441] Writing cached state to disk             block=159849 hash="a1c52f…6f019e" root="bd763e…650a03"
INFO [03-20|10:52:46.441] Persisted trie from memory database      nodes=0   size=0.00B    time="6.793µs"   gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-20|10:52:46.441] Writing snapshot state to disk           root="71d42a…6e7b5f"
INFO [03-20|10:52:46.441] Persisted trie from memory database      nodes=0   size=0.00B    time="1.992µs"   gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [03-20|10:52:46.441] Writing clean trie cache to disk         path=/home/user/.ethereum/yolo-v3/geth/triecache threads=6
INFO [03-20|10:52:46.443] Persisted the clean trie cache           path=/home/user/.ethereum/yolo-v3/geth/triecache elapsed=1.164ms
INFO [03-20|10:52:46.443] Blockchain stopped 
[user@work go-ethereum]$ ./build/bin/geth --yolov3 dump 0
INFO [03-20|10:52:51.820] Maximum peer count                       ETH=50 LES=0 total=50
INFO [03-20|10:52:51.820] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [03-20|10:52:51.820] Set global gas cap                       cap=25000000
INFO [03-20|10:52:51.821] Allocated cache and file handles         database=/home/user/.ethereum/yolo-v3/geth/chaindata cache=512.00MiB handles=262144 readonly=true
INFO [03-20|10:52:51.836] Opened ancient database                  database=/home/user/.ethereum/yolo-v3/geth/chaindata/ancient readonly=true
INFO [03-20|10:52:51.842] Persisted trie from memory database      nodes=365 size=52.16KiB time=1.050828ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
CRIT [03-20|10:52:51.843] Failed to store chain config             err="leveldb: read-only mode"

@rjl493456442
Copy link
Member Author

@holiman I think introducing the "Read-Only" chain is an immature idea. The blockchain is self-contained. It has a lot of recovery logic:

  • init the indexes from the ancient database
  • rewind head for recovering from the crash
  • fix the snapshot for recovering from the crash
  • init/fix the genesis or chain config

All of these will require the disk write permission.


So instead of fixing the MakeChain, I use the MakeChainDatabase as the replacement. I realize that in the most of the commands, we only need the database handler. While for the database it's super easy/nice to control the permission directly.

So I think this version is safer and easier to review. It's just too dangerous to introduce the "read-only" to chain without enough refactoring.

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman merged commit 0c70b83 into ethereum:master Mar 22, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
* all: add read-only option to database

* all: fixes tests

* cmd/geth: migrate flags

* cmd/geth: fix the compact

* cmd/geth: fix the format

* cmd/geth: fix log

* cmd: add chain-readonly

* core: add readonly notion to freezer

* core/rawdb: add log

* core/rawdb: fix freezer close

* cmd: fix

* cmd, core: construct db

* core: update tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants