From 32c9075f013fe009b28b8b1d403e8dd457d844b8 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:34:32 -0400 Subject: [PATCH] fix: the occasional staking module `SimulateMsgCancelUnbondingDelegate` failure (backport #12933) (#12962) --- x/staking/simulation/operations.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index c28b489d6a51..cf4e56d37178 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -410,8 +410,22 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "account does have any unbonding delegation"), nil, nil } - // get random unbonding delegation entry at block height - unbondingDelegationEntry := unbondingDelegation.Entries[r.Intn(len(unbondingDelegation.Entries))] + // This is a temporary fix to make staking simulation pass. We should fetch + // the first unbondingDelegationEntry that matches the creationHeight, because + // currently the staking msgServer chooses the first unbondingDelegationEntry + // with the matching creationHeight. + // + // ref: https://github.com/cosmos/cosmos-sdk/issues/12932 + creationHeight := unbondingDelegation.Entries[r.Intn(len(unbondingDelegation.Entries))].CreationHeight + + var unbondingDelegationEntry types.UnbondingDelegationEntry + + for _, entry := range unbondingDelegation.Entries { + if entry.CreationHeight == creationHeight { + unbondingDelegationEntry = entry + break + } + } if unbondingDelegationEntry.CompletionTime.Before(ctx.BlockTime()) { return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "unbonding delegation is already processed"), nil, nil