From dc5c16b0bed61cad3d3bba0c3bd90ea95faed38b Mon Sep 17 00:00:00 2001 From: Alexander Peters Date: Fri, 12 Jul 2024 17:17:23 +0200 Subject: [PATCH] fix (sims): state written in sims loop (#20936) --- baseapp/test_helpers.go | 6 ++++++ x/simulation/simulate.go | 1 + 2 files changed, 7 insertions(+) diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 288e611fb876..32991aeb1211 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -40,6 +40,12 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, return gasInfo, result, err } +// SimWriteState is an entrypoint for simulations only. They are not executed during the normal ABCI finalize +// block step but later. Therefor an extra call to the root multi-store (app.cms) is required to write the changes. +func (app *BaseApp) SimWriteState() { + app.finalizeBlockState.ms.Write() +} + // NewContextLegacy returns a new sdk.Context with the provided header func (app *BaseApp) NewContextLegacy(isCheckTx bool, header cmtproto.Header) sdk.Context { if isCheckTx { diff --git a/x/simulation/simulate.go b/x/simulation/simulate.go index 771382406cb5..9335f032473c 100644 --- a/x/simulation/simulate.go +++ b/x/simulation/simulate.go @@ -246,6 +246,7 @@ func SimulateFromSeedX( proposerAddress = validators.randomProposer(r) if config.Commit { + app.SimWriteState() if _, err := app.Commit(); err != nil { return params, fmt.Errorf("commit failed at height %d: %w", blockHeight, err) }