Skip to content

Commit

Permalink
feat: adds v1 tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed May 29, 2024
1 parent 1e009d2 commit fb28437
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,10 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
vmenv := b.GetEVM(ctx, msg, statedb, header, &config, nil)
res, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
if err != nil {
log.Error("Failed to apply message", "txHash", args.toTransaction().Hash(), "error", err)
} else {
log.Info("Successfully applied message", "txHash", args.toTransaction().Hash())
}
return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", args.toTransaction().Hash(), err)
}
if tracer.Equal(prevTracer) {
Expand Down
12 changes: 10 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@ func (w *worker) updateSnapshot(env *environment) {
w.snapshotState = env.state.Copy()
}

// This function commits a transaction to the EVM.
// If the transaction type is BlobTxType, it calls the commitBlobTransaction function.
// Otherwise, it applies the transaction and updates the EVM state.
func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) {
if tx.Type() == types.BlobTxType {
return w.commitBlobTransaction(env, tx)
Expand All @@ -762,7 +765,6 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*
env.receipts = append(env.receipts, receipt)
return receipt.Logs, nil
}

func (w *worker) commitBlobTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) {
sc := tx.BlobTxSidecar()
if sc == nil {
Expand Down Expand Up @@ -793,14 +795,20 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction) (*typ
snap = env.state.Snapshot()
gp = env.gasPool.Gas()
)
log.Info("Applying transaction", "tx_hash", tx.Hash(), "coinbase", env.coinbase, "gas_available", gp)
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &env.coinbase, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, *w.chain.GetVMConfig())
if err != nil {
log.Error("Transaction application failed", "tx_hash", tx.Hash(), "error", err)
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gp)
} else {
log.Info("Transaction applied successfully", "tx_hash", tx.Hash(), "gas_used", env.header.GasUsed)
}
return receipt, err
}

// This function commits transactions by processing them in order of price and nonce.
// It handles transaction execution, gas and tip calculations, and interruption handling.
func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAndNonce, interrupt *atomic.Int32, minTip *big.Int) error {
gasLimit := env.header.GasLimit
if env.gasPool == nil {
Expand All @@ -827,7 +835,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
}
// If we don't have enough space for the next transaction, skip the account.
if env.gasPool.Gas() < ltx.Gas {
log.Trace("Not enough gas left for transaction", "hash", ltx.Hash, "left", env.gasPool.Gas(), "needed", ltx.Gas)
log.Info("Not enough gas left for transaction", "hash", ltx.Hash, "left", env.gasPool.Gas(), "needed", ltx.Gas)
txs.Pop()
continue
}
Expand Down

0 comments on commit fb28437

Please sign in to comment.