-
Notifications
You must be signed in to change notification settings - Fork 202
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
v8 Upgrade Handler #683
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2f5a943
added upgrade handler for v8
sampocs e4fa9fe
Merge branch 'main' into v8-upgrade-handler
sampocs 10dea80
sample evmos data
shellvish 8a869d7
update to evmos addrs
shellvish 8b0b94f
fixed unit test with dummy data
sampocs a1f9362
Merge branch 'v8-upgrade-handler' of github.com:Stride-Labs/stride in…
sampocs bb88add
added more test coverage for evmos airdrop addition
sampocs 63afd19
bumped down default upgrade height
sampocs 14bb5be
update allocations with evmos
shellvish 55a6a13
add distributor address
shellvish a385d20
set autopilot params in upgrade handler
sampocs 1984015
addressed pr comments
sampocs 6f9b329
Merge branch 'main' into v8-upgrade-handler
sampocs 2ff514c
fixed import path
sampocs d51298e
lint
sampocs bd55330
fixed unit test
sampocs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Upgrade v8 Changelog | ||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?