mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
cmd, core, eth, internal, miner: wrap pre-execution system calls
This commit is contained in:
parent
297adcb2f0
commit
2f5090b322
6 changed files with 38 additions and 40 deletions
|
|
@ -230,16 +230,17 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
||||||
misc.ApplyDAOHardFork(statedb)
|
misc.ApplyDAOHardFork(statedb)
|
||||||
}
|
}
|
||||||
evm := vm.NewEVM(vmContext, statedb, chainConfig, vmConfig)
|
evm := vm.NewEVM(vmContext, statedb, chainConfig, vmConfig)
|
||||||
if beaconRoot := pre.Env.ParentBeaconBlockRoot; beaconRoot != nil {
|
|
||||||
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
var (
|
||||||
}
|
prevNumber uint64
|
||||||
|
prevHash common.Hash
|
||||||
|
)
|
||||||
if pre.Env.BlockHashes != nil && chainConfig.IsPrague(new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp) {
|
if pre.Env.BlockHashes != nil && chainConfig.IsPrague(new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp) {
|
||||||
var (
|
prevNumber = pre.Env.Number - 1
|
||||||
prevNumber = pre.Env.Number - 1
|
prevHash = pre.Env.BlockHashes[math.HexOrDecimal64(prevNumber)]
|
||||||
prevHash = pre.Env.BlockHashes[math.HexOrDecimal64(prevNumber)]
|
|
||||||
)
|
|
||||||
core.ProcessParentBlockHash(prevHash, evm)
|
|
||||||
}
|
}
|
||||||
|
core.PreExecution(context.Background(), pre.Env.ParentBeaconBlockRoot, prevHash, chainConfig, evm, vmContext.BlockNumber, vmContext.Time)
|
||||||
|
|
||||||
for i := 0; txIt.Next(); i++ {
|
for i := 0; txIt.Next(); i++ {
|
||||||
tx, err := txIt.Tx()
|
tx, err := txIt.Tx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -81,21 +81,13 @@ func (p *StateProcessor) Process(ctx context.Context, block *types.Block, stated
|
||||||
misc.ApplyDAOHardFork(tracingStateDB)
|
misc.ApplyDAOHardFork(tracingStateDB)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
context vm.BlockContext
|
context = NewEVMBlockContext(header, p.chain, nil)
|
||||||
signer = types.MakeSigner(config, header.Number, header.Time)
|
signer = types.MakeSigner(config, header.Number, header.Time)
|
||||||
|
evm = vm.NewEVM(context, tracingStateDB, config, cfg)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Apply pre-execution system calls.
|
|
||||||
context = NewEVMBlockContext(header, p.chain, nil)
|
|
||||||
evm := vm.NewEVM(context, tracingStateDB, config, cfg)
|
|
||||||
defer evm.Release()
|
defer evm.Release()
|
||||||
|
// Run the pre-execution system calls
|
||||||
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
PreExecution(ctx, block.BeaconRoot(), block.ParentHash(), config, evm, block.Number(), block.Time())
|
||||||
ProcessBeaconBlockRoot(*beaconRoot, evm)
|
|
||||||
}
|
|
||||||
if config.IsPrague(block.Number(), block.Time()) || config.IsUBT(block.Number(), block.Time()) {
|
|
||||||
ProcessParentBlockHash(block.ParentHash(), evm)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over and process the individual transactions
|
// Iterate over and process the individual transactions
|
||||||
for i, tx := range block.Transactions() {
|
for i, tx := range block.Transactions() {
|
||||||
|
|
@ -118,6 +110,7 @@ func (p *StateProcessor) Process(ctx context.Context, block *types.Block, stated
|
||||||
allLogs = append(allLogs, receipt.Logs...)
|
allLogs = append(allLogs, receipt.Logs...)
|
||||||
spanEnd(nil)
|
spanEnd(nil)
|
||||||
}
|
}
|
||||||
|
// Run the post-execution system calls
|
||||||
requests, err := PostExecution(ctx, config, block.Number(), block.Time(), allLogs, evm)
|
requests, err := PostExecution(ctx, config, block.Number(), block.Time(), allLogs, evm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -133,6 +126,19 @@ func (p *StateProcessor) Process(ctx context.Context, block *types.Block, stated
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreExecution processes pre-execution system calls.
|
||||||
|
func PreExecution(ctx context.Context, beaconRoot *common.Hash, parent common.Hash, config *params.ChainConfig, evm *vm.EVM, number *big.Int, time uint64) {
|
||||||
|
_, _, spanEnd := telemetry.StartSpan(ctx, "core.preExecution")
|
||||||
|
defer spanEnd(nil)
|
||||||
|
|
||||||
|
if beaconRoot != nil {
|
||||||
|
ProcessBeaconBlockRoot(*beaconRoot, evm)
|
||||||
|
}
|
||||||
|
if config.IsPrague(number, time) || config.IsUBT(number, time) {
|
||||||
|
ProcessParentBlockHash(parent, evm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PostExecution processes post-execution system calls when Prague is enabled.
|
// PostExecution processes post-execution system calls when Prague is enabled.
|
||||||
// If Prague is not activated, it returns null requests to differentiate from
|
// If Prague is not activated, it returns null requests to differentiate from
|
||||||
// empty requests.
|
// empty requests.
|
||||||
|
|
|
||||||
|
|
@ -248,13 +248,10 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block,
|
||||||
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, nil)
|
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, nil)
|
||||||
evm := vm.NewEVM(context, statedb, eth.blockchain.Config(), vm.Config{})
|
evm := vm.NewEVM(context, statedb, eth.blockchain.Config(), vm.Config{})
|
||||||
defer evm.Release()
|
defer evm.Release()
|
||||||
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
|
||||||
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
// Run pre-execution system calls
|
||||||
}
|
core.PreExecution(ctx, block.BeaconRoot(), block.ParentHash(), eth.blockchain.Config(), evm, block.Number(), block.Time())
|
||||||
// If prague hardfork, insert parent block hash in the state as per EIP-2935.
|
|
||||||
if eth.blockchain.Config().IsPrague(block.Number(), block.Time()) {
|
|
||||||
core.ProcessParentBlockHash(block.ParentHash(), evm)
|
|
||||||
}
|
|
||||||
if txIndex == 0 && len(block.Transactions()) == 0 {
|
if txIndex == 0 && len(block.Transactions()) == 0 {
|
||||||
return nil, context, statedb, release, nil
|
return nil, context, statedb, release, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -372,6 +372,7 @@ func (api *API) traceChain(start, end *types.Block, config *TraceConfig, closed
|
||||||
// as per EIP-4788.
|
// as per EIP-4788.
|
||||||
context := core.NewEVMBlockContext(next.Header(), api.chainContext(ctx), nil)
|
context := core.NewEVMBlockContext(next.Header(), api.chainContext(ctx), nil)
|
||||||
evm := vm.NewEVM(context, statedb, api.backend.ChainConfig(), vm.Config{})
|
evm := vm.NewEVM(context, statedb, api.backend.ChainConfig(), vm.Config{})
|
||||||
|
|
||||||
if beaconRoot := next.BeaconRoot(); beaconRoot != nil {
|
if beaconRoot := next.BeaconRoot(); beaconRoot != nil {
|
||||||
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
core.ProcessBeaconBlockRoot(*beaconRoot, evm)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -318,12 +318,9 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
||||||
if precompiles != nil {
|
if precompiles != nil {
|
||||||
evm.SetPrecompiles(precompiles)
|
evm.SetPrecompiles(precompiles)
|
||||||
}
|
}
|
||||||
if sim.chainConfig.IsPrague(header.Number, header.Time) || sim.chainConfig.IsUBT(header.Number, header.Time) {
|
// Run pre-execution system calls
|
||||||
core.ProcessParentBlockHash(header.ParentHash, evm)
|
core.PreExecution(ctx, header.ParentBeaconRoot, header.ParentHash, sim.chainConfig, evm, header.Number, header.Time)
|
||||||
}
|
|
||||||
if header.ParentBeaconRoot != nil {
|
|
||||||
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, evm)
|
|
||||||
}
|
|
||||||
var allLogs []*types.Log
|
var allLogs []*types.Log
|
||||||
for i, call := range block.Calls {
|
for i, call := range block.Calls {
|
||||||
// Terminate if the context is cancelled
|
// Terminate if the context is cancelled
|
||||||
|
|
@ -393,7 +390,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
||||||
header.BlobGasUsed = &blobGasUsed
|
header.BlobGasUsed = &blobGasUsed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process EIP-7685 requests
|
// Run post-execution system calls
|
||||||
requests, err := core.PostExecution(ctx, sim.chainConfig, header.Number, header.Time, allLogs, evm)
|
requests, err := core.PostExecution(ctx, sim.chainConfig, header.Number, header.Time, allLogs, evm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
|
|
|
||||||
|
|
@ -317,12 +317,8 @@ func (miner *Miner) prepareWork(ctx context.Context, genParams *generateParams,
|
||||||
log.Error("Failed to create sealing context", "err", err)
|
log.Error("Failed to create sealing context", "err", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if header.ParentBeaconRoot != nil {
|
// Run pre-execution system calls
|
||||||
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, env.evm)
|
core.PreExecution(ctx, header.ParentBeaconRoot, header.ParentHash, miner.chainConfig, env.evm, header.Number, header.Time)
|
||||||
}
|
|
||||||
if miner.chainConfig.IsPrague(header.Number, header.Time) {
|
|
||||||
core.ProcessParentBlockHash(header.ParentHash, env.evm)
|
|
||||||
}
|
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue