mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
Make block context sharable in parallel state processor
This commit is contained in:
parent
badb574b25
commit
193aee0063
2 changed files with 14 additions and 5 deletions
|
|
@ -18,6 +18,7 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
|
|
@ -83,7 +84,12 @@ func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash
|
||||||
// Then fill up with [refHash.p, refHash.pp, refHash.ppp, ...]
|
// Then fill up with [refHash.p, refHash.pp, refHash.ppp, ...]
|
||||||
var cache []common.Hash
|
var cache []common.Hash
|
||||||
|
|
||||||
|
cacheMutex := &sync.Mutex{}
|
||||||
|
|
||||||
return func(n uint64) common.Hash {
|
return func(n uint64) common.Hash {
|
||||||
|
cacheMutex.Lock()
|
||||||
|
defer cacheMutex.Unlock()
|
||||||
|
|
||||||
// If there's no hash cache yet, make one
|
// If there's no hash cache yet, make one
|
||||||
if len(cache) == 0 {
|
if len(cache) == 0 {
|
||||||
cache = append(cache, ref.ParentHash)
|
cache = append(cache, ref.ParentHash)
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ type ExecutionTask struct {
|
||||||
// next k elements in dependencies -> transaction indexes on which transaction i is dependent on
|
// next k elements in dependencies -> transaction indexes on which transaction i is dependent on
|
||||||
dependencies []int
|
dependencies []int
|
||||||
coinbase common.Address
|
coinbase common.Address
|
||||||
|
blockContext vm.BlockContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (err error) {
|
func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (err error) {
|
||||||
|
|
@ -96,9 +97,7 @@ func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (er
|
||||||
task.statedb.SetMVHashmap(mvh)
|
task.statedb.SetMVHashmap(mvh)
|
||||||
task.statedb.SetIncarnation(incarnation)
|
task.statedb.SetIncarnation(incarnation)
|
||||||
|
|
||||||
blockContext := NewEVMBlockContext(task.header, task.blockChain, nil)
|
evm := vm.NewEVM(task.blockContext, vm.TxContext{}, task.statedb, task.config, task.evmConfig)
|
||||||
|
|
||||||
evm := vm.NewEVM(blockContext, vm.TxContext{}, task.statedb, task.config, task.evmConfig)
|
|
||||||
|
|
||||||
// Create a new context to be used in the EVM environment.
|
// Create a new context to be used in the EVM environment.
|
||||||
txContext := NewEVMTxContext(task.msg)
|
txContext := NewEVMTxContext(task.msg)
|
||||||
|
|
@ -125,8 +124,8 @@ func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (er
|
||||||
|
|
||||||
reads := task.statedb.MVReadMap()
|
reads := task.statedb.MVReadMap()
|
||||||
|
|
||||||
if _, ok := reads[blockstm.NewSubpathKey(blockContext.Coinbase, state.BalancePath)]; ok {
|
if _, ok := reads[blockstm.NewSubpathKey(task.blockContext.Coinbase, state.BalancePath)]; ok {
|
||||||
log.Info("Coinbase is in MVReadMap", "address", blockContext.Coinbase)
|
log.Info("Coinbase is in MVReadMap", "address", task.blockContext.Coinbase)
|
||||||
|
|
||||||
task.shouldRerunWithoutFeeDelay = true
|
task.shouldRerunWithoutFeeDelay = true
|
||||||
}
|
}
|
||||||
|
|
@ -293,6 +292,8 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
metadata = true
|
metadata = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockContext := NewEVMBlockContext(header, p.bc, nil)
|
||||||
|
|
||||||
// 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() {
|
||||||
msg, err := tx.AsMessage(types.MakeSigner(p.config, header.Number), header.BaseFee)
|
msg, err := tx.AsMessage(types.MakeSigner(p.config, header.Number), header.BaseFee)
|
||||||
|
|
@ -328,6 +329,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
allLogs: &allLogs,
|
allLogs: &allLogs,
|
||||||
dependencies: deps[i],
|
dependencies: deps[i],
|
||||||
coinbase: coinbase,
|
coinbase: coinbase,
|
||||||
|
blockContext: blockContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
|
|
@ -352,6 +354,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
allLogs: &allLogs,
|
allLogs: &allLogs,
|
||||||
dependencies: nil,
|
dependencies: nil,
|
||||||
coinbase: coinbase,
|
coinbase: coinbase,
|
||||||
|
blockContext: blockContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue