Skip to content

Commit 6ffdec3

Browse files
committed
fix searching for tx hash in block for ArbitrumLegacyTx
1 parent ae34a6a commit 6ffdec3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

core/rawdb/accessors_indexes.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ func findTxInBlockBody(blockbody rlp.RawValue, target common.Hash) (*types.Trans
162162
if kind == rlp.List { // Legacy transaction
163163
txHashPayload = txRLP
164164
}
165-
if crypto.Keccak256Hash(txHashPayload) == target {
166-
var tx types.Transaction
167-
if err := rlp.DecodeBytes(txRLP, &tx); err != nil {
168-
return nil, 0, err
165+
// arbitrum: decode txRLP to check tx type and support HashOverride in case of ArbitrumLegacyTx (happens in (*Transaction)Hash)
166+
var tx types.Transaction
167+
if err := rlp.DecodeBytes(txRLP, &tx); err != nil {
168+
return nil, 0, err
169+
}
170+
// arbitrum: only use Hash() method for ArbitrumLegacyTxType, otherwise use the optimised path that does not involve encoding the RLP again
171+
if tx.Type() == types.ArbitrumLegacyTxType {
172+
if tx.Hash() == target {
173+
return &tx, txIndex, nil
169174
}
175+
} else if crypto.Keccak256Hash(txHashPayload) == target {
170176
return &tx, txIndex, nil
171177
}
172178
txIndex++

core/rawdb/accessors_indexes_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func TestFindTxInBlockBody(t *testing.T) {
130130
Value: big.NewInt(5),
131131
Data: []byte{0x11, 0x11, 0x11},
132132
})
133+
arbitrumLegacyTx, err := types.NewArbitrumLegacyTx(tx1, common.HexToHash("0xdeadbeef"), 0, 0, new(common.Address))
134+
if err != nil {
135+
t.Fatalf("Failed to create ArbitrumLegacyTx, err: %v", err)
136+
}
133137
tx2 := types.NewTx(&types.AccessListTx{
134138
Nonce: 1,
135139
GasPrice: big.NewInt(1),
@@ -198,7 +202,7 @@ func TestFindTxInBlockBody(t *testing.T) {
198202
},
199203
})
200204

201-
txs := []*types.Transaction{tx1, tx2, tx3, tx4, tx5}
205+
txs := []*types.Transaction{tx1, arbitrumLegacyTx, tx2, tx3, tx4, tx5}
202206

203207
block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, &types.Body{Transactions: txs}, nil, newTestHasher())
204208
db := NewMemoryDatabase()

0 commit comments

Comments
 (0)