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

core/state/snapshot: fix panic on missing parent #22551

Merged
merged 1 commit into from
Mar 22, 2021

Conversation

karalabe
Copy link
Member

When building a snapshot on top of a parent, the parent may occasionally be missing (if there are many blocks imported whilst simultaneously mining a new block). In that case, the current code panics because the path that checks for missing parent already makes an interface conversion before nil check.

panic: interface conversion: interface is nil, not snapshot.snapshot
goroutine 92 [running]:
github.com/ethereum/go-ethereum/core/state/snapshot.(*Tree).Update(0xc02b51d100, 0x1881189dfd6131c7, 0x65806745df63f116, 0xeeb17030c8ccf09f, 0x8be3502ada3d5705, 0xf3286cf6afe5e4da, 0xebc572ab54e816af, 0x6e0e89ca9372a1c2, 0xaa34de51b47e9b97, 0xc087c97ce0, ...)
	github.com/ethereum/go-ethereum/core/state/snapshot/snapshot.go:286 +0xff
github.com/ethereum/go-ethereum/core/state.(*StateDB).Commit(0xc024b59380, 0xc03f27da01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	github.com/ethereum/go-ethereum/core/state/statedb.go:970 +0x74c
github.com/ethereum/go-ethereum/core.(*BlockChain).writeBlockWithState(0xc0000ab900, 0xc06de0d170, 0xc01aa78680, 0x33, 0x33, 0xc0436bbf00, 0x1a, 0x20, 0xc024b59380, 0xc031685001, ...)
	github.com/ethereum/go-ethereum/core/blockchain.go:1530 +0x76c
github.com/ethereum/go-ethereum/core.(*BlockChain).WriteBlockWithState(0xc0000ab900, 0xc06de0d170, 0xc01aa78680, 0x33, 0x33, 0xc0436bbf00, 0x1a, 0x20, 0xc024b59380, 0x7b4000000d901, ...)
	github.com/ethereum/go-ethereum/core/blockchain.go:1498 +0x111
github.com/ethereum/go-ethereum/miner.(*worker).resultLoop(0xc025218240)
	github.com/ethereum/go-ethereum/miner/worker.go:626 +0x80a
created by github.com/ethereum/go-ethereum/miner.newWorker
	github.com/ethereum/go-ethereum/miner/worker.go:229 +0x585
panic: interface conversion: interface is nil, not snapshot.snapshot

The fix is to do the nil check first and only afterwards to cast to the snapshot interface.

@karalabe karalabe added this to the 1.10.2 milestone Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants