Skip to content

Commit

Permalink
fix: the occasional staking module `SimulateMsgCancelUnbondingDelegat…
Browse files Browse the repository at this point in the history
…e` failure (backport #12933) (#12962)
  • Loading branch information
mergify[bot] authored Aug 18, 2022
1 parent d2a5018 commit 32c9075
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32c9075

Please sign in to comment.