From e0d7998eb07d8bf89c159b92a6016507a2cb8895 Mon Sep 17 00:00:00 2001 From: ledgerwatch Date: Sat, 30 Apr 2022 15:46:08 +0100 Subject: [PATCH] Truncate bor receipts on unwind (#4033) Co-authored-by: Alexey Sharp --- core/rawdb/bor_receipts.go | 11 +++++++++++ eth/stagedsync/stage_execute.go | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/rawdb/bor_receipts.go b/core/rawdb/bor_receipts.go index b34fac9c6..ba186a0af 100644 --- a/core/rawdb/bor_receipts.go +++ b/core/rawdb/bor_receipts.go @@ -5,6 +5,7 @@ import ( "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon/common" + "github.com/ledgerwatch/erigon/common/dbutils" "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/rlp" "github.com/ledgerwatch/log/v3" @@ -147,3 +148,13 @@ func ReadBorTransaction(db kv.Tx, hash common.Hash) (*types.Transaction, common. var tx types.Transaction = types.NewBorTransaction() return &tx, blockHash, *blockNumber, uint64(bodyForStorage.TxAmount), nil } + +// TruncateBorReceipts removes all bor receipt for given block number or newer +func TruncateBorReceipts(db kv.RwTx, number uint64) error { + if err := db.ForEach(kv.BorReceipts, dbutils.EncodeBlockNumber(number), func(k, _ []byte) error { + return db.Delete(kv.BorReceipts, k, nil) + }); err != nil { + return err + } + return nil +} diff --git a/eth/stagedsync/stage_execute.go b/eth/stagedsync/stage_execute.go index 08f8aaf3d..4f166536c 100644 --- a/eth/stagedsync/stage_execute.go +++ b/eth/stagedsync/stage_execute.go @@ -520,10 +520,13 @@ func unwindExecutionStage(u *UnwindState, s *StageState, tx kv.RwTx, quit <-chan } if err := rawdb.TruncateReceipts(tx, u.UnwindPoint+1); err != nil { - return fmt.Errorf("walking receipts: %w", err) + return fmt.Errorf("truncate receipts: %w", err) + } + if err := rawdb.TruncateBorReceipts(tx, u.UnwindPoint+1); err != nil { + return fmt.Errorf("truncate bor receipts: %w", err) } if err := rawdb.DeleteNewerEpochs(tx, u.UnwindPoint+1); err != nil { - return fmt.Errorf("walking epoch: %w", err) + return fmt.Errorf("delete newer epochs: %w", err) } // Truncate CallTraceSet