From 65a10d6dea3a95833c0df6d894a889219cd10d66 Mon Sep 17 00:00:00 2001 From: shellvish <104537253+shellvish@users.noreply.github.com> Date: Thu, 10 Aug 2023 14:38:56 -0400 Subject: [PATCH] Add v13 Upgrade Handler (#886) Co-authored-by: strbrian Co-authored-by: strbrian <136667271+strbrian@users.noreply.github.com> Co-authored-by: sampocs --- Makefile | 2 +- app/upgrades.go | 18 ++++++++---- app/upgrades/README.md | 4 +-- app/upgrades/v13/upgrades.go | 43 +++++++++++++++++++++++++++ app/upgrades/v13/upgrades_test.go | 49 +++++++++++++++++++++++++++++++ go.mod | 3 -- go.sum | 16 ++-------- 7 files changed, 110 insertions(+), 25 deletions(-) create mode 100644 app/upgrades/v13/upgrades.go create mode 100644 app/upgrades/v13/upgrades_test.go diff --git a/Makefile b/Makefile index 71dacb1828..1e82948a15 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ submit-upgrade-immediately: UPGRADE_HEIGHT=150 bash $(DOCKERNET_HOME)/upgrades/submit_upgrade.sh submit-upgrade-after-tests: - UPGRADE_HEIGHT=400 bash $(DOCKERNET_HOME)/upgrades/submit_upgrade.sh + UPGRADE_HEIGHT=700 bash $(DOCKERNET_HOME)/upgrades/submit_upgrade.sh start-upgrade-integration-tests: PART=1 bash $(DOCKERNET_HOME)/tests/run_tests_upgrade.sh diff --git a/app/upgrades.go b/app/upgrades.go index a06d87dd5e..6e1a5a417d 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -5,19 +5,17 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" + authz "github.com/cosmos/cosmos-sdk/x/authz" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - authz "github.com/cosmos/cosmos-sdk/x/authz" - consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - v10 "github.com/Stride-Labs/stride/v13/app/upgrades/v10" v11 "github.com/Stride-Labs/stride/v13/app/upgrades/v11" v12 "github.com/Stride-Labs/stride/v13/app/upgrades/v12" + v13 "github.com/Stride-Labs/stride/v13/app/upgrades/v13" v2 "github.com/Stride-Labs/stride/v13/app/upgrades/v2" v3 "github.com/Stride-Labs/stride/v13/app/upgrades/v3" v4 "github.com/Stride-Labs/stride/v13/app/upgrades/v4" @@ -162,6 +160,16 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { ), ) + // v13 upgrade handler + app.UpgradeKeeper.SetUpgradeHandler( + v13.UpgradeName, + v13.CreateUpgradeHandler( + app.mm, + app.configurator, + app.StakeibcKeeper, + ), + ) + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err)) diff --git a/app/upgrades/README.md b/app/upgrades/README.md index 9045834492..ec0d5a36ed 100644 --- a/app/upgrades/README.md +++ b/app/upgrades/README.md @@ -83,7 +83,7 @@ package {upgradeVersion} import ( sdk "github.com/cosmos/cosmos-sdk/types" - {new-consensus-version} "github.com/Stride-Labs/stride/v12/x/records/migrations/{new-consensus-version}" + {new-consensus-version} "github.com/Stride-Labs/stride/v13/x/records/migrations/{new-consensus-version}" ) // TODO: Add migration logic to deserialize with old protos and re-serialize with new ones @@ -98,7 +98,7 @@ func MigrateStore(ctx sdk.Context) error { // app/upgrades/{upgradeVersion}/upgrades.go import ( - {module}migration "github.com/Stride-Labs/stride/v12/x/{module}/migrations/{new-consensus-version}" + {module}migration "github.com/Stride-Labs/stride/v13/x/{module}/migrations/{new-consensus-version}" ) // CreateUpgradeHandler creates an SDK upgrade handler for {upgradeVersion} diff --git a/app/upgrades/v13/upgrades.go b/app/upgrades/v13/upgrades.go new file mode 100644 index 0000000000..84f10305df --- /dev/null +++ b/app/upgrades/v13/upgrades.go @@ -0,0 +1,43 @@ +package v13 + +import ( + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + stakeibckeeper "github.com/Stride-Labs/stride/v13/x/stakeibc/keeper" + stakeibctypes "github.com/Stride-Labs/stride/v13/x/stakeibc/types" +) + +var ( + UpgradeName = "v13" +) + +// CreateUpgradeHandler creates an SDK upgrade handler for v13 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + stakeibcKeeper stakeibckeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Starting upgrade v13...") + + ctx.Logger().Info("Registering stTokens to consumer reward denom whitelist...") + hostZones := stakeibcKeeper.GetAllHostZone(ctx) + allDenoms := []string{} + + // get all stToken denoms + for _, zone := range hostZones { + allDenoms = append(allDenoms, stakeibctypes.StAssetDenomFromHostZoneDenom(zone.HostDenom)) + } + + err := stakeibcKeeper.RegisterStTokenDenomsToWhitelist(ctx, allDenoms) + if err != nil { + return nil, errorsmod.Wrapf(err, "unable to register stTokens to whitelist") + } + + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/app/upgrades/v13/upgrades_test.go b/app/upgrades/v13/upgrades_test.go new file mode 100644 index 0000000000..ba394369a3 --- /dev/null +++ b/app/upgrades/v13/upgrades_test.go @@ -0,0 +1,49 @@ +package v13_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/Stride-Labs/stride/v13/app/apptesting" + stakeibctypes "github.com/Stride-Labs/stride/v13/x/stakeibc/types" +) + +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() { + dummyUpgradeHeight := int64(5) + + // Clear the reward denoms in the consumer keeper + consumerParams := s.App.ConsumerKeeper.GetConsumerParams(s.Ctx) + consumerParams.RewardDenoms = []string{"denomA", "denomB"} + s.App.ConsumerKeeper.SetParams(s.Ctx, consumerParams) + + // Add host zones + hostZones := []stakeibctypes.HostZone{ + {ChainId: "cosmoshub-4", HostDenom: "uatom"}, + {ChainId: "osmosis-1", HostDenom: "uosmo"}, + {ChainId: "juno-1", HostDenom: "ujuno"}, + } + for _, hostZone := range hostZones { + s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone) + } + + // Submit the upgrade which should register the new host denoms + s.ConfirmUpgradeSucceededs("v13", dummyUpgradeHeight) + + // Confirm the new reward denoms were registered + expectedRewardDenoms := []string{"denomA", "denomB", "stuatom", "stuosmo", "stujuno"} + consumerParams = s.App.ConsumerKeeper.GetConsumerParams(s.Ctx) + s.Require().ElementsMatch(expectedRewardDenoms, consumerParams.RewardDenoms) +} diff --git a/go.mod b/go.mod index 15ed4dde9f..bf405852a4 100644 --- a/go.mod +++ b/go.mod @@ -32,9 +32,6 @@ require github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect require ( cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect - github.com/gin-gonic/gin v1.8.1 // indirect - github.com/go-playground/validator/v10 v10.11.1 // indirect - github.com/goccy/go-json v0.9.11 // indirect github.com/google/s2a-go v0.1.4 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/oxyno-zeta/gomock-extra-matcher v1.1.0 // indirect diff --git a/go.sum b/go.sum index de30573a34..660d505e7f 100644 --- a/go.sum +++ b/go.sum @@ -411,9 +411,8 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= -github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -432,13 +431,10 @@ github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KE github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= -github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -447,8 +443,6 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= -github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -693,7 +687,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -702,7 +695,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= @@ -815,7 +807,6 @@ github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 h1:hDSdbBuw3Lefr6 github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -867,7 +858,6 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= @@ -1002,7 +992,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= @@ -1588,7 +1577,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=