diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index dcff36247d3..210553c65d9 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -34,7 +34,6 @@ import ( "github.com/erigontech/erigon-lib/log/v3" "github.com/erigontech/erigon-lib/common" - "github.com/erigontech/erigon-lib/common/dbg" "github.com/erigontech/erigon-lib/common/hexutility" "github.com/erigontech/erigon-lib/common/length" "github.com/erigontech/erigon-lib/kv" @@ -836,34 +835,6 @@ func ReadRawReceipts(db kv.Tx, blockNum uint64) types.Receipts { return receipts } -// ReadReceipts retrieves all the transaction receipts belonging to a block, including -// its corresponding metadata fields. If it is unable to populate these metadata -// fields then nil is returned. -// -// The current implementation populates these metadata fields by reading the receipts' -// corresponding block body, so if the block body is not found it will return nil even -// if the receipt itself is stored. -func ReadReceipts(db kv.Tx, block *types.Block, senders []common.Address) types.Receipts { - if block == nil { - return nil - } - // We're deriving many fields from the block body, retrieve beside the receipt - receipts := ReadRawReceipts(db, block.NumberU64()) - if receipts == nil { - return nil - } - if len(senders) > 0 { - block.SendersToTxs(senders) - } else { - senders = block.Body().SendersFromTxs() - } - if err := receipts.DeriveFields(block.Hash(), block.NumberU64(), block.Transactions(), senders); err != nil { - log.Error("Failed to derive block receipts fields", "hash", block.Hash(), "number", block.NumberU64(), "err", err, "stack", dbg.Stack()) - return nil - } - return receipts -} - // WriteReceipts stores all the transaction receipts belonging to a block. func WriteReceipts(tx kv.Putter, number uint64, receipts types.Receipts) error { buf := bytes.NewBuffer(make([]byte, 0, 1024)) diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index cfa44a1e01a..73df7b067c0 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -460,99 +460,6 @@ func TestHeadStorage(t *testing.T) { } } -// Tests that receipts associated with a single block can be stored and retrieved. -func TestBlockReceiptStorage(t *testing.T) { - t.Parallel() - m := mock.Mock(t) - tx, err := m.DB.BeginRw(m.Ctx) - require.NoError(t, err) - defer tx.Rollback() - br := m.BlockReader - require := require.New(t) - ctx := m.Ctx - - // Create a live block since we need metadata to reconstruct the receipt - tx1 := types.NewTransaction(1, libcommon.HexToAddress("0x1"), u256.Num1, 1, u256.Num1, nil) - tx2 := types.NewTransaction(2, libcommon.HexToAddress("0x2"), u256.Num2, 2, u256.Num2, nil) - - body := &types.Body{Transactions: types.Transactions{tx1, tx2}} - - // Create the two receipts to manage afterwards - receipt1 := &types.Receipt{ - Status: types.ReceiptStatusFailed, - CumulativeGasUsed: 1, - Logs: []*types.Log{ - {Address: libcommon.BytesToAddress([]byte{0x11})}, - {Address: libcommon.BytesToAddress([]byte{0x01, 0x11})}, - }, - TxHash: tx1.Hash(), - ContractAddress: libcommon.BytesToAddress([]byte{0x01, 0x11, 0x11}), - GasUsed: 111111, - } - //receipt1.Bloom = types.CreateBloom(types.Receipts{receipt1}) - - receipt2 := &types.Receipt{ - PostState: libcommon.Hash{2}.Bytes(), - CumulativeGasUsed: 2, - Logs: []*types.Log{ - {Address: libcommon.BytesToAddress([]byte{0x22})}, - {Address: libcommon.BytesToAddress([]byte{0x02, 0x22})}, - }, - TxHash: tx2.Hash(), - ContractAddress: libcommon.BytesToAddress([]byte{0x02, 0x22, 0x22}), - GasUsed: 222222, - } - //receipt2.Bloom = types.CreateBloom(types.Receipts{receipt2}) - receipts := []*types.Receipt{receipt1, receipt2} - header := &types.Header{Number: big.NewInt(1)} - - // Check that no receipt entries are in a pristine database - hash := header.Hash() //libcommon.BytesToHash([]byte{0x03, 0x14}) - - rawdb.WriteCanonicalHash(tx, header.Hash(), header.Number.Uint64()) - rawdb.WriteHeader(tx, header) - // Insert the body that corresponds to the receipts - require.NoError(rawdb.WriteBody(tx, hash, 1, body)) - require.NoError(rawdb.WriteSenders(tx, hash, 1, body.SendersFromTxs())) - - // Insert the receipt slice into the database and check presence - require.NoError(rawdb.WriteReceipts(tx, 1, receipts)) - - b, senders, err := br.BlockWithSenders(ctx, tx, hash, 1) - require.NoError(err) - require.NotNil(b) - if rs := rawdb.ReadReceipts(tx, b, senders); len(rs) == 0 { - t.Fatalf("no receipts returned") - } else { - if err := checkReceiptsRLP(rs, receipts); err != nil { - t.Fatal(err.Error()) - } - } - // Delete the body and ensure that the receipts are no longer returned (metadata can't be recomputed) - rawdb.DeleteHeader(tx, hash, 1) - rawdb.DeleteBody(tx, hash, 1) - b, senders, err = br.BlockWithSenders(ctx, tx, hash, 1) - require.NoError(err) - require.Nil(b) - if rs := rawdb.ReadReceipts(tx, b, senders); rs != nil { - t.Fatalf("receipts returned when body was deleted: %v", rs) - } - // Ensure that receipts without metadata can be returned without the block body too - if err := checkReceiptsRLP(rawdb.ReadRawReceipts(tx, 1), receipts); err != nil { - t.Fatal(err) - } - rawdb.WriteHeader(tx, header) - // Sanity check that body alone without the receipt is a full purge - require.NoError(rawdb.WriteBody(tx, hash, 1, body)) - require.NoError(rawdb.TruncateReceipts(tx, 1)) - b, senders, err = br.BlockWithSenders(ctx, tx, hash, 1) - require.NoError(err) - require.NotNil(b) - if rs := rawdb.ReadReceipts(tx, b, senders); len(rs) != 0 { - t.Fatalf("deleted receipts returned: %v", rs) - } -} - // Tests block storage and retrieval operations with withdrawals. func TestBlockWithdrawalsStorage(t *testing.T) { t.Parallel()