Skip to content

Commit

Permalink
update checkStateMtx
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Jul 10, 2023
1 parent 250495a commit 48a9d68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,12 @@ func (app *BaseApp) Commit() abci.ResponseCommit {
// Write the DeliverTx state into branched storage and commit the MultiStore.
// 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()

app.queryStateMtx.Lock()
commitID := app.cms.Commit()
app.setQueryState(header)
app.queryStateMtx.Unlock()

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

// Reset the Check state to the latest committed.
//
// NOTE: This is safe because Tendermint holds a lock on the mempool for
// Commit. Use the header from this latest block.
app.checkStateMtx.Lock()
app.setState(runTxModeCheck, header)
app.checkStateMtx.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions baseapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *

// Simulate executes a tx in simulate mode to get result and gas info.
func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) {
app.checkStateMtx.Lock()
defer app.checkStateMtx.Unlock()
app.checkStateMtx.RLock()
defer app.checkStateMtx.RUnlock()
gasInfo, result, _, _, err := app.runTx(runTxModeSimulate, txBytes)
return gasInfo, result, err
}
Expand Down

0 comments on commit 48a9d68

Please sign in to comment.