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, accounts, eth, trie: handle genesis state missing #28171

Merged
merged 11 commits into from Sep 28, 2023

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Sep 21, 2023

This pull request addresses scenarios where the associated head state is missing.

In the original design, the chain head would never be stateless because the genesis state was always considered present, and we could always rewind the chain back to the genesis block. However, in path mode, the genesis state may have already been overwritten by the state syncer, making recovery impossible.

As a result, it is important to ensure that even when the chain is in a stateless condition, everything continues to function smoothly until the state synchronization process is fully completed.

The lazy initialization is introduces to txpool if the chain is stateless, it's looks a bit ugly, but no idea how to make it elegant.

A few scenarios need to be tested:

  • Restart node in the middle of snap sync
    • Path mode
    • Hash mode
  • Rewind a snap sync'd node below the pivot point
    • Path mode
    • Hash mode
  • Start snap sync, then restart with full-sync mode when the sync is not finished
    • Path mode
    • Hash mode
  • Call txpool API when node is not synced

eth/backend.go Outdated Show resolved Hide resolved
if err == nil {
h.enableSyncedFeatures() // Mark initial sync done on any fetcher import
}
return n, err
Copy link
Member Author

Choose a reason for hiding this comment

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

The node will only be marked as initialized after the initial sync cycle. There are some behavioral changes in legacy un-merged chain, but it's fine, just do a tiny full-sync instead of a single block fetch.

Copy link
Member

Choose a reason for hiding this comment

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

What happens with empty networks that are just starting up? They can't do any type of sync because there's nothing yet to sync

Copy link
Member

Choose a reason for hiding this comment

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

Ah this is specifically the fetcher path. Still in that case, what happens if my node never does a sync cycle because it's always in sync and connected?

Copy link
Member Author

Choose a reason for hiding this comment

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

enableSyncedFeatures will be called if (1) mining is enabled or (2) we successfully do a forkchoiceUpdate. Basically block producer will be marked as synced to generate blocks and it will trigger other nodes to sync.

@rjl493456442
Copy link
Member Author

Btw, for the reviewers, https://github.com/ethereum/go-ethereum/blob/master/eth/handler.go#L248 here snapSync is used to determine if new blocks should be accepted by block fetcher or not. It looks a bit confusing, can I change it to use synced flag, which means reject any block insertion while node is not fully synced?

eth/handler.go Outdated Show resolved Hide resolved
core/txpool/txpool.go Outdated Show resolved Hide resolved
trie/database.go Outdated Show resolved Hide resolved
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.

LGTM

@karalabe karalabe added this to the 1.13.2 milestone Sep 28, 2023
@karalabe karalabe merged commit 73f5bcb into ethereum:master Sep 28, 2023
2 checks passed
tyler-smith pushed a commit to blocknative/go-ethereum that referenced this pull request Oct 9, 2023
* core, accounts, eth, trie: handle genesis state missing

* core, eth, trie: polish

* core: manage txpool subscription in mainpool

* eth/backend: fix test

* cmd, eth: fix test

* core/rawdb, trie/triedb/pathdb: address comments

* eth, trie: address comments

* eth: inline the function

* eth: use synced flag

* core/txpool: revert changes in txpool

* core, eth, trie: rename functions
tyler-smith pushed a commit to blocknative/go-ethereum that referenced this pull request Oct 12, 2023
* core, accounts, eth, trie: handle genesis state missing

* core, eth, trie: polish

* core: manage txpool subscription in mainpool

* eth/backend: fix test

* cmd, eth: fix test

* core/rawdb, trie/triedb/pathdb: address comments

* eth, trie: address comments

* eth: inline the function

* eth: use synced flag

* core/txpool: revert changes in txpool

* core, eth, trie: rename functions
tyler-smith pushed a commit to blocknative/go-ethereum that referenced this pull request Oct 12, 2023
* core, accounts, eth, trie: handle genesis state missing

* core, eth, trie: polish

* core: manage txpool subscription in mainpool

* eth/backend: fix test

* cmd, eth: fix test

* core/rawdb, trie/triedb/pathdb: address comments

* eth, trie: address comments

* eth: inline the function

* eth: use synced flag

* core/txpool: revert changes in txpool

* core, eth, trie: rename functions
siosw pushed a commit to SpecularL2/go-ethereum that referenced this pull request Oct 16, 2023
* core, accounts, eth, trie: handle genesis state missing

* core, eth, trie: polish

* core: manage txpool subscription in mainpool

* eth/backend: fix test

* cmd, eth: fix test

* core/rawdb, trie/triedb/pathdb: address comments

* eth, trie: address comments

* eth: inline the function

* eth: use synced flag

* core/txpool: revert changes in txpool

* core, eth, trie: rename functions
0x366 pushed a commit to Dexcelerate/go-ethereum that referenced this pull request Nov 8, 2023
* core, accounts, eth, trie: handle genesis state missing

* core, eth, trie: polish

* core: manage txpool subscription in mainpool

* eth/backend: fix test

* cmd, eth: fix test

* core/rawdb, trie/triedb/pathdb: address comments

* eth, trie: address comments

* eth: inline the function

* eth: use synced flag

* core/txpool: revert changes in txpool

* core, eth, trie: rename functions
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
* core, accounts, eth, trie: handle genesis state missing

* core, eth, trie: polish

* core: manage txpool subscription in mainpool

* eth/backend: fix test

* cmd, eth: fix test

* core/rawdb, trie/triedb/pathdb: address comments

* eth, trie: address comments

* eth: inline the function

* eth: use synced flag

* core/txpool: revert changes in txpool

* core, eth, trie: rename functions
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
sduchesneau pushed a commit to streamingfast/go-ethereum that referenced this pull request Feb 26, 2024
core, accounts, eth, trie: handle genesis state missing (ethereum#28171)

 Conflicts:
  core/blockchain.go
We made many changes in setHeadBeyondRoot. upstream removed assumption
that genesis state is always in the db. Accepted both changes
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

2 participants