-
Notifications
You must be signed in to change notification settings - Fork 20.8k
core, eth/downloader: implement pruning mode sync #31414
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
Conversation
916eaf0
to
d3b8b71
Compare
386d78f
to
5dd27fd
Compare
Snap sync with
|
Snap sync with
|
f954c7f
to
6327d1e
Compare
Sorry, I accidentally closed this PR instead of my own. |
6327d1e
to
26e6cc1
Compare
2ae9569
to
15e5c08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't run this, but it did run successfully before.
One aspect of this change that took me a while to understand is the removal of the sidechain deletion in InsertReceiptChain
. With these changes, we will now insert headers, block bodies, and receipts in a single batch directly into the freezer. We previously had quite a bit of code to handle divergence between the downloader header chain and the body items, i.e. there could be sidechains during sync. By combining the writes into a single batch, this condition can no longer occur, and thus it is safe to remove the cleanup logic.
This pull request introduces new sync logic for pruning mode. The downloader will now skip insertion of block bodies and receipts before the configured history cutoff point. Originally, in snap sync, the header chain and other components (bodies and receipts) were inserted separately. However, in Proof-of-Stake, this separation is unnecessary since the sync target is already verified by the CL. To simplify the process, this pull request modifies `InsertReceiptChain` to insert headers along with block bodies and receipts together. Besides, `InsertReceiptChain` doesn't have the notion of reorg, as the common ancestor is always be found before the sync and extra side chain is truncated at the beginning if they fall in the ancient store. The stale canonical chain flags will always be rewritten by the new chain. Explicit reorg logic is no longer required in `InsertReceiptChain`.
These were caused by crossed merges of recent PRs ethereum#31414 and ethereum#31361
This pull request introduces new sync logic for pruning mode.
Pruning Mode:
Geth now supports two chain history modes (
-history.chain
):all
andpostmerge
.all
(default): Retains the entire historical chain as usual.postmerge
: Discards chain segments before the configured cutoff point and skips them during synchronization.The cutoff point is defined as the first block after the Paris fork and will be dynamically
adjusted in the future.
Sync mechanism with chain cutoff
A consensus has been reached across different EL implementations that chain
segments before the merge point will be pruned by default in the near future.
This means these segments—specifically block bodies and receipts—will no longer
be available in the P2P network. As a result, these components must be skipped
during retrieval in pruning mode.
Internally, Geth uses a freezer to maintain historical chain segments, which must
be inserted sequentially. This raises the question of how to handle the gap between
the genesis block and the first block after the cutoff in the freezer.
Two options were considered:
(a) Introducing a new freezer API to set the freezer tail to an arbitrary block number.
(b) Replacing chain data before the cutoff with null data.
The latter option is simpler and functionally equivalent to the former. When retrieving
data for chain segments before the cutoff, null values will be returned, indicating that
these items do not exist locally. Additionally it's a more robust approach that all chain
segment inserted into the freezer always in an atomic manner. Lots of complexities are
needed in approach (a) if this property is required. For example, we must guarantee
the header x write and body table tail shifting to x happen atomically.
Therefore, the approach (b) is chosen for the sake of simplicity.
Additionally, this pull request introduces some important changes worth highlighting.
Originally, in snap sync, the header chain and other components (bodies and receipts)
were inserted separately. However, in Proof-of-Stake, this separation is unnecessary
since the sync target is already verified by the CL.
To simplify the process, this pull request modifies
InsertReceiptChain
to insert headersalong with block bodies and receipts together. Besides,
InsertReceiptChain
doesn'thave the notion of reorg, as the common ancestor is always be found before the sync
and extra side chain is truncated at the beginning if they fall in the ancient store.
The stale canonical chain flags will always be rewritten by the new chain. No explicit
reorg logic required in the
InsertReceiptChain
.