core, eth, internal: rename

This commit is contained in:
Gary Rong 2025-06-23 13:27:36 +08:00
parent 7a5c0f10a0
commit 02c86786ad
14 changed files with 75 additions and 64 deletions

View file

@ -295,7 +295,7 @@ type BlockChain struct {
bodyCache *lru.Cache[common.Hash, *types.Body] bodyCache *lru.Cache[common.Hash, *types.Body]
bodyRLPCache *lru.Cache[common.Hash, rlp.RawValue] 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] blockCache *lru.Cache[common.Hash, *types.Block]
txLookupLock sync.RWMutex txLookupLock sync.RWMutex

View file

@ -216,9 +216,11 @@ func (bc *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*type
return return
} }
// GetReceiptByIndex allows fetching a receipt for a transaction that was already // GetCanonicalReceipt allows fetching a receipt for a transaction that was
// looked up on the index. // already looked up on the index. Notably, only receipt in canonical chain
func (bc *BlockChain) GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, txIndex uint64) (*types.Receipt, error) { // 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 receipts, ok := bc.receiptsCache.Get(blockHash); ok {
if int(txIndex) >= len(receipts) { if int(txIndex) >= len(receipts) {
return nil, fmt.Errorf("receipt out of index, length: %d, index: %d", len(receipts), txIndex) 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 { if header.ExcessBlobGas != nil {
blobGasPrice = eip4844.CalcBlobFee(bc.chainConfig, header) 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 { if err != nil {
return nil, err 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) 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. // itself associate with the given transaction hash.
// //
// A null will be returned if the transaction is not found. This can be due to // 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 transaction indexer not being finished. The caller must explicitly check
// the indexer progress. // 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() bc.txLookupLock.RLock()
defer bc.txLookupLock.RUnlock() 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 { if item, exist := bc.txLookupCache.Get(hash); exist {
return item.lookup, item.transaction 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 { if tx == nil {
return nil, nil return nil, nil
} }

View file

@ -1007,21 +1007,21 @@ func testChainTxReorgs(t *testing.T, scheme string) {
// removed tx // removed tx
for i, tx := range (types.Transactions{pastDrop, freshDrop}) { 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) 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) t.Errorf("drop %d: receipt %v found while shouldn't have been", i, rcpt)
} }
} }
// added tx // added tx
for i, tx := range (types.Transactions{pastAdd, freshAdd, futureAdd}) { 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) 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) 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) t.Errorf("add %d: expected raw receipt to be found", i)
} else { } else {
if rcpt.GasUsed != ctx.GasUsed { if rcpt.GasUsed != ctx.GasUsed {
@ -1034,12 +1034,12 @@ func testChainTxReorgs(t *testing.T, scheme string) {
} }
// shared tx // shared tx
for i, tx := range (types.Transactions{postponed, swapped}) { 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) 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) 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) t.Errorf("add %d: expected raw receipt to be found", i)
} else { } else {
if rcpt.GasUsed != ctx.GasUsed { 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()) t.Fatalf("Missed block receipts: %d, cutoff: %d", num, cutoffBlock.NumberU64())
} }
for indx, receipt := range receipts { 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)) receipt.BlockNumber.Uint64(), uint64(indx))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, receipt, receiptByLookup) 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 const chainLength = 64
// Configure and generate a sample block chain // Configure and generate a sample block chain
@ -4498,7 +4498,7 @@ func TestGetReceiptByIndex(t *testing.T) {
blockReceipts := chain.GetReceiptsByHash(block.Hash()) blockReceipts := chain.GetReceiptsByHash(block.Hash())
chain.receiptsCache.Purge() // ugly hack chain.receiptsCache.Purge() // ugly hack
for txIndex, tx := range block.Body().Transactions { 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 { if err != nil {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }

View file

@ -449,8 +449,9 @@ func ReadBodyRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue
return data return data
} }
// ReadCanonicalBodyRLP retrieves the block body (transactions and uncles) for the canonical // ReadCanonicalBodyRLP retrieves the block body (transactions and uncles) for the
// block at number, in RLP encoding. Optionally it takes the block hash to avoid looking it up // 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 { func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64, hash *common.Hash) rlp.RawValue {
var data []byte var data []byte
db.ReadAncients(func(reader ethdb.AncientReaderOp) error { db.ReadAncients(func(reader ethdb.AncientReaderOp) error {
@ -459,11 +460,11 @@ func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64, hash *common.Hash) rlp
return nil return nil
} }
// Block is not in ancients, read from leveldb by hash and number. // 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 { if hash != nil {
data, _ = db.Get(blockBodyKey(number, *hash)) data, _ = db.Get(blockBodyKey(number, *hash))
} else { } else {
// Note: ReadCanonicalHash cannot be used here because it also
// calls ReadAncients internally.
hashBytes, _ := db.Get(headerHashKey(number)) hashBytes, _ := db.Get(headerHashKey(number))
data, _ = db.Get(blockBodyKey(number, common.BytesToHash(hashBytes))) 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 return data
} }
// ReadCanonicalReceiptsRLP retrieves the receipts RLP for the canonical // ReadCanonicalReceiptsRLP retrieves the receipts RLP for the canonical block at
// block at number, in RLP encoding. Optionally it takes the block hash to avoid looking it up // 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 { func ReadCanonicalReceiptsRLP(db ethdb.Reader, number uint64, hash *common.Hash) rlp.RawValue {
var data []byte var data []byte
db.ReadAncients(func(reader ethdb.AncientReaderOp) error { db.ReadAncients(func(reader ethdb.AncientReaderOp) error {
@ -558,11 +559,11 @@ func ReadCanonicalReceiptsRLP(db ethdb.Reader, number uint64, hash *common.Hash)
return nil return nil
} }
// Block is not in ancients, read from leveldb by hash and number. // 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 { if hash != nil {
data, _ = db.Get(blockReceiptsKey(number, *hash)) data, _ = db.Get(blockReceiptsKey(number, *hash))
} else { } else {
// Note: ReadCanonicalHash cannot be used here because it also
// calls ReadAncients internally.
hashBytes, _ := db.Get(headerHashKey(number)) hashBytes, _ := db.Get(headerHashKey(number))
data, _ = db.Get(blockReceiptsKey(number, common.BytesToHash(hashBytes))) data, _ = db.Get(blockReceiptsKey(number, common.BytesToHash(hashBytes)))
} }

View file

@ -170,9 +170,10 @@ func findTxInBlockBody(blockbody rlp.RawValue, target common.Hash) (*types.Trans
return nil, 0, errors.New("transaction not found") return nil, 0, errors.New("transaction not found")
} }
// ReadTransaction retrieves a specific transaction from the database, along with // ReadCanonicalTransaction retrieves a specific transaction from the database, along
// its added positional metadata. // with its added positional metadata. Notably, only the transaction in the canonical
func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { // chain is visible.
func ReadCanonicalTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) {
blockNumber := ReadTxLookupEntry(db, hash) blockNumber := ReadTxLookupEntry(db, hash)
if blockNumber == nil { if blockNumber == nil {
return nil, common.Hash{}, 0, 0 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 return tx, blockHash, *blockNumber, txIndex
} }
// ReadReceipt retrieves a specific transaction receipt from the database, along with // ReadCanonicalReceipt retrieves a specific transaction receipt from the database,
// its added positional metadata. // along with its added positional metadata. Notably, only the receipt in the canonical
func ReadReceipt(db ethdb.Reader, hash common.Hash, config *params.ChainConfig) (*types.Receipt, common.Hash, uint64, uint64) { // 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 // Retrieve the context of the receipt based on the transaction hash
blockNumber := ReadTxLookupEntry(db, hash) blockNumber := ReadTxLookupEntry(db, hash)
if blockNumber == nil { if blockNumber == nil {
@ -261,10 +263,12 @@ type RawReceiptContext struct {
LogIndex uint // Starting index of the logs within the block LogIndex uint // Starting index of the logs within the block
} }
// ReadRawReceipt reads a raw receipt at the specified position. It also returns // ReadCanonicalRawReceipt reads a raw receipt at the specified position. It also
// the gas used by the associated transaction and the starting index of the logs // returns the gas used by the associated transaction and the starting index of
// within the block. // the logs within the block. The main difference with ReadCanonicalReceipt is
func ReadRawReceipt(db ethdb.Reader, blockHash common.Hash, blockNumber, txIndex uint64) (*types.Receipt, RawReceiptContext, error) { // 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)) receiptIt, err := rlp.NewListIterator(ReadCanonicalReceiptsRLP(db, blockNumber, &blockHash))
if err != nil { if err != nil {
return nil, RawReceiptContext{}, err return nil, RawReceiptContext{}, err

View file

@ -89,7 +89,7 @@ func TestLookupStorage(t *testing.T) {
// Check that no transactions entries are in a pristine database // Check that no transactions entries are in a pristine database
for i, tx := range txs { 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) 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) tc.writeTxLookupEntriesByBlock(db, block)
for i, tx := range txs { 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()) t.Fatalf("tx #%d [%x]: transaction not found", i, tx.Hash())
} else { } else {
if hash != block.Hash() || number != block.NumberU64() || index != uint64(i) { 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 // Delete the transactions and check purge
for i, tx := range txs { for i, tx := range txs {
DeleteTxLookupEntry(db, tx.Hash()) 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) t.Fatalf("tx #%d [%x]: deleted transaction returned: %v", i, tx.Hash(), txn)
} }
} }

View file

@ -276,8 +276,8 @@ func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (type
return b.eth.blockchain.GetReceiptsByHash(hash), nil return b.eth.blockchain.GetReceiptsByHash(hash), nil
} }
func (b *EthAPIBackend) GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { func (b *EthAPIBackend) GetCanonicalReceipt(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) {
return b.eth.blockchain.GetReceiptByIndex(tx, blockHash, blockNumber, blockIndex) return b.eth.blockchain.GetCanonicalReceipt(tx, blockHash, blockNumber, blockIndex)
} }
func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) { 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) return b.eth.txPool.Get(hash)
} }
// GetTransaction retrieves the lookup along with the transaction itself associate // GetCanonicalTransaction retrieves the lookup along with the transaction itself
// with the given transaction hash. // associate with the given transaction hash.
// //
// A null will be returned if the transaction is not found. The transaction is not // 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 // 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. // 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 { if lookup == nil || tx == nil {
return false, nil, common.Hash{}, 0, 0 return false, nil, common.Hash{}, 0, 0
} }

View file

@ -82,7 +82,7 @@ type Backend interface {
HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*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 TxIndexDone() bool
RPCGasCap() uint64 RPCGasCap() uint64
ChainConfig() *params.ChainConfig 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 // TraceTransaction returns the structured logs created during the execution of EVM
// and returns them as a JSON object. // and returns them as a JSON object.
func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { 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 { if !found {
// Warn in case tx indexer is not done. // Warn in case tx indexer is not done.
if !api.backend.TxIndexDone() { if !api.backend.TxIndexDone() {

View file

@ -117,8 +117,8 @@ func (b *testBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber)
return b.chain.GetBlockByNumber(uint64(number)), nil return b.chain.GetBlockByNumber(uint64(number)), nil
} }
func (b *testBackend) GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { func (b *testBackend) GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) {
tx, hash, blockNumber, index := rawdb.ReadTransaction(b.chaindb, txHash) tx, hash, blockNumber, index := rawdb.ReadCanonicalTransaction(b.chaindb, txHash)
return tx != nil, tx, hash, blockNumber, index return tx != nil, tx, hash, blockNumber, index
} }

View file

@ -229,7 +229,7 @@ func (t *Transaction) resolve(ctx context.Context) (*types.Transaction, *Block)
return t.tx, t.block return t.tx, t.block
} }
// Try to return an already finalized transaction // 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 { if found {
t.tx = tx t.tx = tx
blockNrOrHash := rpc.BlockNumberOrHashWithHash(blockHash, false) blockNrOrHash := rpc.BlockNumberOrHashWithHash(blockHash, false)

View file

@ -1333,7 +1333,7 @@ func (api *TransactionAPI) GetTransactionCount(ctx context.Context, address comm
// GetTransactionByHash returns the transaction for the given hash // GetTransactionByHash returns the transaction for the given hash
func (api *TransactionAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) { func (api *TransactionAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) {
// Try to return an already finalized transaction // 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 { if !found {
// No finalized transaction, try to retrieve it from the pool // No finalized transaction, try to retrieve it from the pool
if tx := api.b.GetPoolTransaction(hash); tx != nil { 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. // GetRawTransactionByHash returns the bytes of the transaction for the given hash.
func (api *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { func (api *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) {
// Retrieve a finalized transaction, or a pooled otherwise // Retrieve a finalized transaction, or a pooled otherwise
found, tx, _, _, _ := api.b.GetTransaction(hash) found, tx, _, _, _ := api.b.GetCanonicalTransaction(hash)
if !found { if !found {
if tx = api.b.GetPoolTransaction(hash); tx != nil { if tx = api.b.GetPoolTransaction(hash); tx != nil {
return tx.MarshalBinary() 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. // GetTransactionReceipt returns the transaction receipt for the given transaction hash.
func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) { 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 { if !found {
// Make sure indexer is done. // Make sure indexer is done.
if !api.b.TxIndexDone() { if !api.b.TxIndexDone() {
@ -1386,7 +1386,7 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo
if err != nil { if err != nil {
return nil, err return nil, err
} }
receipt, err := api.b.GetReceiptByIndex(tx, blockHash, blockNumber, index) receipt, err := api.b.GetCanonicalReceipt(tx, blockHash, blockNumber, index)
if err != nil { if err != nil {
return nil, err 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. // GetRawTransaction returns the bytes of the transaction for the given hash.
func (api *DebugAPI) GetRawTransaction(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { func (api *DebugAPI) GetRawTransaction(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) {
// Retrieve a finalized transaction, or a pooled otherwise // Retrieve a finalized transaction, or a pooled otherwise
found, tx, _, _, _ := api.b.GetTransaction(hash) found, tx, _, _, _ := api.b.GetCanonicalTransaction(hash)
if !found { if !found {
if tx = api.b.GetPoolTransaction(hash); tx != nil { if tx = api.b.GetPoolTransaction(hash); tx != nil {
return tx.MarshalBinary() return tx.MarshalBinary()

View file

@ -586,12 +586,12 @@ func (b testBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) even
func (b testBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { func (b testBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
panic("implement me") panic("implement me")
} }
func (b testBackend) GetTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) { func (b testBackend) GetCanonicalTransaction(txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64) {
tx, blockHash, blockNumber, index := rawdb.ReadTransaction(b.db, txHash) tx, blockHash, blockNumber, index := rawdb.ReadCanonicalTransaction(b.db, txHash)
return tx != nil, tx, blockHash, blockNumber, index return tx != nil, tx, blockHash, blockNumber, index
} }
func (b testBackend) GetReceiptByIndex(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) { func (b testBackend) GetCanonicalReceipt(tx *types.Transaction, blockHash common.Hash, blockNumber, blockIndex uint64) (*types.Receipt, error) {
return b.chain.GetReceiptByIndex(tx, blockHash, blockNumber, blockIndex) return b.chain.GetCanonicalReceipt(tx, blockHash, blockNumber, blockIndex)
} }
func (b testBackend) TxIndexDone() bool { func (b testBackend) TxIndexDone() bool {
return true return true

View file

@ -68,14 +68,14 @@ type Backend interface {
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
Pending() (*types.Block, types.Receipts, *state.StateDB) Pending() (*types.Block, types.Receipts, *state.StateDB)
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) 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 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 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
// Transaction pool API // Transaction pool API
SendTx(ctx context.Context, signedTx *types.Transaction) error 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 TxIndexDone() bool
GetPoolTransactions() (types.Transactions, error) GetPoolTransactions() (types.Transactions, error)
GetPoolTransaction(txHash common.Hash) *types.Transaction GetPoolTransaction(txHash common.Hash) *types.Transaction

View file

@ -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) { func (b *backendMock) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
return nil, nil 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 return nil, nil
} }
func (b *backendMock) GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error) { 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 return nil
} }
func (b *backendMock) SendTx(ctx context.Context, signedTx *types.Transaction) error { 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 return false, nil, [32]byte{}, 0, 0
} }
func (b *backendMock) TxIndexDone() bool { return true } func (b *backendMock) TxIndexDone() bool { return true }