ethereumjs / ethereumjs-monorepo

Monorepo for the Ethereum VM TypeScript Implementation
2.6k stars 755 forks source link

Running geth README example compromises geth database #697

Closed holgerd77 closed 1 year ago

holgerd77 commented 6 years ago

When I run the geth iterator example from the README with geth 1.8.14-stable and having synced some blocks with:

geth --datadir="./test-chain" --syncmode="full"

...I am ending up with a compromised geth database, so running the geth sync command from above again gives me the following error stack (shortened):

INFO [08-29|11:45:56.103] Initialising Ethereum protocol           versions="[63 62]" network=1
WARN [08-29|11:45:56.104] Head state missing, repairing chain      number=0 hash=d4e567…cb8fa3
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x447e3fa]

goroutine 1 [running]:
github.com/ethereum/go-ethereum/core/types.(*Block).Root(...)
    /private/tmp/ethereum-20180829-39282-1s822bo/build/_workspace/src/github.com/ethereum/go-ethereum/core/types/block.go:315
github.com/ethereum/go-ethereum/core.(*BlockChain).repair(0xc000018000, 0xc0004e61e0, 0xc0004e6248, 0x4)
    /private/tmp/ethereum-20180829-39282-1s822bo/build/_workspace/src/github.com/ethereum/go-ethereum/core/blockchain.go:429 +0x4a
github.com/ethereum/go-ethereum/core.(*BlockChain).loadLastState(0xc000018000, 0x0, 0xc0002d4360)

This is also happening when removing the iterator(...) call from the example code.

holgerd77 commented 6 years ago

Hi @vpulim, can you have a look at this since I think that this might be a (severe) bug in the blockchain library?

vpulim commented 6 years ago

Hi @holgerd77, I'm having a hard time reproducing this. Can you send me any more details that might help? Node version, leveldown version, how many blocks are synced in your geth db... Does this happen consistently with a fresh geth db? Also, can you share the exact javascript code you are running, as well as your package-lock.json file.

In general, the geth DB structure is fairly complex and I wouldn't be surprised if geth failed to read the DB after an ethereumjs-blockchain write operation is performed (we should explicitly state this as a warning in the README). However, it shouldn't break the DB if all we're doing is iterating, except to write some new keys to track the VM iterator heads, so that is definitely a bug.

holgerd77 commented 6 years ago

Have added a warning to the README on this along with the PR for an v.3.3.0 release: https://github.com/ethereumjs/ethereumjs-blockchain/pull/72

holgerd77 commented 1 year ago

Along the latest README updates I have removed the Geth example since it was outdated anyhow, will close here.