Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify on every message regardless of the failure + Nonce on pending fix #168

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading