Skip to content

Commit

Permalink
update checkState
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Jul 10, 2023
1 parent 48a9d68 commit 25350a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 6 additions & 6 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ func (app *BaseApp) Commit() abci.ResponseCommit {
// The write to the DeliverTx state writes all state transitions to the root
// MultiStore (app.cms) so when Commit() is called is persists those values.
// checkState needs to be locked here to prevent a race condition
app.checkStateMtx.Lock()
app.deliverState.ms.Write()
commitID := app.cms.Commit()

Expand All @@ -496,6 +495,7 @@ func (app *BaseApp) Commit() abci.ResponseCommit {
app.logger.Info("commit synced", "commit", fmt.Sprintf("%X", commitID))

// Reset the Check state to the latest committed.
app.checkStateMtx.Lock()
app.setState(runTxModeCheck, header)
app.checkStateMtx.Unlock()

Expand Down Expand Up @@ -617,9 +617,9 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
}()

// when a client did not provide a query height, manually inject the latest
if req.Height == 0 {
req.Height = app.LastBlockHeight()
}
// if req.Height == 0 {
// req.Height = app.LastBlockHeight()
// }

telemetry.IncrCounter(1, "query", "count")
telemetry.IncrCounter(1, "query", req.Path)
Expand Down Expand Up @@ -911,9 +911,9 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool, path ...string)

if height > lastBlockHeight {
return sdk.Context{},
sdkerrors.Wrap(
sdkerrors.Wrapf(
sdkerrors.ErrInvalidHeight,
"cannot query with height in the future; please provide a valid height",
"cannot query with height in the future(%d, latest height %d); please provide a valid height", height, lastBlockHeight,
)
}

Expand Down
11 changes: 9 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,15 @@ func (app *BaseApp) setState(mode runTxMode, header tmproto.Header) {
switch mode {
case runTxModeCheck:
// Minimum gas prices are also set. It is set on InitChain and reset on Commit.
baseState.ctx = baseState.ctx.WithIsCheckTx(true).WithMinGasPrices(app.minGasPrices)
app.checkState = baseState
var msCopy sdk.CacheMultiStore
if rs, ok := app.cms.(*rootmulti.Store); ok {
msCopy = rs.DeepCopyMultiStore()
baseState.ms = msCopy
baseState.ctx = baseState.ctx.WithIsCheckTx(true).WithMinGasPrices(app.minGasPrices).WithMultiStore(msCopy)
app.checkState = baseState
} else {
panic(fmt.Sprintf("set checkState failed: %T is not rootmulti.Store", app.cms))
}
case runTxModeDeliver:
// It is set on InitChain and BeginBlock and set to nil on Commit.
app.deliverState = baseState
Expand Down

0 comments on commit 25350a5

Please sign in to comment.