-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathevm_process.go
More file actions
78 lines (66 loc) · 1.82 KB
/
evm_process.go
File metadata and controls
78 lines (66 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package parallel
import (
"time"
common2 "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/yu-org/yu/core/tripod"
"github.com/yu-org/yu/common"
"github.com/yu-org/yu/core/types"
"github.com/reddio-com/reddio/config"
"github.com/reddio-com/reddio/evm"
)
const (
txnLabelRedoExecute = "redo"
txnLabelExecuteSuccess = "success"
txnLabelErrExecute = "err"
batchTxnLabelSuccess = "success"
batchTxnLabelRedo = "redo"
)
type ParallelEVM struct {
*tripod.Tripod
cpdb *state.StateDB
Solidity *evm.Solidity `tripod:"solidity"`
statManager *BlockTxnStatManager
objectInc map[common2.Address]int
processor EvmProcessor
}
func NewParallelEVM() *ParallelEVM {
evm := &ParallelEVM{
Tripod: tripod.NewTripod(),
}
return evm
}
func (k *ParallelEVM) setupProcessor() {
if config.GetGlobalConfig().IsParallel {
k.processor = NewParallelEvmExecutor(k)
} else {
k.processor = NewSerialEvmExecutor(k)
}
}
func (k *ParallelEVM) Execute(block *types.Block) error {
k.statManager = &BlockTxnStatManager{TxnCount: len(block.Txns)}
k.cpdb = k.Solidity.StateDBCopy()
k.setupProcessor()
start := time.Now()
defer func() {
k.statManager.ExecuteDuration = time.Since(start)
k.statManager.UpdateMetrics()
}()
k.processor.Prepare(block)
k.processor.Execute(block)
k.Solidity.SetStateDB(k.cpdb)
receipts := k.processor.Receipts(block)
return k.Commit(block, receipts)
}
func (k *ParallelEVM) Commit(block *types.Block, receipts map[common.Hash]*types.Receipt) error {
commitStart := time.Now()
defer func() {
k.statManager.CommitDuration = time.Since(commitStart)
}()
return k.PostExecute(block, receipts)
}
type EvmProcessor interface {
Prepare(block *types.Block)
Execute(block *types.Block)
Receipts(block *types.Block) map[common.Hash]*types.Receipt
}