Skip to content

Commit

Permalink
e3: fix eth_getLogs data field (#12047)
Browse files Browse the repository at this point in the history
for #12045
  • Loading branch information
AskAlexSharov committed Sep 23, 2024
1 parent 336e1e7 commit e528765
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
16 changes: 9 additions & 7 deletions cmd/state/exec3/historical_trace_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func NewHistoricalTraceWorker(
logger: logger,
taskGasPool: new(core.GasPool),
}
ie.taskGasPool.AddBlobGas(execArgs.ChainConfig.GetMaxBlobGasPerBlock())
ie.ibs = state.New(ie.stateReader)

return ie
}

func (rw *HistoricalTraceWorker) Run() error {
defer rw.evm.JumpDestCache.LogStats()
for txTask, ok := rw.in.Next(rw.ctx); ok; txTask, ok = rw.in.Next(rw.ctx) {
rw.RunTxTask(txTask)
if err := rw.out.Add(rw.ctx, txTask); err != nil {
Expand All @@ -133,9 +133,7 @@ func (rw *HistoricalTraceWorker) RunTxTask(txTask *state.TxTask) {
}

rw.stateReader.SetTxNum(txTask.TxNum)
//rw.stateWriter.SetTxNum(rw.ctx, txTask.TxNum)
rw.stateReader.ResetReadSet()
//rw.stateWriter.ResetWriteSet()
rw.stateWriter = state.NewNoopWriter()

rw.ibs.Reset()
Expand Down Expand Up @@ -179,17 +177,15 @@ func (rw *HistoricalTraceWorker) RunTxTask(txTask *state.TxTask) {
txTask.Error = err
}
default:
rw.taskGasPool.Reset(txTask.Tx.GetGas(), rw.execArgs.ChainConfig.GetMaxBlobGasPerBlock())
rw.taskGasPool.Reset(txTask.Tx.GetGas(), txTask.Tx.GetBlobGas())
if tracer := rw.consumer.NewTracer(); tracer != nil {
rw.vmConfig.Debug = true
rw.vmConfig.Tracer = tracer
}
rw.vmConfig.SkipAnalysis = txTask.SkipAnalysis
ibs.SetTxContext(txTask.TxIndex)
msg := txTask.TxAsMessage

rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, core.NewEVMTxContext(msg), ibs, *rw.vmConfig, rules)

msg.SetCheckNonce(!rw.vmConfig.StatelessExec)
if msg.FeeCap().IsZero() {
// Only zero-gas transactions may be service ones
syscall := func(contract common.Address, data []byte) ([]byte, error) {
Expand All @@ -198,6 +194,12 @@ func (rw *HistoricalTraceWorker) RunTxTask(txTask *state.TxTask) {
msg.SetIsFree(rw.execArgs.Engine.IsServiceTransaction(msg.From(), syscall))
}

txContext := core.NewEVMTxContext(msg)
if rw.vmConfig.TraceJumpDest {
txContext.TxHash = txTask.Tx.Hash()
}
rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, txContext, ibs, *rw.vmConfig, rules)

// MA applytx
applyRes, err := core.ApplyMessage(rw.evm, msg, rw.taskGasPool, true /* refunds */, false /* gasBailout */)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/state/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, mode stages.Mode) {
rw.vmCfg.SkipAnalysis = txTask.SkipAnalysis
ibs.SetTxContext(txTask.TxIndex)
msg := txTask.TxAsMessage

rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, core.NewEVMTxContext(msg), ibs, rw.vmCfg, rules)

if msg.FeeCap().IsZero() && rw.engine != nil {
// Only zero-gas transactions may be service ones
syscall := func(contract libcommon.Address, data []byte) ([]byte, error) {
Expand All @@ -269,6 +266,8 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, mode stages.Mode) {
msg.SetIsFree(rw.engine.IsServiceTransaction(msg.From(), syscall))
}

rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, core.NewEVMTxContext(msg), ibs, rw.vmCfg, rules)

// MA applytx
applyRes, err := core.ApplyMessage(rw.evm, msg, rw.taskGasPool, true /* refunds */, false /* gasBailout */)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/state/exec3/state_recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,21 @@ func (rw *ReconWorker) runTxTask(txTask *state.TxTask) error {
vmConfig := vm.Config{NoReceipts: true, SkipAnalysis: txTask.SkipAnalysis}
ibs.SetTxContext(txTask.TxIndex)
msg := txTask.TxAsMessage

rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, core.NewEVMTxContext(msg), ibs, vmConfig, txTask.Rules)
vmenv := rw.evm
if msg.FeeCap().IsZero() && rw.engine != nil {
msg.SetCheckNonce(!vmConfig.StatelessExec)
if msg.FeeCap().IsZero() {
// Only zero-gas transactions may be service ones
syscall := func(contract libcommon.Address, data []byte) ([]byte, error) {
return core.SysCallContract(contract, data, rw.chainConfig, ibs, header, rw.engine, true /* constCall */)
}
msg.SetIsFree(rw.engine.IsServiceTransaction(msg.From(), syscall))
}

//fmt.Printf("txNum=%d, blockNum=%d, txIndex=%d\n", txTask.TxNum, txTask.BlockNum, txTask.TxIndex)
_, err = core.ApplyMessage(vmenv, msg, gp, true /* refunds */, false /* gasBailout */)
txContext := core.NewEVMTxContext(msg)
if vmConfig.TraceJumpDest {
txContext.TxHash = txTask.Tx.Hash()
}
rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, txContext, ibs, vmConfig, txTask.Rules)
_, err = core.ApplyMessage(rw.evm, msg, gp, true /* refunds */, false /* gasBailout */)
if err != nil {
if _, readError := rw.stateReader.ReadError(); !readError {
return fmt.Errorf("could not apply blockNum=%d, txIdx=%d txNum=%d [%x] failed: %w", txTask.BlockNum, txTask.TxIndex, txTask.TxNum, txTask.Tx.Hash(), err)
Expand Down
14 changes: 11 additions & 3 deletions cmd/state/exec3/trace_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/erigontech/erigon-lib/chain"
"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/kv"

"github.com/erigontech/erigon/consensus"
"github.com/erigontech/erigon/core"
"github.com/erigontech/erigon/core/state"
Expand Down Expand Up @@ -108,23 +107,32 @@ func (e *TraceWorker) ExecTxn(txNum uint64, txIndex int, txn types.Transaction)
e.stateReader.SetTxNum(txNum)
e.ibs.Reset()
e.ibs.SetTxContext(txIndex)
gp := new(core.GasPool).AddGas(txn.GetGas()).AddBlobGas(txn.GetBlobGas())

msg, err := txn.AsMessage(*e.signer, e.header.BaseFee, e.rules)
if err != nil {
return nil, err
}
e.evm.ResetBetweenBlocks(*e.blockCtx, core.NewEVMTxContext(msg), e.ibs, *e.vmConfig, e.rules)
msg.SetCheckNonce(!e.vmConfig.StatelessExec)
if msg.FeeCap().IsZero() {
// Only zero-gas transactions may be service ones
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return core.SysCallContract(contract, data, e.chainConfig, e.ibs, e.header, e.engine, true /* constCall */)
}
msg.SetIsFree(e.engine.IsServiceTransaction(msg.From(), syscall))
}

txContext := core.NewEVMTxContext(msg)
if e.vmConfig.TraceJumpDest {
txContext.TxHash = txn.Hash()
}
e.evm.ResetBetweenBlocks(*e.blockCtx, txContext, e.ibs, *e.vmConfig, e.rules)

gp := new(core.GasPool).AddGas(txn.GetGas()).AddBlobGas(txn.GetBlobGas())
res, err := core.ApplyMessage(e.evm, msg, gp, true /* refunds */, false /* gasBailout */)
if err != nil {
return nil, fmt.Errorf("%w: blockNum=%d, txNum=%d, %s", err, e.blockNum, txNum, e.ibs.Error())
}
e.ibs.SoftFinalise()
if e.vmConfig.Tracer != nil {
if e.tracer.Found() {
e.tracer.SetTransaction(txn)
Expand Down
2 changes: 1 addition & 1 deletion turbo/jsonrpc/eth_callMany.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont
}
txCtx = core.NewEVMTxContext(msg)
evm = vm.NewEVM(blockCtx, txCtx, evm.IntraBlockState(), chainConfig, vm.Config{Debug: false})
result, err := core.ApplyMessage(evm, msg, gp, true, false)
result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e528765

Please sign in to comment.