Skip to content

Commit

Permalink
Re-execute parallel tasks when there is a read in coinbase or burn ad…
Browse files Browse the repository at this point in the history
…dress
  • Loading branch information
cffls authored and pratikspatil024 committed Aug 18, 2022
1 parent 41af9dc commit 680a63b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
41 changes: 30 additions & 11 deletions core/parallel_state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 680a63b

Please sign in to comment.