Update accessors_indexes.go

This commit is contained in:
Felix Lange 2025-06-16 14:57:48 +02:00 committed by GitHub
parent 7623170f6a
commit 3bd0deacbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -154,28 +154,26 @@ func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, com
return nil, common.Hash{}, 0, 0 return nil, common.Hash{}, 0, 0
} }
txIndex := 0 txIndex := uint64(0)
for txnIterator.Next() && txnIterator.Err() == nil { for txnIterator.Next() && txnIterator.Err() == nil {
txnRLP := txnIterator.Value() // The preimage for the hash calculation of legacy transactions
// is just their RLP encoding. For typed (EIP-2718) transactions,
// Preimage for hash calculation of legacy transactions // which are encoded as byte arrays, the preimage is the content of
// are just their RLP encoding, but for EIP-2728 transactions // the byte array, so trim their prefix here.
// the prefix needs to be trimmed before hashing. txRLP := txnIterator.Value()
rlpKind, hashPreimage, _, err := rlp.Split(txnRLP) rlpKind, txHashPayload, _, err := rlp.Split(txRLP)
if err != nil { if err != nil {
return nil, common.Hash{}, 0, 0 return nil, common.Hash{}, 0, 0
} }
// Legacy transactions are encoded as rlp lists.
if rlpKind == rlp.List { if rlpKind == rlp.List {
hashPreimage = txnRLP txHashPayload = txRLP
} }
if crypto.Keccak256Hash(txHashPayload) == hash {
if crypto.Keccak256Hash(hashPreimage) == hash {
var tx types.Transaction var tx types.Transaction
if err := rlp.DecodeBytes(txnRLP, &tx); err != nil { if err := rlp.DecodeBytes(txRLP, &tx); err != nil {
return nil, common.Hash{}, 0, 0 return nil, common.Hash{}, 0, 0
} }
return &tx, blockHash, *blockNumber, uint64(txIndex) return &tx, blockHash, *blockNumber, txIndex
} }
txIndex++ txIndex++
} }