Skip to content

Commit

Permalink
Notify on every message regardless of the failure + Nonce on pending …
Browse files Browse the repository at this point in the history
…fix (#168)
  • Loading branch information
lukanus authored Mar 14, 2024
1 parent 193e27c commit 59a0cd0
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions eth/filters/trace_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,43 +86,50 @@ func (api *FilterAPI) NewPendingTransactionsWithTrace(ctx context.Context, trace
header.ExcessBlobGas = &ex
}

blockCtx := core.NewEVMBlockContext(header, api.sys.chain, nil)
for _, tx := range txs {
rpcTx := newRPCPendingTransaction(tx)
if rpcTx == nil {
tracedTxs = append(tracedTxs, nil)
continue
}
rpcTx.BlockHash = &blockHash
rpcTx.BlockNumber = &blockNumber
rpcTx.TransactionIndex = &txIndex
gasPrice := hexutil.Big(*tx.GasPrice())
rpcTx.GasPrice = &gasPrice
tracedTxs = append(tracedTxs, rpcTx)
}

blockCtx := core.NewEVMBlockContext(header, api.sys.chain, nil)
statedb, err := api.sys.chain.State()
if err != nil {
log.Error("failed to get state", "err", err)
notifier.Notify(rpcSub.ID, tracedTxs)
return
}

for _, tx := range txs {
msg, _ = core.TransactionToMessage(tx, signer, header.BaseFee)
if err != nil {
log.Error("failed to create tx message", "err", err, "tx", tx.Hash())
for i, tx := range tracedTxs {
if tx == nil {
continue
}

traceCtx.TxHash = tx.Hash()
trace, err := traceTx(msg, traceCtx, blockCtx, chainConfig, statedb, tracerOpts)
msg, err = core.TransactionToMessage(txs[i], signer, header.BaseFee)
if err != nil {
log.Info("failed to trace tx", "err", err, "tx", tx.Hash())
log.Error("failed to create tx message", "err", err, "tx", tx.Hash)
continue
}
msg.SkipAccountChecks = true

gasPrice := hexutil.Big(*tx.GasPrice())
rpcTx := newRPCPendingTransaction(tx)
rpcTx.BlockHash = &blockHash
rpcTx.BlockNumber = &blockNumber
rpcTx.TransactionIndex = &txIndex
rpcTx.Trace = trace
rpcTx.GasPrice = &gasPrice
tracedTxs = append(tracedTxs, rpcTx)
}

if len(tracedTxs) == 0 {
continue
traceCtx.TxHash = tx.Hash
tx.Trace, err = traceTx(msg, traceCtx, blockCtx, chainConfig, statedb, tracerOpts)
if err != nil {
log.Info("failed to trace tx", "err", err, "tx", tx.Hash)
continue
}
}

notifier.Notify(rpcSub.ID, tracedTxs)

case <-rpcSub.Err():
return
}
Expand Down Expand Up @@ -189,7 +196,7 @@ func (api *FilterAPI) NewFullBlocksWithTrace(ctx context.Context, tracerOptsJSON
log.Error("failed to marshal block", "err", err, "block", block.Number())
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())
Expand Down Expand Up @@ -239,7 +246,7 @@ func traceTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockContex
tracer, err := blocknative.NewTracerWithOpts(tracerOpts)
if err != nil {
return nil, err
}
}
vmenv := vm.NewEVM(vmctx, core.NewEVMTxContext(message), statedb, chainConfig, vm.Config{Tracer: tracer, NoBaseFee: true})
statedb.SetTxContext(txCtx.TxHash, txCtx.TxIndex)

Expand Down

0 comments on commit 59a0cd0

Please sign in to comment.