-
Notifications
You must be signed in to change notification settings - Fork 182
/
execution_task.go
111 lines (95 loc) · 2.78 KB
/
execution_task.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package state
import (
"encoding/hex"
"fmt"
"github.com/okex/exchain/libs/system/trace"
cfg "github.com/okex/exchain/libs/tendermint/config"
"github.com/okex/exchain/libs/tendermint/libs/automation"
"github.com/okex/exchain/libs/tendermint/libs/log"
"github.com/okex/exchain/libs/tendermint/proxy"
"github.com/okex/exchain/libs/tendermint/types"
dbm "github.com/okex/exchain/libs/tm-db"
)
type executionResult struct {
res *ABCIResponses
err error
}
type executionTask struct {
height int64
index int64
block *types.Block
stopped bool
taskResultChan chan *executionTask
result *executionResult
proxyApp proxy.AppConnConsensus
db dbm.DB
logger log.Logger
blockHash string
}
func newExecutionTask(blockExec *BlockExecutor, block *types.Block, index int64) *executionTask {
ret := &executionTask{
height: block.Height,
block: block,
db: blockExec.db,
proxyApp: blockExec.proxyApp,
logger: blockExec.logger,
taskResultChan: blockExec.prerunCtx.taskResultChan,
index: index,
}
ret.blockHash = hex.EncodeToString(block.Hash())
return ret
}
func (e *executionTask) dump(when string) {
e.logger.Info(when,
"stopped", e.stopped,
"Height", e.block.Height,
"index", e.index,
"blockHash", e.blockHash,
//"AppHash", e.block.AppHash,
)
}
func (t *executionTask) stop() {
if t.stopped {
return
}
t.stopped = true
}
func (t *executionTask) run() {
t.dump("Start prerun")
trc := trace.NewTracer("lastRun")
var abciResponses *ABCIResponses
var err error
mode := DeliverTxsExecMode(cfg.DynamicConfig.GetDeliverTxsExecuteMode())
switch mode {
case DeliverTxsExecModeSerial:
abciResponses, err = execBlockOnProxyApp(t)
case DeliverTxsExecModePartConcurrent:
abciResponses, err = execBlockOnProxyAppPartConcurrent(t.logger, t.proxyApp, t.block, t.db)
case DeliverTxsExecModeParallel:
abciResponses, err = execBlockOnProxyAppAsync(t.logger, t.proxyApp, t.block, t.db)
default:
abciResponses, err = execBlockOnProxyApp(t)
}
if !t.stopped {
t.result = &executionResult{
abciResponses, err,
}
trace.GetElapsedInfo().AddInfo(trace.Prerun, fmt.Sprintf("num<%d>, lastRun<%s>", t.index, trc.Format()))
}
automation.PrerunTimeOut(t.block.Height, int(t.index)-1)
t.dump("Prerun completed")
t.taskResultChan <- t
}
//========================================================
func (blockExec *BlockExecutor) InitPrerun() {
if blockExec.deltaContext.downloadDelta {
panic("download delta is not allowed if prerun enabled")
}
go blockExec.prerunCtx.prerunRoutine()
}
func (blockExec *BlockExecutor) NotifyPrerun(block *types.Block) {
if block.Height == 1+types.GetStartBlockHeight() {
return
}
blockExec.prerunCtx.notifyPrerun(blockExec, block)
}