From 48a9d68b46a0abdf5eb25700460b1b654656ca64 Mon Sep 17 00:00:00 2001 From: Roshan Date: Mon, 10 Jul 2023 13:31:24 +0800 Subject: [PATCH] update checkStateMtx --- baseapp/abci.go | 8 +++----- baseapp/test_helpers.go | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) 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 }