Skip to content

Commit 916eaf0

Browse files
committed
core, eth/downloader: implement pruning mode sync
1 parent 8e3cd41 commit 916eaf0

15 files changed

+528
-538
lines changed

cmd/geth/chaincmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func importHistory(ctx *cli.Context) error {
445445
network = networks[0]
446446
}
447447

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

cmd/utils/cmd.go

+3-7
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

+1-1
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)