From 70684e927f02391f1209ef763db7d727b9c652d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mi=C5=82kowski?= Date: Tue, 19 Mar 2024 18:15:46 +0100 Subject: [PATCH] Enforce the copy of state for pending tx (#171) --- eth/filters/trace_api.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/eth/filters/trace_api.go b/eth/filters/trace_api.go index 13f00b1040ce..57a44b23948f 100644 --- a/eth/filters/trace_api.go +++ b/eth/filters/trace_api.go @@ -101,15 +101,13 @@ func (api *FilterAPI) NewPendingTransactionsWithTrace(ctx context.Context, trace tracedTxs = append(tracedTxs, rpcTx) } - statedb, err := api.sys.chain.State() + sDB, err := api.sys.chain.State() if err != nil { log.Error("failed to get state", "err", err) notifier.Notify(rpcSub.ID, tracedTxs) return } - blockCtx := core.NewEVMBlockContext(header, api.sys.chain, nil) - snapID := statedb.Snapshot() for i, tx := range tracedTxs { if tx == nil { @@ -126,11 +124,8 @@ func (api *FilterAPI) NewPendingTransactionsWithTrace(ctx context.Context, trace msg.GasFeeCap = common.Big0 // skip the check of ErrFeeCapTooLow msg.GasTipCap = common.Big0 // skip the check of ErrFeeCapTooLow - if i > 0 && snapID > 0 { - statedb.RevertToSnapshot(snapID) - } traceCtx.TxHash = tx.Hash - tx.Trace, err = traceTx(msg, traceCtx, blockCtx, chainConfig, statedb, tracerOpts) + tx.Trace, err = traceTx(msg, traceCtx, blockCtx, chainConfig, sDB.Copy(), tracerOpts) if err != nil { log.Info("failed to trace tx", "err", err, "tx", tx.Hash) } @@ -205,11 +200,11 @@ func (api *FilterAPI) NewFullBlocksWithTrace(ctx context.Context, tracerOptsJSON continue } - trace, _ := traceBlock(block, chainConfig, api.sys.chain, tracerOpts) - // if err != nil { - // log.Info("failed to trace block", "err", err, "hash", hash, "block", block.Number()) - // continue - // } + trace, err := traceBlock(block, chainConfig, api.sys.chain, tracerOpts) + if err != nil { + log.Info("failure in block trace", "err", err, "hash", hash, "block", block.Number()) + } + marshalBlock["trace"] = trace marshalReceipts := make(map[common.Hash]map[string]interface{}) receipts, err := api.sys.backend.GetReceipts(ctx, hash)