From a7ebe87c7d133b1d40de6d6c3297777f233d61fd Mon Sep 17 00:00:00 2001 From: sampocs Date: Sat, 25 Mar 2023 17:56:14 -0500 Subject: [PATCH] added airdrop safety checks (#694) --- app/upgrades/v8/upgrades.go | 22 ++++++++++++++++++++++ app/upgrades/v8/upgrades_test.go | 17 +++++++++++------ x/claim/handler.go | 3 --- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/upgrades/v8/upgrades.go b/app/upgrades/v8/upgrades.go index 843e63ed4..ea7b777a2 100644 --- a/app/upgrades/v8/upgrades.go +++ b/app/upgrades/v8/upgrades.go @@ -12,9 +12,11 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/Stride-Labs/stride/v8/utils" autopilotkeeper "github.com/Stride-Labs/stride/v8/x/autopilot/keeper" autopilottypes "github.com/Stride-Labs/stride/v8/x/autopilot/types" claimkeeper "github.com/Stride-Labs/stride/v8/x/claim/keeper" + "github.com/Stride-Labs/stride/v8/x/claim/types" claimtypes "github.com/Stride-Labs/stride/v8/x/claim/types" ) @@ -46,6 +48,26 @@ func CreateUpgradeHandler( } } + // Delete all unofficial airdrops from the store so they don't conflict with the evmos addition + claimParams, err := claimKeeper.GetParams(ctx) + if err != nil { + return vm, errorsmod.Wrapf(err, "unable to get claim parameters") + } + + updatedAirdropList := []*types.Airdrop{} + for _, existingAirdrop := range claimParams.Airdrops { + if utils.ContainsString(ResetAirdropIdentifiers, existingAirdrop.AirdropIdentifier) { + updatedAirdropList = append(updatedAirdropList, existingAirdrop) + } + } + updatedClaimsParams := claimtypes.Params{ + Airdrops: updatedAirdropList, + } + + if err := claimKeeper.SetParams(ctx, updatedClaimsParams); err != nil { + return vm, errorsmod.Wrapf(err, "unable to remove unofficial airdrops") + } + // Add the evmos airdrop ctx.Logger().Info("Adding evmos airdrop...") duration := uint64(AirdropDuration.Seconds()) diff --git a/app/upgrades/v8/upgrades_test.go b/app/upgrades/v8/upgrades_test.go index 26e87be2d..8ca086885 100644 --- a/app/upgrades/v8/upgrades_test.go +++ b/app/upgrades/v8/upgrades_test.go @@ -17,10 +17,11 @@ import ( ) var ( - ustrd = "ustrd" - dummyUpgradeHeight = int64(5) - osmoAirdropId = "osmosis" - addresses = []string{ + ustrd = "ustrd" + dummyUpgradeHeight = int64(5) + osmoAirdropId = "osmosis" + unofficialAirdropId = "unofficial-airdrop" + addresses = []string{ "stride12a06af3mm5j653446xr4dguacuxfkj293ey2vh", "stride1udf2vyj5wyjckl7nzqn5a2vh8fpmmcffey92y8", "stride1uc8ccxy5s2hw55fn8963ukfdycaamq95jqcfnr", @@ -60,6 +61,10 @@ func (s *UpgradeTestSuite) SetupStoreBeforeUpgrade() { AirdropIdentifier: osmoAirdropId, ClaimedSoFar: sdkmath.NewInt(1000000), }, + { + AirdropIdentifier: unofficialAirdropId, // this should be removed + ClaimedSoFar: sdkmath.NewInt(1000000), + }, }, } err := s.App.ClaimKeeper.SetParams(s.Ctx, params) @@ -97,10 +102,10 @@ func (s *UpgradeTestSuite) SetupStoreBeforeUpgrade() { func (s *UpgradeTestSuite) CheckStoreAfterUpgrade() { afterCtx := s.Ctx.WithBlockHeight(dummyUpgradeHeight) - // Check that the evmos airdrop was added + // Check that the evmos airdrop was added and the unofficial airdrop was removed claimParams, err := s.App.ClaimKeeper.GetParams(s.Ctx) s.Require().NoError(err, "no error expected when getting params") - s.Require().Len(claimParams.Airdrops, 2, "there should be two airdrops (evmos and osmo)") + s.Require().Len(claimParams.Airdrops, 2, "there should be only two airdrops (evmos and osmo)") osmoAirdrop := claimParams.Airdrops[0] evmosAirdrop := claimParams.Airdrops[1] diff --git a/x/claim/handler.go b/x/claim/handler.go index 73cdcf0e8..54a6c3cee 100644 --- a/x/claim/handler.go +++ b/x/claim/handler.go @@ -24,9 +24,6 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgClaimFreeAmount: res, err := msgServer.ClaimFreeAmount(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgCreateAirdrop: - res, err := msgServer.CreateAirdrop(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) case *types.MsgDeleteAirdrop: res, err := msgServer.DeleteAirdrop(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err)