github.com/okex/exchain@v1.8.0/libs/tendermint/state/execution_task.go (about) 1 package state 2 3 import ( 4 "encoding/hex" 5 "fmt" 6 "time" 7 8 "github.com/okex/exchain/libs/system/trace" 9 cfg "github.com/okex/exchain/libs/tendermint/config" 10 "github.com/okex/exchain/libs/tendermint/libs/automation" 11 "github.com/okex/exchain/libs/tendermint/libs/log" 12 "github.com/okex/exchain/libs/tendermint/proxy" 13 "github.com/okex/exchain/libs/tendermint/types" 14 dbm "github.com/okex/exchain/libs/tm-db" 15 ) 16 17 type executionResult struct { 18 res *ABCIResponses 19 duration time.Duration 20 err error 21 } 22 23 type executionTask struct { 24 height int64 25 index int64 26 block *types.Block 27 stopped bool 28 taskResultChan chan *executionTask 29 result *executionResult 30 proxyApp proxy.AppConnConsensus 31 db dbm.DB 32 logger log.Logger 33 blockHash string 34 } 35 36 func newExecutionTask(blockExec *BlockExecutor, block *types.Block, index int64) *executionTask { 37 ret := &executionTask{ 38 height: block.Height, 39 block: block, 40 db: blockExec.db, 41 proxyApp: blockExec.proxyApp, 42 logger: blockExec.logger, 43 taskResultChan: blockExec.prerunCtx.taskResultChan, 44 index: index, 45 } 46 ret.blockHash = hex.EncodeToString(block.Hash()) 47 48 return ret 49 } 50 51 func (e *executionTask) dump(when string) { 52 53 e.logger.Info(when, 54 "stopped", e.stopped, 55 "Height", e.block.Height, 56 "index", e.index, 57 "blockHash", e.blockHash, 58 //"AppHash", e.block.AppHash, 59 ) 60 } 61 62 func (t *executionTask) stop() { 63 if t.stopped { 64 return 65 } 66 67 t.stopped = true 68 } 69 70 func (t *executionTask) run() { 71 t.dump("Start prerun") 72 73 var abciResponses *ABCIResponses 74 var err error 75 76 t0 := time.Now() 77 mode := DeliverTxsExecMode(cfg.DynamicConfig.GetDeliverTxsExecuteMode()) 78 switch mode { 79 case DeliverTxsExecModeSerial: 80 abciResponses, err = execBlockOnProxyApp(t) 81 case DeliverTxsExecModeParallel: 82 abciResponses, err = execBlockOnProxyAppAsync(t.logger, t.proxyApp, t.block, t.db) 83 default: 84 abciResponses, err = execBlockOnProxyApp(t) 85 } 86 duration := time.Now().Sub(t0) 87 88 if !t.stopped { 89 t.result = &executionResult{ 90 abciResponses, duration,err, 91 } 92 trace.GetElapsedInfo().AddInfo(trace.Prerun, fmt.Sprintf("%d", t.index)) 93 } 94 automation.PrerunTimeOut(t.block.Height, int(t.index)-1) 95 t.dump("Prerun completed") 96 t.taskResultChan <- t 97 } 98 99 //======================================================== 100 func (blockExec *BlockExecutor) InitPrerun() { 101 if blockExec.deltaContext.downloadDelta { 102 panic("download delta is not allowed if prerun enabled") 103 } 104 go blockExec.prerunCtx.prerunRoutine() 105 } 106 107 func (blockExec *BlockExecutor) NotifyPrerun(block *types.Block) { 108 if block.Height == 1+types.GetStartBlockHeight() { 109 return 110 } 111 blockExec.prerunCtx.notifyPrerun(blockExec, block) 112 }