mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Merge pull request #19 from streamingfast/battlefield-integration
FIX: Added receipt in processor.go/ApplyMessage
This commit is contained in:
commit
96ec0a70d8
4 changed files with 32 additions and 30 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"math"
|
||||
"math/big"
|
||||
|
||||
|
|
@ -70,29 +71,9 @@ func ApplyMessage(
|
|||
header *types.Header,
|
||||
chainConfig *params.ChainConfig,
|
||||
chainContext core.ChainContext,
|
||||
spanID int64,
|
||||
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 +84,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 +131,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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue