fix(rawdb, api): fix rawdb.writeSkippedTransaction & api.GetSkippedTransaction (#503)

* fix(rawsdb): fix `writeSkippedTransaction`

* Update version.go

* minor

* clean up
This commit is contained in:
HAOYUatHZ 2023-09-07 15:35:04 +08:00 committed by GitHub
parent c75ebdbdb0
commit dade96d416
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View file

@ -86,15 +86,17 @@ type SkippedTransactionV2 struct {
// writeSkippedTransaction writes a skipped transaction to the database. // 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) { 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 // workaround: RLP decoding fails if this is nil
if blockHash == nil { if blockHash == nil {
blockHash = &common.Hash{} blockHash = &common.Hash{}
} }
b, err := json.Marshal(traces) stx := SkippedTransactionV2{Tx: tx, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
if err != nil { 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) 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) bytes, err := rlp.EncodeToBytes(stx)
if err != nil { if err != nil {
log.Crit("Failed to RLP encode skipped transaction", "hash", tx.Hash().String(), "err", err) log.Crit("Failed to RLP encode skipped transaction", "hash", tx.Hash().String(), "err", err)

View file

@ -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.SkipBlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(stx.BlockNumber))
rpcTx.SkipBlockHash = stx.BlockHash rpcTx.SkipBlockHash = stx.BlockHash
if len(stx.TracesBytes) != 0 { 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) return nil, fmt.Errorf("fail to Unmarshal traces for skipped tx, hash: %s, err: %w", hash.String(), err)
} }
rpcTx.Traces = traces
} }
return &rpcTx, nil return &rpcTx, nil
} }

View file

@ -24,7 +24,7 @@ import (
const ( const (
VersionMajor = 4 // Major version component of the current release VersionMajor = 4 // Major version component of the current release
VersionMinor = 4 // Minor 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 VersionMeta = "sepolia" // Version metadata to append to the version string
) )