diff --git a/baseapp/abci.go b/baseapp/abci.go index f662a25dff..70537a8f0a 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -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() @@ -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() diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 0c8c470cdd..47f5d6848c 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -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 }