Navigation Menu

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

blockchain: fix flaw in block import #19986

Merged
merged 3 commits into from Aug 21, 2019
Merged

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Aug 20, 2019

This PR fixes a problem which we've seen on the monitoring nodes

WARN [08-20|11:36:00.080] Reduced total capacity                   maxFreePeers=153
INFO [08-20|11:36:07.994] Imported new chain segment               blocks=1  txs=104  mgas=8.003  elapsed=9.274s    mgasps=0.863   number=8386921 hash=5c37c8…03da03 age=15m52s   dirty=201.49MiB
INFO [08-20|11:36:16.709] Deep froze chain segment                 blocks=10 elapsed=1.344s    number=8296920 hash=19882b…ac6077
INFO [08-20|11:36:26.607] Imported new chain segment               blocks=1  txs=107  mgas=7.828  elapsed=18.613s   mgasps=0.421   number=8386922 hash=9e95e0…7fcadd age=16m4s    dirty=201.60MiB
INFO [08-20|11:36:46.553] Imported new chain segment               blocks=3  txs=290  mgas=23.962 elapsed=19.945s   mgasps=1.201   number=8386925 hash=626756…e38e0f age=16m10s   dirty=201.54MiB
INFO [08-20|11:36:55.482] Imported new chain segment               blocks=2  txs=266  mgas=15.963 elapsed=8.929s    mgasps=1.788   number=8386927 hash=3f1233…0d2a07 age=15m53s   dirty=201.96MiB
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x522a9e]
goroutine 6200928 [running]:
math/big.(*Int).Cmp(0xc068601b20, 0x0, 0xb29f47668c56a78d)
	/usr/local/go/src/math/big/int.go:326 +0x2e
github.com/ethereum/go-ethereum/core.(*BlockChain).insertSideChain(0xc000222000, 0xc0bc3b46c0, 0xc0b2973c00, 0x4, 0xc0b2973b00, 0x4, 0x4, 0x2, 0x1, 0xc1465c8f60, ...)
	/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/core/blockchain.go:1786 +0x1303
github.com/ethereum/go-ethereum/core.(*BlockChain).insertChain(0xc000222000, 0xc12bee5ec8, 0x1, 0x1, 0x1c3dd01, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/core/blockchain.go:1525 +0x4874
github.com/ethereum/go-ethereum/core.(*BlockChain).InsertChain(0xc000222000, 0xc12bee5ec8, 0x1, 0x1, 0x0, 0x0, 0x0)
	/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/core/blockchain.go:1431 +0xd61
github.com/ethereum/go-ethereum/eth.NewProtocolManager.func3(0xc12bee5ec8, 0x1, 0x1, 0x2227501, 0xc0bd2f6bd0, 0x1e85cfc0628d07e0)
	/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/eth/handler.go:181 +0x73f
github.com/ethereum/go-ethereum/eth/fetcher.(*Fetcher).insert.func1(0xc01cb54d00, 0x3c3b7b00c197e6c0, 0x1b409f6a1917b835, 0x1e85cfc0628d07e0, 0x27e55d3693e5bb46, 0xc0bc3b46c0, 0xc0a04bb000, 0x10)
	/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/eth/fetcher/fetcher.go:667 +0x571
created by github.com/ethereum/go-ethereum/eth/fetcher.(*Fetcher).insert
	/go-ethereum/build/_workspace/src/github.com/ethereum/go-ethereum/eth/fetcher/fetcher.go:641 +0x2bc
INFO [08-20|11:36:57.600] Starting pprof server                    addr=http://0.0.0.0:6060/debug/pprof
INFO [08-20|11:36:57.600] Bumping default cache on mainnet         provided=1024 updated=4096 

The testcase added in this PR triggers the same bug. For some reason, blockchain is given a chunk of blocks that are already canon and imported, but have been pruned already (more than 128 blocks back). Pruned but canon blocks make the sidechain import loop continue early, and unless a non-canon block is found, the loop ends without setting externTd, leaving it nil, which causes a seg violation later on.

core/blockchain_test.go Outdated Show resolved Hide resolved
core/blockchain_test.go Outdated Show resolved Hide resolved
core/blockchain_test.go Outdated Show resolved Hide resolved
Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

SGTM

@karalabe karalabe added this to the 1.9.3 milestone Aug 21, 2019
@karalabe karalabe merged commit 4aee0d1 into ethereum:master Aug 21, 2019
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.

None yet

4 participants