Skip to content

Commit

Permalink
fix(rawdb, api): fix rawdb.writeSkippedTransaction & `api.GetSkippe…
Browse files Browse the repository at this point in the history
…dTransaction` (#503)

* fix(rawsdb): fix `writeSkippedTransaction`

* Update version.go

* minor

* clean up
  • Loading branch information
0xmountaintop authored Sep 7, 2023
1 parent c75ebdb commit dade96d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions core/rawdb/accessors_skipped_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,17 @@ type SkippedTransactionV2 struct {

// writeSkippedTransaction writes a skipped transaction to the database.
func writeSkippedTransaction(db ethdb.KeyValueWriter, tx *types.Transaction, traces *types.BlockTrace, reason string, blockNumber uint64, blockHash *common.Hash) {
var err error
// workaround: RLP decoding fails if this is nil
if blockHash == nil {
blockHash = &common.Hash{}
}
b, err := json.Marshal(traces)
if err != nil {
log.Crit("Failed to json marshal skipped transaction", "hash", tx.Hash().String(), "err", err)
stx := SkippedTransactionV2{Tx: tx, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
if traces != nil {
if stx.TracesBytes, err = json.Marshal(traces); err != nil {
log.Crit("Failed to json marshal skipped transaction", "hash", tx.Hash().String(), "err", err)
}
}
stx := SkippedTransactionV2{Tx: tx, TracesBytes: b, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
bytes, err := rlp.EncodeToBytes(stx)
if err != nil {
log.Crit("Failed to RLP encode skipped transaction", "hash", tx.Hash().String(), "err", err)
Expand Down
4 changes: 3 additions & 1 deletion eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,11 @@ func (api *ScrollAPI) GetSkippedTransaction(ctx context.Context, hash common.Has
rpcTx.SkipBlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(stx.BlockNumber))
rpcTx.SkipBlockHash = stx.BlockHash
if len(stx.TracesBytes) != 0 {
if err := json.Unmarshal(stx.TracesBytes, rpcTx.Traces); err != nil {
traces := &types.BlockTrace{}
if err := json.Unmarshal(stx.TracesBytes, traces); err != nil {
return nil, fmt.Errorf("fail to Unmarshal traces for skipped tx, hash: %s, err: %w", hash.String(), err)
}
rpcTx.Traces = traces
}
return &rpcTx, nil
}
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 4 // Major version component of the current release
VersionMinor = 4 // Minor version component of the current release
VersionPatch = 1 // Patch version component of the current release
VersionPatch = 2 // Patch version component of the current release
VersionMeta = "sepolia" // Version metadata to append to the version string
)

Expand Down

0 comments on commit dade96d

Please # to comment.