diff --git a/core/blockchain.go b/core/blockchain.go index 25b37b5cce..d8073de6d2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -295,7 +295,7 @@ type BlockChain struct { bodyCache *lru.Cache[common.Hash, *types.Body] bodyRLPCache *lru.Cache[common.Hash, rlp.RawValue] - receiptsCache *lru.Cache[common.Hash, []*types.Receipt] + receiptsCache *lru.Cache[common.Hash, []*types.Receipt] // Receipts cache with all fields derived blockCache *lru.Cache[common.Hash, *types.Block] txLookupLock sync.RWMutex diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index a4240a3405..df867d2972 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -216,9 +216,11 @@ func (bc *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*type return } -// GetReceiptByIndex allows fetching a receipt for a transaction that was already -// looked up on the index. -func (bc *BlockChain) GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, txIndex uint64) (*types.Receipt, error) { +// GetCanonicalReceipt allows fetching a receipt for a transaction that was +// already looked up on the index. Notably, only receipt in canonical chain +// is visible. +func (bc *BlockChain) GetCanonicalReceipt(tx *types.Transaction, blockHash common.Hash, blockNumber, txIndex uint64) (*types.Receipt, error) { + // The receipt retrieved from the cache contains all previously derived fields if receipts, ok := bc.receiptsCache.Get(blockHash); ok { if int(txIndex) >= len(receipts) { return nil, fmt.Errorf("receipt out of index, length: %d, index: %d", len(receipts), txIndex) @@ -233,7 +235,7 @@ func (bc *BlockChain) GetReceiptByIndex(tx *types.Transaction, blockHash common. if header.ExcessBlobGas != nil { blobGasPrice = eip4844.CalcBlobFee(bc.chainConfig, header) } - receipt, ctx, err := rawdb.ReadRawReceipt(bc.db, blockHash, blockNumber, txIndex) + receipt, ctx, err := rawdb.ReadCanonicalRawReceipt(bc.db, blockHash, blockNumber, txIndex) if err != nil { return nil, err } @@ -316,13 +318,15 @@ func (bc *BlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, max return bc.hc.GetAncestor(hash, number, ancestor, maxNonCanonical) } -// GetTransactionLookup retrieves the lookup along with the transaction +// GetCanonicalTransaction retrieves the lookup along with the transaction // itself associate with the given transaction hash. // // A null will be returned if the transaction is not found. This can be due to // the transaction indexer not being finished. The caller must explicitly check // the indexer progress. -func (bc *BlockChain) GetTransactionLookup(hash common.Hash) (*rawdb.LegacyTxLookupEntry, *types.Transaction) { +// +// Notably, only the transaction in the canonical chain is visible. +func (bc *BlockChain) GetCanonicalTransaction(hash common.Hash) (*rawdb.LegacyTxLookupEntry, *types.Transaction) { bc.txLookupLock.RLock() defer bc.txLookupLock.RUnlock() @@ -330,7 +334,7 @@ func (bc *BlockChain) GetTransactionLookup(hash common.Hash) (*rawdb.LegacyTxLoo if item, exist := bc.txLookupCache.Get(hash); exist { return item.lookup, item.transaction } - tx, blockHash, blockNumber, txIndex := rawdb.ReadTransaction(bc.db, hash) + tx, blockHash, blockNumber, txIndex := rawdb.ReadCanonicalTransaction(bc.db, hash) if tx == nil { return nil, nil } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 353293d138..5e768fccdf 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -1007,21 +1007,21 @@ func testChainTxReorgs(t *testing.T, scheme string) { // removed tx for i, tx := range (types.Transactions{pastDrop, freshDrop}) { - if txn, _, _, _ := rawdb.ReadTransaction(db, tx.Hash()); txn != nil { + if txn, _, _, _ := rawdb.ReadCanonicalTransaction(db, tx.Hash()); txn != nil { t.Errorf("drop %d: tx %v found while shouldn't have been", i, txn) } - if rcpt, _, _, _ := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt != nil { + if rcpt, _, _, _ := rawdb.ReadCanonicalReceipt(db, tx.Hash(), blockchain.Config()); rcpt != nil { t.Errorf("drop %d: receipt %v found while shouldn't have been", i, rcpt) } } // added tx for i, tx := range (types.Transactions{pastAdd, freshAdd, futureAdd}) { - if txn, _, _, _ := rawdb.ReadTransaction(db, tx.Hash()); txn == nil { + if txn, _, _, _ := rawdb.ReadCanonicalTransaction(db, tx.Hash()); txn == nil { t.Errorf("add %d: expected tx to be found", i) } - if rcpt, _, _, index := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { + if rcpt, _, _, index := rawdb.ReadCanonicalReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { t.Errorf("add %d: expected receipt to be found", i) - } else if rawRcpt, ctx, _ := rawdb.ReadRawReceipt(db, rcpt.BlockHash, rcpt.BlockNumber.Uint64(), index); rawRcpt == nil { + } else if rawRcpt, ctx, _ := rawdb.ReadCanonicalRawReceipt(db, rcpt.BlockHash, rcpt.BlockNumber.Uint64(), index); rawRcpt == nil { t.Errorf("add %d: expected raw receipt to be found", i) } else { if rcpt.GasUsed != ctx.GasUsed { @@ -1034,12 +1034,12 @@ func testChainTxReorgs(t *testing.T, scheme string) { } // shared tx for i, tx := range (types.Transactions{postponed, swapped}) { - if txn, _, _, _ := rawdb.ReadTransaction(db, tx.Hash()); txn == nil { + if txn, _, _, _ := rawdb.ReadCanonicalTransaction(db, tx.Hash()); txn == nil { t.Errorf("share %d: expected tx to be found", i) } - if rcpt, _, _, index := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { + if rcpt, _, _, index := rawdb.ReadCanonicalReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { t.Errorf("share %d: expected receipt to be found", i) - } else if rawRcpt, ctx, _ := rawdb.ReadRawReceipt(db, rcpt.BlockHash, rcpt.BlockNumber.Uint64(), index); rawRcpt == nil { + } else if rawRcpt, ctx, _ := rawdb.ReadCanonicalRawReceipt(db, rcpt.BlockHash, rcpt.BlockNumber.Uint64(), index); rawRcpt == nil { t.Errorf("add %d: expected raw receipt to be found", i) } else { if rcpt.GasUsed != ctx.GasUsed { @@ -4426,7 +4426,7 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64, t.Fatalf("Missed block receipts: %d, cutoff: %d", num, cutoffBlock.NumberU64()) } for indx, receipt := range receipts { - receiptByLookup, err := chain.GetReceiptByIndex(body.Transactions[indx], receipt.BlockHash, + receiptByLookup, err := chain.GetCanonicalReceipt(body.Transactions[indx], receipt.BlockHash, receipt.BlockNumber.Uint64(), uint64(indx)) assert.NoError(t, err) assert.Equal(t, receipt, receiptByLookup) @@ -4435,7 +4435,7 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64, } } -func TestGetReceiptByIndex(t *testing.T) { +func TestGetCanonicalReceipt(t *testing.T) { const chainLength = 64 // Configure and generate a sample block chain @@ -4498,7 +4498,7 @@ func TestGetReceiptByIndex(t *testing.T) { blockReceipts := chain.GetReceiptsByHash(block.Hash()) chain.receiptsCache.Purge() // ugly hack for txIndex, tx := range block.Body().Transactions { - receipt, err := chain.GetReceiptByIndex(tx, block.Hash(), block.NumberU64(), uint64(txIndex)) + receipt, err := chain.GetCanonicalReceipt(tx, block.Hash(), block.NumberU64(), uint64(txIndex)) if err != nil { t.Fatalf("Unexpected error %v", err) } diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index b7945ba073..4426c6a9e7 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -449,8 +449,9 @@ func ReadBodyRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue return data } -// ReadCanonicalBodyRLP retrieves the block body (transactions and uncles) for the canonical -// block at number, in RLP encoding. Optionally it takes the block hash to avoid looking it up +// ReadCanonicalBodyRLP retrieves the block body (transactions and uncles) for the +// canonical block at number, in RLP encoding. Optionally it takes the block hash +// to avoid looking it up func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64, hash *common.Hash) rlp.RawValue { var data []byte db.ReadAncients(func(reader ethdb.AncientReaderOp) error { @@ -459,11 +460,11 @@ func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64, hash *common.Hash) rlp return nil } // Block is not in ancients, read from leveldb by hash and number. - // Note: ReadCanonicalHash cannot be used here because it also - // calls ReadAncients internally. if hash != nil { data, _ = db.Get(blockBodyKey(number, *hash)) } else { + // Note: ReadCanonicalHash cannot be used here because it also + // calls ReadAncients internally. hashBytes, _ := db.Get(headerHashKey(number)) data, _ = db.Get(blockBodyKey(number, common.BytesToHash(hashBytes))) } @@ -548,8 +549,8 @@ func ReadReceiptsRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawVa return data } -// ReadCanonicalReceiptsRLP retrieves the receipts RLP for the canonical -// block at number, in RLP encoding. Optionally it takes the block hash to avoid looking it up +// ReadCanonicalReceiptsRLP retrieves the receipts RLP for the canonical block at +// number, in RLP encoding. Optionally it takes the block hash to avoid looking it up. func ReadCanonicalReceiptsRLP(db ethdb.Reader, number uint64, hash *common.Hash) rlp.RawValue { var data []byte db.ReadAncients(func(reader ethdb.AncientReaderOp) error { @@ -558,11 +559,11 @@ func ReadCanonicalReceiptsRLP(db ethdb.Reader, number uint64, hash *common.Hash) return nil } // Block is not in ancients, read from leveldb by hash and number. - // Note: ReadCanonicalHash cannot be used here because it also - // calls ReadAncients internally. if hash != nil { data, _ = db.Get(blockReceiptsKey(number, *hash)) } else { + // Note: ReadCanonicalHash cannot be used here because it also + // calls ReadAncients internally. hashBytes, _ := db.Get(headerHashKey(number)) data, _ = db.Get(blockReceiptsKey(number, common.BytesToHash(hashBytes))) } diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index 3e9a16fec6..f56ff066e9 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -170,9 +170,10 @@ func findTxInBlockBody(blockbody rlp.RawValue, target common.Hash) (*types.Trans return nil, 0, errors.New("transaction not found") } -// ReadTransaction retrieves a specific transaction from the database, along with -// its added positional metadata. -func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { +// ReadCanonicalTransaction retrieves a specific transaction from the database, along +// with its added positional metadata. Notably, only the transaction in the canonical +// chain is visible. +func ReadCanonicalTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { blockNumber := ReadTxLookupEntry(db, hash) if blockNumber == nil { return nil, common.Hash{}, 0, 0 @@ -194,9 +195,10 @@ func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, com return tx, blockHash, *blockNumber, txIndex } -// ReadReceipt retrieves a specific transaction receipt from the database, along with -// its added positional metadata. -func ReadReceipt(db ethdb.Reader, hash common.Hash, config *params.ChainConfig) (*types.Receipt, common.Hash, uint64, uint64) { +// ReadCanonicalReceipt retrieves a specific transaction receipt from the database, +// along with its added positional metadata. Notably, only the receipt in the canonical +// chain is visible. +func ReadCanonicalReceipt(db ethdb.Reader, hash common.Hash, config *params.ChainConfig) (*types.Receipt, common.Hash, uint64, uint64) { // Retrieve the context of the receipt based on the transaction hash blockNumber := ReadTxLookupEntry(db, hash) if blockNumber == nil { @@ -261,10 +263,12 @@ type RawReceiptContext struct { LogIndex uint // Starting index of the logs within the block } -// ReadRawReceipt reads a raw receipt at the specified position. It also returns -// the gas used by the associated transaction and the starting index of the logs -// within the block. -func ReadRawReceipt(db ethdb.Reader, blockHash common.Hash, blockNumber, txIndex uint64) (*types.Receipt, RawReceiptContext, error) { +// ReadCanonicalRawReceipt reads a raw receipt at the specified position. It also +// returns the gas used by the associated transaction and the starting index of +// the logs within the block. The main difference with ReadCanonicalReceipt is +// that the additional positional fields are not directly included in the receipt. +// Notably, only receipts from the canonical chain are visible. +func ReadCanonicalRawReceipt(db ethdb.Reader, blockHash common.Hash, blockNumber, txIndex uint64) (*types.Receipt, RawReceiptContext, error) { receiptIt, err := rlp.NewListIterator(ReadCanonicalReceiptsRLP(db, blockNumber, &blockHash)) if err != nil { return nil, RawReceiptContext{}, err diff --git a/core/rawdb/accessors_indexes_test.go b/core/rawdb/accessors_indexes_test.go index f45264b52b..a812fefeaa 100644 --- a/core/rawdb/accessors_indexes_test.go +++ b/core/rawdb/accessors_indexes_test.go @@ -89,7 +89,7 @@ func TestLookupStorage(t *testing.T) { // Check that no transactions entries are in a pristine database for i, tx := range txs { - if txn, _, _, _ := ReadTransaction(db, tx.Hash()); txn != nil { + if txn, _, _, _ := ReadCanonicalTransaction(db, tx.Hash()); txn != nil { t.Fatalf("tx #%d [%x]: non existent transaction returned: %v", i, tx.Hash(), txn) } } @@ -99,7 +99,7 @@ func TestLookupStorage(t *testing.T) { tc.writeTxLookupEntriesByBlock(db, block) for i, tx := range txs { - if txn, hash, number, index := ReadTransaction(db, tx.Hash()); txn == nil { + if txn, hash, number, index := ReadCanonicalTransaction(db, tx.Hash()); txn == nil { t.Fatalf("tx #%d [%x]: transaction not found", i, tx.Hash()) } else { if hash != block.Hash() || number != block.NumberU64() || index != uint64(i) { @@ -113,7 +113,7 @@ func TestLookupStorage(t *testing.T) { // Delete the transactions and check purge for i, tx := range txs { DeleteTxLookupEntry(db, tx.Hash()) - if txn, _, _, _ := ReadTransaction(db, tx.Hash()); txn != nil { + if txn, _, _, _ := ReadCanonicalTransaction(db, tx.Hash()); txn != nil { t.Fatalf("tx #%d [%x]: deleted transaction returned: %v", i, tx.Hash(), txn) } } diff --git a/eth/api_backend.go b/eth/api_backend.go index 96f48de999..f2ef62223b 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -276,8 +276,8 @@ func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (type return b.eth.blockchain.GetReceiptsByHash(hash), nil } -func (b *EthAPIBackend) GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { - return b.eth.blockchain.GetReceiptByIndex(tx, blockHash, blockNumber, blockIndex) +func (b *EthAPIBackend) GetCanonicalReceipt(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { + return b.eth.blockchain.GetCanonicalReceipt(tx, blockHash, blockNumber, blockIndex) } func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) { @@ -352,14 +352,16 @@ func (b *EthAPIBackend) GetPoolTransaction(hash common.Hash) *types.Transaction return b.eth.txPool.Get(hash) } -// GetTransaction retrieves the lookup along with the transaction itself associate -// with the given transaction hash. +// GetCanonicalTransaction retrieves the lookup along with the transaction itself +// associate with the given transaction hash. // // A null will be returned if the transaction is not found. The transaction is not // existent from the node's perspective. This can be due to the transaction indexer // not being finished. The caller must explicitly check the indexer progress. -func (b *EthAPIBackend) GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { - lookup, tx := b.eth.blockchain.GetTransactionLookup(txHash) +// +// Notably, only the transaction in the canonical chain is visible. +func (b *EthAPIBackend) GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { + lookup, tx := b.eth.blockchain.GetCanonicalTransaction(txHash) if lookup == nil || tx == nil { return false, nil, common.Hash{}, 0, 0 } diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 6b01976084..6962023343 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -82,7 +82,7 @@ type Backend interface { HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) - GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) + GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) TxIndexDone() bool RPCGasCap() uint64 ChainConfig() *params.ChainConfig @@ -863,7 +863,7 @@ func containsTx(block *types.Block, hash common.Hash) bool { // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { - found, _, blockHash, blockNumber, index := api.backend.GetTransaction(hash) + found, _, blockHash, blockNumber, index := api.backend.GetCanonicalTransaction(hash) if !found { // Warn in case tx indexer is not done. if !api.backend.TxIndexDone() { diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index 1826c78582..076e6fd8d4 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -117,8 +117,8 @@ func (b *testBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) return b.chain.GetBlockByNumber(uint64(number)), nil } -func (b *testBackend) GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { - tx, hash, blockNumber, index := rawdb.ReadTransaction(b.chaindb, txHash) +func (b *testBackend) GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { + tx, hash, blockNumber, index := rawdb.ReadCanonicalTransaction(b.chaindb, txHash) return tx != nil, tx, hash, blockNumber, index } diff --git a/graphql/graphql.go b/graphql/graphql.go index e23e6fcb0e..6b7046f629 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -229,7 +229,7 @@ func (t *Transaction) resolve(ctx context.Context) (*types.Transaction, *Block) return t.tx, t.block } // Try to return an already finalized transaction - found, tx, blockHash, _, index := t.r.backend.GetTransaction(t.hash) + found, tx, blockHash, _, index := t.r.backend.GetCanonicalTransaction(t.hash) if found { t.tx = tx blockNrOrHash := rpc.BlockNumberOrHashWithHash(blockHash, false) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index ae198c8f42..8a9e8c818c 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1333,7 +1333,7 @@ func (api *TransactionAPI) GetTransactionCount(ctx context.Context, address comm // GetTransactionByHash returns the transaction for the given hash func (api *TransactionAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) { // Try to return an already finalized transaction - found, tx, blockHash, blockNumber, index := api.b.GetTransaction(hash) + found, tx, blockHash, blockNumber, index := api.b.GetCanonicalTransaction(hash) if !found { // No finalized transaction, try to retrieve it from the pool if tx := api.b.GetPoolTransaction(hash); tx != nil { @@ -1356,7 +1356,7 @@ func (api *TransactionAPI) GetTransactionByHash(ctx context.Context, hash common // GetRawTransactionByHash returns the bytes of the transaction for the given hash. func (api *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { // Retrieve a finalized transaction, or a pooled otherwise - found, tx, _, _, _ := api.b.GetTransaction(hash) + found, tx, _, _, _ := api.b.GetCanonicalTransaction(hash) if !found { if tx = api.b.GetPoolTransaction(hash); tx != nil { return tx.MarshalBinary() @@ -1373,7 +1373,7 @@ func (api *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash com // GetTransactionReceipt returns the transaction receipt for the given transaction hash. func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) { - found, tx, blockHash, blockNumber, index := api.b.GetTransaction(hash) + found, tx, blockHash, blockNumber, index := api.b.GetCanonicalTransaction(hash) if !found { // Make sure indexer is done. if !api.b.TxIndexDone() { @@ -1386,7 +1386,7 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo if err != nil { return nil, err } - receipt, err := api.b.GetReceiptByIndex(tx, blockHash, blockNumber, index) + receipt, err := api.b.GetCanonicalReceipt(tx, blockHash, blockNumber, index) if err != nil { return nil, err } @@ -1775,7 +1775,7 @@ func (api *DebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.Block // GetRawTransaction returns the bytes of the transaction for the given hash. func (api *DebugAPI) GetRawTransaction(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { // Retrieve a finalized transaction, or a pooled otherwise - found, tx, _, _, _ := api.b.GetTransaction(hash) + found, tx, _, _, _ := api.b.GetCanonicalTransaction(hash) if !found { if tx = api.b.GetPoolTransaction(hash); tx != nil { return tx.MarshalBinary() diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 511f92c0a8..1c9be836fc 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -586,12 +586,12 @@ func (b testBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) even func (b testBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { panic("implement me") } -func (b testBackend) GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { - tx, blockHash, blockNumber, index := rawdb.ReadTransaction(b.db, txHash) +func (b testBackend) GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { + tx, blockHash, blockNumber, index := rawdb.ReadCanonicalTransaction(b.db, txHash) return tx != nil, tx, blockHash, blockNumber, index } -func (b testBackend) GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { - return b.chain.GetReceiptByIndex(tx, blockHash, blockNumber, blockIndex) +func (b testBackend) GetCanonicalReceipt(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { + return b.chain.GetCanonicalReceipt(tx, blockHash, blockNumber, blockIndex) } func (b testBackend) TxIndexDone() bool { return true diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 1b29796118..f709a1fcdc 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -68,14 +68,14 @@ type Backend interface { StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) Pending() (*types.Block, types.Receipts, *state.StateDB) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) - GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) + GetCanonicalReceipt(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription // Transaction pool API SendTx(ctx context.Context, signedTx *types.Transaction) error - GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) + GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) TxIndexDone() bool GetPoolTransactions() (types.Transactions, error) GetPoolTransaction(txHash common.Hash) *types.Transaction diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 2b377ab9c8..30791f32b5 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -369,7 +369,7 @@ func (b *backendMock) Pending() (*types.Block, types.Receipts, *state.StateDB) { func (b *backendMock) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { return nil, nil } -func (b *backendMock) GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { +func (b *backendMock) GetCanonicalReceipt(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { return nil, nil } func (b *backendMock) GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error) { @@ -383,7 +383,7 @@ func (b *backendMock) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) eve return nil } func (b *backendMock) SendTx(ctx context.Context, signedTx *types.Transaction) error { return nil } -func (b *backendMock) GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { +func (b *backendMock) GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { return false, nil, [32]byte{}, 0, 0 } func (b *backendMock) TxIndexDone() bool { return true }