mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-27 05:57:28 +00:00
41ee460a27
* optimize codeBitmap * add lru * remove custom lru * jumpDests as explocit parameter * lint * lint * linters * default jumpDestsCache * remove common.rand
85 lines
3.5 KiB
Go
85 lines
3.5 KiB
Go
// Copyright 2019 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package core
|
|
|
|
import (
|
|
"sync/atomic"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/consensus"
|
|
"github.com/ledgerwatch/turbo-geth/core/state"
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
"github.com/ledgerwatch/turbo-geth/core/vm"
|
|
"github.com/ledgerwatch/turbo-geth/params"
|
|
)
|
|
|
|
// statePrefetcher is a basic Prefetcher, which blindly executes a block on top
|
|
// of an arbitrary state with the goal of prefetching potentially useful state
|
|
// data from disk before the main block processor start executing.
|
|
type statePrefetcher struct {
|
|
config *params.ChainConfig // Chain configuration options
|
|
bc *BlockChain // Canonical block chain
|
|
engine consensus.Engine // Consensus engine used for block rewards
|
|
}
|
|
|
|
// newStatePrefetcher initialises a new statePrefetcher.
|
|
func newStatePrefetcher(config *params.ChainConfig, bc *BlockChain, engine consensus.Engine) *statePrefetcher {
|
|
return &statePrefetcher{
|
|
config: config,
|
|
bc: bc,
|
|
engine: engine,
|
|
}
|
|
}
|
|
|
|
// Prefetch processes the state changes according to the Ethereum rules by running
|
|
// the transaction messages using the statedb, but any changes are discarded. The
|
|
// only goal is to pre-cache transaction signatures and state trie nodes.
|
|
func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.IntraBlockState, cfg vm.Config, interrupt *uint32, dests vm.Cache) {
|
|
var (
|
|
header = block.Header()
|
|
gaspool = new(GasPool).AddGas(block.GasLimit())
|
|
)
|
|
for i, tx := range block.Transactions() {
|
|
// If block precaching was interrupted, abort
|
|
if interrupt != nil && atomic.LoadUint32(interrupt) == 1 {
|
|
return
|
|
}
|
|
// Block precaching permitted to continue, execute the transaction
|
|
statedb.Prepare(tx.Hash(), block.Hash(), i)
|
|
if err := precacheTransaction(p.config, p.bc, nil, gaspool, statedb, header, tx, cfg, dests); err != nil {
|
|
return // Ugh, something went horribly wrong, bail out
|
|
}
|
|
}
|
|
}
|
|
|
|
// precacheTransaction attempts to apply a transaction to the given state database
|
|
// and uses the input parameters for its environment. The goal is not to execute
|
|
// the transaction successfully, rather to warm up touched data slots.
|
|
func precacheTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gaspool *GasPool, statedb vm.IntraBlockState, header *types.Header, tx *types.Transaction, cfg vm.Config, dests vm.Cache) error {
|
|
// Convert the transaction into an executable message and pre-cache its sender
|
|
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// Create the EVM and execute the transaction
|
|
context := NewEVMContext(msg, header, bc, author)
|
|
vm := vm.NewEVM(context, statedb, config, cfg, dests)
|
|
|
|
_, err = ApplyMessage(vm, msg, gaspool)
|
|
return err
|
|
}
|