Skip to content

Commit 90d44e7

Browse files
authored
core, eth/downloader: implement pruning mode sync (ethereum#31414)
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`.
1 parent 22c0605 commit 90d44e7

17 files changed

+599
-543
lines changed

cmd/geth/chaincmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func importHistory(ctx *cli.Context) error {
457457
network = networks[0]
458458
}
459459

460-
if err := utils.ImportHistory(chain, db, dir, network); err != nil {
460+
if err := utils.ImportHistory(chain, dir, network); err != nil {
461461
return err
462462
}
463463
fmt.Printf("Import done in %v\n", time.Since(start))

cmd/utils/cmd.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ func readList(filename string) ([]string, error) {
246246
}
247247

248248
// ImportHistory imports Era1 files containing historical block information,
249-
// starting from genesis.
250-
func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, network string) error {
249+
// starting from genesis. The assumption is held that the provided chain
250+
// segment in Era1 file should all be canonical and verified.
251+
func ImportHistory(chain *core.BlockChain, dir string, network string) error {
251252
if chain.CurrentSnapBlock().Number.BitLen() != 0 {
252253
return errors.New("history import only supported when starting from genesis")
253254
}
@@ -308,11 +309,6 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
308309
if err != nil {
309310
return fmt.Errorf("error reading receipts %d: %w", it.Number(), err)
310311
}
311-
if status, err := chain.HeaderChain().InsertHeaderChain([]*types.Header{block.Header()}, start); err != nil {
312-
return fmt.Errorf("error inserting header %d: %w", it.Number(), err)
313-
} else if status != core.CanonStatTy {
314-
return fmt.Errorf("error inserting header %d, not canon: %v", it.Number(), status)
315-
}
316312
if _, err := chain.InsertReceiptChain([]*types.Block{block}, []types.Receipts{receipts}, 2^64-1); err != nil {
317313
return fmt.Errorf("error inserting body %d: %w", it.Number(), err)
318314
}

cmd/utils/history_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func TestHistoryImportAndExport(t *testing.T) {
171171
if err != nil {
172172
t.Fatalf("unable to initialize chain: %v", err)
173173
}
174-
if err := ImportHistory(imported, db2, dir, "mainnet"); err != nil {
174+
if err := ImportHistory(imported, dir, "mainnet"); err != nil {
175175
t.Fatalf("failed to import chain: %v", err)
176176
}
177177
if have, want := imported.CurrentHeader(), chain.CurrentHeader(); have.Hash() != want.Hash() {

0 commit comments

Comments
 (0)