Skip to content

Commit

Permalink
Merge PR: fix prerun bug (#1461)
Browse files Browse the repository at this point in the history
Co-authored-by: KamiD <[email protected]>
  • Loading branch information
xiangjianmeng and KamiD authored Jan 19, 2022
1 parent a2f8671 commit 01f9180
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
22 changes: 13 additions & 9 deletions libs/cosmos-sdk/baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/okex/exchain/libs/iavl"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"github.com/okex/exchain/libs/tendermint/trace"
tmtypes "github.com/okex/exchain/libs/tendermint/types"

"github.com/okex/exchain/libs/cosmos-sdk/codec"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
Expand Down Expand Up @@ -86,14 +87,6 @@ func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOp
case "ResetCheckState":
// reset check state
app.checkState.ms = app.cms.CacheMultiStore()
case "ResetDeliverState":
// reset deliver state

// Reset the DeliverTx state. If this is the first block, it should
// already be initialized in InitChain. Otherwise app.deliverState will be
// nil, since it is reset on Commit.
// init chain will set deliverstate without blockHeight
app.deliverState = nil
default:
// do nothing
}
Expand Down Expand Up @@ -131,9 +124,19 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
// Initialize the DeliverTx state. If this is the first block, it should
// already be initialized in InitChain. Otherwise app.deliverState will be
// nil, since it is reset on Commit.
if app.deliverState == nil {
if req.Header.Height > 1+tmtypes.GetStartBlockHeight() {
if app.deliverState != nil {
app.logger.Info(
"deliverState was not reset by BaseApp.Commit due to the previous prerun task being stopped",
"height", req.Header.Height)
}
app.setDeliverState(req.Header)
} else {
// for TestDeliverTx only
if app.deliverState == nil {
initHeader := abci.Header{ChainID: req.Header.ChainID}
app.setDeliverState(initHeader)
}
// In the first block, app.deliverState.ctx will already be initialized
// by InitChain. Context is now updated with Header information.
app.deliverState.ctx = app.deliverState.ctx.
Expand Down Expand Up @@ -256,6 +259,7 @@ func (app *BaseApp) Commit(req abci.RequestCommit) abci.ResponseCommit {
// Commit. Use the header from this latest block.
app.setCheckState(header)

app.logger.Info("deliverState reset by BaseApp.Commit", "height", header.Height)
// empty/reset the deliver state
app.deliverState = nil

Expand Down
48 changes: 20 additions & 28 deletions libs/tendermint/state/execution_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package state

import (
"fmt"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"github.com/okex/exchain/libs/tendermint/libs/automation"
"github.com/okex/exchain/libs/tendermint/trace"

Expand All @@ -12,34 +11,33 @@ import (
dbm "github.com/tendermint/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
height int64
index int64
block *types.Block
stopped bool
taskResultChan chan *executionTask
result *executionResult
proxyApp proxy.AppConnConsensus
db dbm.DB
logger log.Logger
}

func newExecutionTask(blockExec *BlockExecutor, block *types.Block, index int64) *executionTask {

return &executionTask{
height: block.Height,
block: block,
db: blockExec.db,
proxyApp: blockExec.proxyApp,
logger: blockExec.logger,
taskResultChan: blockExec.prerunCtx.taskResultChan,
index: index,
height: block.Height,
block: block,
db: blockExec.db,
proxyApp: blockExec.proxyApp,
logger: blockExec.logger,
taskResultChan: blockExec.prerunCtx.taskResultChan,
index: index,
}
}

Expand All @@ -58,22 +56,13 @@ func (t *executionTask) stop() {
return
}

//reset deliverState
if t.height != 1 {
t.proxyApp.SetOptionSync(abci.RequestSetOption{Key: "ResetDeliverState",})
}
t.stopped = true
}


func (t *executionTask) run() {
t.dump("Start prerun")
trc := trace.NewTracer(fmt.Sprintf("num<%d>, lastRun", t.index))

if t.height != 1 {
t.proxyApp.SetOptionSync(abci.RequestSetOption{Key: "ResetDeliverState",})
}

abciResponses, err := execBlockOnProxyApp(t)

if !t.stopped {
Expand All @@ -96,5 +85,8 @@ func (blockExec *BlockExecutor) InitPrerun() {
}

func (blockExec *BlockExecutor) NotifyPrerun(block *types.Block) {
if block.Height == 1+types.GetStartBlockHeight() {
return
}
blockExec.prerunCtx.notifyPrerun(blockExec, block)
}
}

0 comments on commit 01f9180

Please sign in to comment.