From ab3ebebccac6d7c0534eb4286fca5949e9f95d66 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 27 Jul 2022 19:35:23 +0000 Subject: [PATCH] Re-execute parallel tasks when there is a read in coinbase or burn address --- core/parallel_state_processor.go | 41 +++++++++++++++++++++++--------- core/state/statedb.go | 4 ++++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index dd0e9dc0a5..5fa7a4d56e 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -55,17 +55,18 @@ type ExecutionTask struct { msg types.Message config *params.ChainConfig - gasLimit uint64 - blockNumber *big.Int - blockHash common.Hash - blockContext vm.BlockContext - tx *types.Transaction - index int - statedb *state.StateDB // State database that stores the modified values after tx execution. - cleanStateDB *state.StateDB // A clean copy of the initial statedb. It should not be modified. - evmConfig vm.Config - result *ExecutionResult - shouldDelayFeeCal *bool + gasLimit uint64 + blockNumber *big.Int + blockHash common.Hash + blockContext vm.BlockContext + tx *types.Transaction + index int + statedb *state.StateDB // State database that stores the modified values after tx execution. + cleanStateDB *state.StateDB // A clean copy of the initial statedb. It should not be modified. + evmConfig vm.Config + result *ExecutionResult + shouldDelayFeeCal *bool + shouldRerunWithoutFeeDelay bool } func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (err error) { @@ -94,6 +95,14 @@ func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (er // Apply the transaction to the current state (included in the env). if *task.shouldDelayFeeCal { task.result, err = ApplyMessageNoFeeBurnOrTip(evm, task.msg, new(GasPool).AddGas(task.gasLimit)) + + if _, ok := task.statedb.MVReadMap()[string(task.blockContext.Coinbase.Bytes())]; ok { + task.shouldRerunWithoutFeeDelay = true + } + + if _, ok := task.statedb.MVReadMap()[string(task.result.BurntContractAddress.Bytes())]; ok { + task.shouldRerunWithoutFeeDelay = true + } } else { task.result, err = ApplyMessage(evm, task.msg, new(GasPool).AddGas(task.gasLimit)) } @@ -180,6 +189,16 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat _, err := blockstm.ExecuteParallel(tasks) + for _, task := range tasks { + task := task.(*ExecutionTask) + if task.shouldRerunWithoutFeeDelay { + shouldDelayFeeCal = false + _, err = blockstm.ExecuteParallel(tasks) + + break + } + } + if err != nil { log.Error("blockstm error executing block", "err", err) return nil, nil, 0, err diff --git a/core/state/statedb.go b/core/state/statedb.go index 1b7af5dda3..bfc6821d2a 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -201,6 +201,10 @@ func (s *StateDB) MVFullWriteList() []blockstm.WriteDescriptor { return writes } +func (s *StateDB) MVReadMap() map[string]blockstm.ReadDescriptor { + return s.readMap +} + func (s *StateDB) MVReadList() []blockstm.ReadDescriptor { reads := make([]blockstm.ReadDescriptor, 0, len(s.readMap))