From 43c0685ac67eaf56b49440fdcf4697b2e0947455 Mon Sep 17 00:00:00 2001 From: David Zhou Date: Thu, 5 Jun 2025 15:12:24 -0400 Subject: [PATCH 1/2] FIX: Added receipt in ApplyMessage --- consensus/bor/statefull/processor.go | 55 +++++++++++++++------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/consensus/bor/statefull/processor.go b/consensus/bor/statefull/processor.go index be80605aaa..bed739927d 100644 --- a/consensus/bor/statefull/processor.go +++ b/consensus/bor/statefull/processor.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "github.com/ethereum/go-ethereum/core/tracing" + "github.com/ethereum/go-ethereum/crypto" "math" "math/big" @@ -74,25 +75,6 @@ func ApplyMessage( tracer *tracing.Hooks, ) (uint64, error) { - initialGas := msg.Gas() - - blockContext := core.NewEVMBlockContext(header, chainContext, &header.Coinbase) - - // Create a new environment which holds all relevant information - // about the transaction and calling mechanisms. - msgForCtx := core.Message{ - To: msg.To(), - From: msg.From(), - Nonce: msg.Nonce(), - Value: msg.Value(), - GasLimit: msg.Gas(), - GasPrice: msg.GasPrice(), - SkipNonceChecks: false, - SkipFromEOACheck: false, - } - txContext := core.NewEVMTxContext(&msgForCtx) - vmenv := vm.NewEVM(blockContext, txContext, state, chainConfig, vm.Config{Tracer: tracer}) - tx := types.NewTx(&types.LegacyTx{ Nonce: msg.Nonce(), GasPrice: msg.GasPrice(), @@ -103,19 +85,20 @@ func ApplyMessage( }) state.SetTxContext(tx.Hash(), 0) - // Notify tracers about transaction start (system call is already started at Bor level) + initialGas := msg.Gas() + + blockContext := core.NewEVMBlockContext(header, chainContext, &header.Coinbase) + + // Create a new environment which holds all relevant information + // about the transaction and calling mechanisms. + vmenv := vm.NewEVM(blockContext, vm.TxContext{}, state, chainConfig, vm.Config{Tracer: tracer}) + if tracer != nil { if tracer.OnTxStart != nil { tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From()) } } - defer func() { - if tracer != nil && tracer.OnTxEnd != nil { - tracer.OnTxEnd(nil, nil) - } - }() - // nolint : contextcheck // Apply the transaction to the current state (included in the env) ret, gasLeft, err := vmenv.Call( @@ -149,6 +132,26 @@ func ApplyMessage( gasUsed := initialGas - gasLeft + if tracer != nil { + blockHash := header.Hash() + cumulativeGasUsed := gasUsed + + receipt := types.NewReceipt(nil, err != nil, cumulativeGasUsed) + receipt.TxHash = tx.Hash() + receipt.GasUsed = gasUsed + + if msg.To() == nil { + receipt.ContractAddress = crypto.CreateAddress(vmenv.TxContext.Origin, tx.Nonce()) + } + + receipt.Logs = state.GetLogs(tx.Hash(), header.Number.Uint64(), blockHash) + receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) + receipt.BlockHash = blockHash + receipt.BlockNumber = header.Number + receipt.TransactionIndex = 0 + tracer.OnTxEnd(receipt, nil) + } + return gasUsed, nil } From 8a15a4201599d62faccf4c75028480aa36fa69c9 Mon Sep 17 00:00:00 2001 From: David Zhou Date: Thu, 5 Jun 2025 15:25:10 -0400 Subject: [PATCH 2/2] FIX: Removed unused parameter spanID --- consensus/bor/contract/client.go | 2 +- consensus/bor/heimdall/span/spanner.go | 2 +- consensus/bor/statefull/processor.go | 1 - eth/tracers/api.go | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/consensus/bor/contract/client.go b/consensus/bor/contract/client.go index 910eff1d4c..42247f9614 100644 --- a/consensus/bor/contract/client.go +++ b/consensus/bor/contract/client.go @@ -93,7 +93,7 @@ func (gc *GenesisContractsClient) CommitState( log.Info("→ committing new state", "eventRecord", event.ID) - gasUsed, err := statefull.ApplyMessage(context.Background(), msg, state, header, gc.chainConfig, chCtx, 0, tracer) + gasUsed, err := statefull.ApplyMessage(context.Background(), msg, state, header, gc.chainConfig, chCtx, tracer) // Logging event log with time and individual gasUsed log.Info("→ committed new state", "eventRecord", event.String(gasUsed)) diff --git a/consensus/bor/heimdall/span/spanner.go b/consensus/bor/heimdall/span/spanner.go index 26841443b4..09433fea1d 100644 --- a/consensus/bor/heimdall/span/spanner.go +++ b/consensus/bor/heimdall/span/spanner.go @@ -336,7 +336,7 @@ func (c *ChainSpanner) CommitSpan(ctx context.Context, heimdallSpan HeimdallSpan msg := statefull.GetSystemMessage(c.validatorContractAddress, data) // apply message - _, err = statefull.ApplyMessage(ctx, msg, state, header, c.chainConfig, chainContext, 0, tracer) + _, err = statefull.ApplyMessage(ctx, msg, state, header, c.chainConfig, chainContext, tracer) return err } diff --git a/consensus/bor/statefull/processor.go b/consensus/bor/statefull/processor.go index bed739927d..e75354da97 100644 --- a/consensus/bor/statefull/processor.go +++ b/consensus/bor/statefull/processor.go @@ -71,7 +71,6 @@ func ApplyMessage( header *types.Header, chainConfig *params.ChainConfig, chainContext core.ChainContext, - spanID int64, tracer *tracing.Hooks, ) (uint64, error) { diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 1e01331694..43ba248c8d 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -711,7 +711,7 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config if *config.BorTraceEnabled { callmsg := prepareCallMessage(*msg) statedb.SetTxContext(stateSyncHash, i) - if _, err := statefull.ApplyMessage(ctx, callmsg, statedb, block.Header(), api.backend.ChainConfig(), api.chainContext(ctx), 0, nil); err != nil { + if _, err := statefull.ApplyMessage(ctx, callmsg, statedb, block.Header(), api.backend.ChainConfig(), api.chainContext(ctx), nil); err != nil { log.Warn("Tracing intermediate roots did not complete", "txindex", i, "txhash", stateSyncHash, "err", err) // We intentionally don't return the error here: if we do, then the RPC server will not // return the roots. Most likely, the caller already knows that a certain transaction fails to