Skip to content

Commit 7d908e6

Browse files
committed
fix RLP encoding issue
1 parent d463e3c commit 7d908e6

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

core/rawdb/accessors_skipped_txs.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rawdb
33
import (
44
"bytes"
55
"encoding/binary"
6+
"encoding/json"
67
"math/big"
78
"sync"
89

@@ -52,8 +53,10 @@ type SkippedTransaction struct {
5253
Tx *types.Transaction
5354

5455
// Traces is the wrapped traces of the skipped transaction.
55-
// We only store it when `MinerStoreSkippedTxTracesFlag` is enabled, so it may return nil.
56-
Traces *types.BlockTrace
56+
// We only store it when `MinerStoreSkippedTxTracesFlag` is enabled, so it might be empty.
57+
// Note that we don't use *types.BlockTrace directly because types.BlockTrace.StorageTrace.Proofs is of
58+
// type map[string][]hexutil.Bytes, and is not RLP-serializable.
59+
TracesBytes []byte
5760

5861
// Reason is the skip reason.
5962
Reason string
@@ -71,10 +74,14 @@ func writeSkippedTransaction(db ethdb.KeyValueWriter, tx *types.Transaction, tra
7174
if blockHash == nil {
7275
blockHash = &common.Hash{}
7376
}
74-
stx := SkippedTransaction{Tx: tx, Traces: traces, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
77+
b, err := json.Marshal(traces)
78+
if err != nil {
79+
log.Crit("Failed to json marshal skipped transaction", "hash", tx.Hash().String(), "err", err)
80+
}
81+
stx := SkippedTransaction{Tx: tx, TracesBytes: b, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
7582
bytes, err := rlp.EncodeToBytes(stx)
7683
if err != nil {
77-
log.Crit("Failed to RLP encode skipped transaction", "err", err)
84+
log.Crit("Failed to RLP encode skipped transaction", "hash", tx.Hash().String(), "err", err)
7885
}
7986
if err := db.Put(SkippedTransactionKey(tx.Hash()), bytes); err != nil {
8087
log.Crit("Failed to store skipped transaction", "hash", tx.Hash().String(), "err", err)

eth/api.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package eth
1919
import (
2020
"compress/gzip"
2121
"context"
22+
"encoding/json"
2223
"errors"
2324
"fmt"
2425
"io"
@@ -728,8 +729,14 @@ func (api *ScrollAPI) GetSkippedTransaction(ctx context.Context, hash common.Has
728729
if stx == nil {
729730
return nil, nil
730731
}
732+
var traces *types.BlockTrace
733+
if len(stx.TracesBytes) != 0 {
734+
if err := json.Unmarshal(stx.TracesBytes, traces); err != nil {
735+
return nil, fmt.Errorf("fail to Unmarshal traces for skipped tx, hash: %s, err: %w", hash.String(), err)
736+
}
737+
}
731738
var rpcTx RPCTransaction
732-
rpcTx.RPCTransaction = *ethapi.NewRPCTransaction(stx.Tx, stx.Traces, common.Hash{}, 0, 0, nil, api.eth.blockchain.Config())
739+
rpcTx.RPCTransaction = *ethapi.NewRPCTransaction(stx.Tx, traces, common.Hash{}, 0, 0, nil, api.eth.blockchain.Config())
733740
rpcTx.SkipReason = stx.Reason
734741
rpcTx.SkipBlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(stx.BlockNumber))
735742
rpcTx.SkipBlockHash = stx.BlockHash

0 commit comments

Comments
 (0)