Truncate bor receipts on unwind (#4033)

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2022-04-30 15:46:08 +01:00 committed by GitHub
parent 93ab7f5d82
commit e0d7998eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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
}

View File

@ -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