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

eth: when triggering a sync, check the head header TD, not block #20780

Merged
merged 1 commit into from
Mar 18, 2020

Conversation

karalabe
Copy link
Member

@karalabe karalabe commented Mar 18, 2020

This PR fixes a regression introduced in v1.9.0 by the freezer, unfortunately that regression was completely silent and was surfaced only by b9c90c5.

The symptom is when a miner is started against an empty database, instantly mines a block, and then fast syncs... crashing. Since the node mined a block, it's current head block is 1, with hashA. Fast sync will start and dump a whole lot of data into the freezer/ancient database (including block 1, with hashB). Later on, any code that accesses the currentBlock, will want data belonging to hashA, but the freezer only has data belonging to hashB.

The crash is due to the sync code accessing the current block and then it's TD, which is returned as nil, since the hash doesn't match (the crash is due to b9c90c5 actually validating the hash, previously we trusted it blindly).

The fix is to change the sync code to base it's TD retrieval on the head header, instead of the head block. This is actually the correct behavior as throughout fast sync the current block is the genesis, we've been doing it wrong for 4 years. This will also solve the panic because the head header is either the actual one from the ancient db, or if it's newer than the ancient limit then we'll always have it.

Fixes #20770, #20614

@karalabe karalabe force-pushed the fix-eth-mine-sync-race branch from 7882fe3 to dc6e98d Compare March 18, 2020 12:35
@karalabe karalabe added this to the 1.9.13 milestone Mar 18, 2020
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

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.

Clique miner + fresh start + fast sync = panic
2 participants