From 2a5c3ed91f44007732cb5c87b7c3d8d13f5eba05 Mon Sep 17 00:00:00 2001 From: adu Date: Tue, 16 Aug 2022 16:45:26 +0800 Subject: [PATCH 1/3] fix staking simulation --- go.work.sum | 1 + x/staking/simulation/operations.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/go.work.sum b/go.work.sum index 97292c8f8b16..0ebfcac75ee1 100644 --- a/go.work.sum +++ b/go.work.sum @@ -3,6 +3,7 @@ cosmossdk.io/math v1.0.0-beta.3.0.20220726092710-f848e4300a8a/go.mod h1:3LYasri3 github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/Workiva/go-datastructures v1.0.53 h1:J6Y/52yX10Xc5JjXmGtWoSSxs3mZnGSaq37xZZh7Yig= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20201201074141-dd0ecada1be6/go.mod h1:eSYp2T6f0apnuW8TzhV3f6Aff2SE8Dwio++U4ha4yEM= github.com/btcsuite/btcd v0.0.0-20190315201642-aa6e0f35703c/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 542536fc8e82..8c49e720b3c7 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -413,8 +413,19 @@ 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 with the creationHeight. + // because currently the staking msgServer chooses the first unbondingDelegationEntry with the matching creationHeight. + 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 From bb30dde6a643854dfd1355b5e1b4b4f0aba6458e Mon Sep 17 00:00:00 2001 From: adu-crypto <94821467+adu-crypto@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:33:15 +0800 Subject: [PATCH 2/3] Update x/staking/simulation/operations.go --- x/staking/simulation/operations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 8c49e720b3c7..d7dba53bfd48 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -414,7 +414,7 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee } // this is a temporary fix to make staking simulation pass. - // we should fetch the first unbondingDelegationEntry that matches with the creationHeight. + // we should fetch the first unbondingDelegationEntry that matches the creationHeight. // because currently the staking msgServer chooses the first unbondingDelegationEntry with the matching creationHeight. creationHeight := unbondingDelegation.Entries[r.Intn(len(unbondingDelegation.Entries))].CreationHeight From 3a643569c8110846c7807de15a12b1e83921c2e3 Mon Sep 17 00:00:00 2001 From: adu-crypto <94821467+adu-crypto@users.noreply.github.com> Date: Wed, 17 Aug 2022 09:29:01 +0800 Subject: [PATCH 3/3] Update x/staking/simulation/operations.go Co-authored-by: Aleksandr Bezobchuk --- x/staking/simulation/operations.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index d7dba53bfd48..c4dbd7ecd631 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -413,9 +413,12 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "account does have any unbonding delegation"), nil, nil } - // 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. + // 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