diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index c9065381986df84ecf1aba09b0f3e2d6d4015193..e96969ae8ef7446b530f98d3bb5e9f4e8ac73d2b 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -816,8 +816,14 @@ func DownloadAndIndexSnapshotsIfNeed(s *StageState, ctx context.Context, tx kv.R } // Fill kv.HeaderTD table from snapshots - c, _ := tx.Cursor(kv.HeaderTD) - count, _ := c.Count() + c, err := tx.Cursor(kv.HeaderTD) + if err != nil { + return err + } + count, err := c.Count() + if err != nil { + return err + } if count == 0 || count == 1 { // genesis does write 1 record logEvery := time.NewTicker(logInterval) defer logEvery.Stop() @@ -843,21 +849,23 @@ func DownloadAndIndexSnapshotsIfNeed(s *StageState, ctx context.Context, tx kv.R return err } - // Fill kv.HeaderCanonical table from snapshots - tx.ClearBucket(kv.HeaderCanonical) - if err := fixCanonicalChain(s.LogPrefix(), logEvery, lastHeader.Number.Uint64(), lastHeader.Hash(), tx, cfg.blockReader); err != nil { - return err - } + if lastHeader != nil { + // Fill kv.HeaderCanonical table from snapshots + tx.ClearBucket(kv.HeaderCanonical) + if err := fixCanonicalChain(s.LogPrefix(), logEvery, lastHeader.Number.Uint64(), lastHeader.Hash(), tx, cfg.blockReader); err != nil { + return err + } - sn, ok := cfg.snapshots.Blocks(cfg.snapshots.BlocksAvailable()) - if !ok { - return fmt.Errorf("snapshot not found for block: %d", cfg.snapshots.BlocksAvailable()) - } + sn, ok := cfg.snapshots.Blocks(cfg.snapshots.BlocksAvailable()) + if !ok { + return fmt.Errorf("snapshot not found for block: %d", cfg.snapshots.BlocksAvailable()) + } - // ResetSequence - allow set arbitrary value to sequence (for example to decrement it to exact value) - lastTxnID := sn.TxnHashIdx.BaseDataID() + uint64(sn.Transactions.Count()) - if err := rawdb.ResetSequence(tx, kv.EthTx, lastTxnID+1); err != nil { - return err + // ResetSequence - allow set arbitrary value to sequence (for example to decrement it to exact value) + lastTxnID := sn.TxnHashIdx.BaseDataID() + uint64(sn.Transactions.Count()) + if err := rawdb.ResetSequence(tx, kv.EthTx, lastTxnID+1); err != nil { + return err + } } } diff --git a/turbo/snapshotsync/snapshothashes/erigon-snapshots b/turbo/snapshotsync/snapshothashes/erigon-snapshots index 42fb09c4cc58bd6c1acb8add828d7861e91a9183..2c5b3e77580645f869820a435e34a857092aa89f 160000 --- a/turbo/snapshotsync/snapshothashes/erigon-snapshots +++ b/turbo/snapshotsync/snapshothashes/erigon-snapshots @@ -1 +1 @@ -Subproject commit 42fb09c4cc58bd6c1acb8add828d7861e91a9183 +Subproject commit 2c5b3e77580645f869820a435e34a857092aa89f