Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v8 Upgrade Handler #683

Merged
merged 16 commits into from
Mar 25, 2023
Merged
12 changes: 12 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
v5 "github.com/Stride-Labs/stride/v7/app/upgrades/v5"
v6 "github.com/Stride-Labs/stride/v7/app/upgrades/v6"
v7 "github.com/Stride-Labs/stride/v7/app/upgrades/v7"
v8 "github.com/Stride-Labs/stride/v7/app/upgrades/v8"
autopilottypes "github.com/Stride-Labs/stride/v7/x/autopilot/types"
claimtypes "github.com/Stride-Labs/stride/v7/x/claim/types"
icacallbacktypes "github.com/Stride-Labs/stride/v7/x/icacallbacks/types"
Expand Down Expand Up @@ -84,6 +85,17 @@ func (app *StrideApp) setupUpgradeHandlers() {
),
)

// v8 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v8.UpgradeName,
v8.CreateUpgradeHandler(
app.mm,
app.configurator,
app.appCodec,
app.ClaimKeeper,
),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err))
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Upgrade v8 Changelog
TODO
6 changes: 6 additions & 0 deletions app/upgrades/v8/allocations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v8

var allocations = `identifier,address,weight
evmos,evmos12wmlcr0hmaxgvmwzn86sejkqcpvxp28rdywza2,32828
evmos,evmos1ctmjqtapj7kj5khywf7pv9rc9e0ne467d7uxzz,31630'
`
59 changes: 59 additions & 0 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package v8

import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

claimkeeper "github.com/Stride-Labs/stride/v7/x/claim/keeper"
claimtypes "github.com/Stride-Labs/stride/v7/x/claim/types"
)

var (
UpgradeName = "v8"
EvmosAirdropDistributor = "TODO"
EvmosAirdropIdentifier = "evmos"
AirdropDuration = time.Hour * 24 * 30 * 12 * 3 // 3 years
ResetAirdropIdentifiers = []string{"stride", "gaia", "osmosis", "juno", "stars"}
)

// CreateUpgradeHandler creates an SDK upgrade handler for v8
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
cdc codec.Codec,
claimKeeper claimkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v8...")

// Reset Claims
ctx.Logger().Info("Resetting airdrop claims...")
for _, claimType := range ResetAirdropIdentifiers {
if err := claimKeeper.ResetClaimStatus(ctx, claimType); err != nil {
return vm, errorsmod.Wrapf(err, fmt.Sprintf("unable to reset %s claim status", claimType))
}
}

// Add the evmos airdrop
ctx.Logger().Info("Adding evmos airdrop...")
blockTime := uint64(ctx.BlockTime().Unix())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should pick a blocktime in the future I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call! should we shoot for next monday?

duration := uint64(AirdropDuration.Seconds())
if err := claimKeeper.CreateAirdropAndEpoch(ctx, EvmosAirdropDistributor, claimtypes.DefaultClaimDenom, blockTime, duration, EvmosAirdropIdentifier); err != nil {
return vm, err
}

ctx.Logger().Info("Loading airdrop allocations...")
claimKeeper.LoadAllocationData(ctx, allocations)

ctx.Logger().Info("Running module mogrations...")
return mm.RunMigrations(ctx, configurator, vm)
}
}
117 changes: 117 additions & 0 deletions app/upgrades/v8/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package v8_test

import (
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"

sdkmath "cosmossdk.io/math"
"github.com/stretchr/testify/suite"

"github.com/Stride-Labs/stride/v7/app/apptesting"
v8 "github.com/Stride-Labs/stride/v7/app/upgrades/v8"
"github.com/Stride-Labs/stride/v7/x/claim/types"
claimtypes "github.com/Stride-Labs/stride/v7/x/claim/types"
)

var (
dummyUpgradeHeight = int64(5)
osmoAirdropId = "osmosis"
addresses = []string{
"stride12a06af3mm5j653446xr4dguacuxfkj293ey2vh",
"stride1udf2vyj5wyjckl7nzqn5a2vh8fpmmcffey92y8",
"stride1uc8ccxy5s2hw55fn8963ukfdycaamq95jqcfnr",
}
weights = []sdk.Dec{
sdk.NewDec(1000),
sdk.NewDec(2000),
sdk.NewDec(3000),
}
)

type UpgradeTestSuite struct {
apptesting.AppTestHelper
}

func (s *UpgradeTestSuite) SetupTest() {
s.Setup()
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

s.SetupStoreBeforeUpgrade()
s.ConfirmUpgradeSucceededs("v8", dummyUpgradeHeight)
s.CheckStoreAfterUpgrade()
}

func (s *UpgradeTestSuite) SetupStoreBeforeUpgrade() {
// Add a test aidrop to the store
params := claimtypes.Params{
Airdrops: []*claimtypes.Airdrop{
{
AirdropIdentifier: osmoAirdropId,
ClaimedSoFar: sdkmath.NewInt(1000000),
},
},
}
s.App.ClaimKeeper.SetParams(s.Ctx, params)

// Add claim records for the airdrop
claimRecords := []claimtypes.ClaimRecord{
{
AirdropIdentifier: osmoAirdropId,
Address: addresses[0],
Weight: weights[0],
ActionCompleted: []bool{true, true, false},
},
{
AirdropIdentifier: osmoAirdropId,
Address: addresses[1],
Weight: weights[1],
ActionCompleted: []bool{true, true, true},
},
{
AirdropIdentifier: osmoAirdropId,
Address: addresses[2],
Weight: weights[2],
ActionCompleted: []bool{false, false, false},
},
}
err := s.App.ClaimKeeper.SetClaimRecords(s.Ctx, claimRecords)
s.Require().NoError(err, "no error expected when setting claim record")

// Set vesting to 0s
types.DefaultVestingInitialPeriod, err = time.ParseDuration("0s")
s.Require().NoError(err, "no error expected when setting vesting initial period")
}

func (s *UpgradeTestSuite) CheckStoreAfterUpgrade() {
afterCtx := s.Ctx.WithBlockHeight(dummyUpgradeHeight)

// Check that the evmos airdrop was added
evmosClaimRecords := s.App.ClaimKeeper.GetClaimRecords(afterCtx, v8.EvmosAirdropIdentifier)
s.Require().Positive(len(evmosClaimRecords))

// Check that the osmo airdrop params were reset
claimParams, err := s.App.ClaimKeeper.GetParams(s.Ctx)
s.Require().NoError(err, "no error expected when getting params")
s.Require().Equal(osmoAirdropId, claimParams.Airdrops[0].AirdropIdentifier, "airdrop identifier")
s.Require().Zero(claimParams.Airdrops[0].ClaimedSoFar.Int64(), "claimed so far")

// Check that the claim actions were reset
osmoClaimRecords := s.App.ClaimKeeper.GetClaimRecords(s.Ctx, osmoAirdropId)
s.Require().Equal(len(osmoClaimRecords), 3, "claim records length")

fullyResetAction := []bool{false, false, false}
for i, claimRecord := range osmoClaimRecords {
s.Require().Equal(fullyResetAction, claimRecord.ActionCompleted, "record %d reset", i)
s.Require().Equal(addresses[i], claimRecord.Address, "record %d address", i)
s.Require().Equal(weights[i], claimRecord.Weight, "record %d weight", i)
}
}