diff --git a/module/app/app.go b/module/app/app.go index 2c5a6f3b7..bbca29d31 100644 --- a/module/app/app.go +++ b/module/app/app.go @@ -82,6 +82,7 @@ import ( "github.com/gorilla/mux" gravityparams "github.com/peggyjv/gravity-bridge/module/v3/app/params" v2 "github.com/peggyjv/gravity-bridge/module/v3/app/upgrades/v2" + v3 "github.com/peggyjv/gravity-bridge/module/v3/app/upgrades/v3" "github.com/peggyjv/gravity-bridge/module/v3/x/gravity" gravityclient "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/client" "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/keeper" @@ -840,4 +841,12 @@ func (app *Gravity) setupUpgradeHandlers() { app.bankKeeper, ), ) + + app.upgradeKeeper.SetUpgradeHandler( + v3.UpgradeName, + v3.CreateUpgradeHandler( + app.mm, + app.configurator, + ), + ) } diff --git a/module/app/upgrades/v3/README.md b/module/app/upgrades/v3/README.md new file mode 100644 index 000000000..f8075cb59 --- /dev/null +++ b/module/app/upgrades/v3/README.md @@ -0,0 +1,21 @@ +# v3 upgrade + +This upgrade moves the gravity module from consensus version 2 to 3. + +## Summary of changes + +* Bumps cosmos-sdk to v0.45.10 and ibc-go to v3.4.0 +* Bumps minor dependency versions +* Fix signer set signature sorting inconsistency between orchestrator and chain when powers are equal +* Add CompletedOutgoingTx store for marking transactions as executed +* Refactor slashing logic and include CompletedOutgoingTx in unslashed tx getter +* Add tx confirmation pruning +* Add event vote record pruning +* Fix bug that iterated the entire key store when SetDelegateKeys was called +* Refactor address lookups used in SetDelegateKeys to not require scanning entire list of validators +* Remove MsgRequestBatchTx and handlers +* Add missing Amino registrations +* Fix minor CLI bugs +* Improve and correct terminology in function names and comments +* Update queries + diff --git a/module/app/upgrades/v3/constants.go b/module/app/upgrades/v3/constants.go new file mode 100644 index 000000000..8cffd9af2 --- /dev/null +++ b/module/app/upgrades/v3/constants.go @@ -0,0 +1,4 @@ +package v3 + +// UpgradeName defines the on-chain upgrade name for the Gravity v3 upgrade +const UpgradeName = "v3" diff --git a/module/app/upgrades/v3/upgrades.go b/module/app/upgrades/v3/upgrades.go new file mode 100644 index 000000000..1f3d508b1 --- /dev/null +++ b/module/app/upgrades/v3/upgrades.go @@ -0,0 +1,18 @@ +package v3 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("v3 upgrade: entering handler") + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} diff --git a/module/app/upgrades/v3/upgrades_test.go b/module/app/upgrades/v3/upgrades_test.go new file mode 100644 index 000000000..eac3ae96a --- /dev/null +++ b/module/app/upgrades/v3/upgrades_test.go @@ -0,0 +1 @@ +package v3 diff --git a/module/x/gravity/keeper/migrations.go b/module/x/gravity/keeper/migrations.go index 38d50b0ca..c5a52cc70 100644 --- a/module/x/gravity/keeper/migrations.go +++ b/module/x/gravity/keeper/migrations.go @@ -3,6 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" v1 "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/migrations/v1" + v2 "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/migrations/v2" ) // Migrator is a struct for handling in-place store migrations. @@ -19,3 +20,8 @@ func NewMigrator(keeper Keeper) Migrator { func (m Migrator) Migrate1to2(ctx sdk.Context) error { return v1.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) } + +// Migrate2to3 migrates from consensus version 2 to 3. +func (m Migrator) Migrate2to3(ctx sdk.Context) error { + return v2.MigrateParamStore(ctx, m.keeper.paramSpace) +} diff --git a/module/x/gravity/migrations/v2/store.go b/module/x/gravity/migrations/v2/store.go new file mode 100644 index 000000000..7097c9824 --- /dev/null +++ b/module/x/gravity/migrations/v2/store.go @@ -0,0 +1,19 @@ +package v2 + +import ( + sdktypes "github.com/cosmos/cosmos-sdk/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/types" +) + +func MigrateParamStore(ctx sdktypes.Context, subspace paramstypes.Subspace) error { + // Don't want to overwrite values if they were set in an upgrade handler + if !subspace.Has(ctx, types.ParamStoreConfirmedOutgoingTxWindow) { + subspace.Set(ctx, types.ParamStoreConfirmedOutgoingTxWindow, types.DefaultParams().ConfirmedOutgoingTxWindow) + } + if !subspace.Has(ctx, types.ParamStoreEthereumEventVoteWindow) { + subspace.Set(ctx, types.ParamStoreEthereumEventVoteWindow, types.DefaultParams().EthereumEventVoteWindow) + } + + return nil +} diff --git a/module/x/gravity/migrations/v2/store_test.go b/module/x/gravity/migrations/v2/store_test.go new file mode 100644 index 000000000..76053c07b --- /dev/null +++ b/module/x/gravity/migrations/v2/store_test.go @@ -0,0 +1,37 @@ +package v2_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + v2 "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/migrations/v2" + "github.com/peggyjv/gravity-bridge/module/v3/x/gravity/types" + "github.com/stretchr/testify/require" +) + +const ( + ModuleName = "gravity" +) + +func TestStoreMigration(t *testing.T) { + gravityKey := storetypes.NewKVStoreKey(ModuleName) + tGravityKey := storetypes.NewTransientStoreKey("transient_test") + ctx := testutil.DefaultContext(gravityKey, tGravityKey) + aminoCodec := codec.NewLegacyAmino() + paramstore := paramtypes.NewSubspace(nil, aminoCodec, gravityKey, tGravityKey, ModuleName) + + // Check no params + require.False(t, paramstore.Has(ctx, types.ParamStoreConfirmedOutgoingTxWindow)) + require.False(t, paramstore.Has(ctx, types.ParamStoreEventVoteWindow)) + + // Run migrations. + err := v2.MigrateParamStore(ctx, paramstore) + require.NoError(t, err) + + // Make sure the new params are set. + require.True(t, paramstore.Has(ctx, types.ParamStoreConfirmedOutgoingTxWindow)) + require.True(t, paramstore.Has(ctx, types.ParamStoreEventVoteWindow)) +} diff --git a/module/x/gravity/module.go b/module/x/gravity/module.go index 9c5736e07..96f549f06 100644 --- a/module/x/gravity/module.go +++ b/module/x/gravity/module.go @@ -104,7 +104,7 @@ func (AppModule) Name() string { // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { - return 2 + return 3 } // RegisterInvariants implements app module @@ -137,6 +137,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { panic(fmt.Sprintf("failed to migrate x/gravity from version 1 to 2: %v", err)) } + + if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil { + panic(fmt.Sprintf("failed to migrate x/gravity from version 2 to 3: %v", err)) + } } // InitGenesis initializes the genesis state for this module and implements app module. diff --git a/module/x/gravity/types/genesis.go b/module/x/gravity/types/genesis.go index 162ae2310..f8de6d063 100644 --- a/module/x/gravity/types/genesis.go +++ b/module/x/gravity/types/genesis.go @@ -65,8 +65,8 @@ var ( // ParamStoreUnbondSlashingSignerSetTxsWindow stores unbond slashing valset window ParamStoreUnbondSlashingSignerSetTxsWindow = []byte("UnbondSlashingSignerSetTxsWindow") - // ParamStoreEventVoteWindow stores the event vote window - ParamStoreEventVoteWindow = []byte("EventVoteWindow") + // ParamStoreEthereumEventVoteWindow stores the event vote window + ParamStoreEthereumEventVoteWindow = []byte("EthereumEventVoteWindow") // ParamStoreUnbondSlashingSignerSetTxsWindow stores unbond slashing valset window ParamStoreConfirmedOutgoingTxWindow = []byte("ConfirmedOutgoingTxWindow") @@ -228,7 +228,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(ParamsStoreSlashFractionEthereumSignature, &p.SlashFractionEthereumSignature, validateSlashFractionEthereumSignature), paramtypes.NewParamSetPair(ParamsStoreSlashFractionConflictingEthereumSignature, &p.SlashFractionConflictingEthereumSignature, validateSlashFractionConflictingEthereumSignature), paramtypes.NewParamSetPair(ParamStoreUnbondSlashingSignerSetTxsWindow, &p.UnbondSlashingSignerSetTxsWindow, validateUnbondSlashingSignerSetTxsWindow), - paramtypes.NewParamSetPair(ParamStoreEventVoteWindow, &p.EthereumEventVoteWindow, validateEthereumEventVoteWindow), + paramtypes.NewParamSetPair(ParamStoreEthereumEventVoteWindow, &p.EthereumEventVoteWindow, validateEthereumEventVoteWindow), paramtypes.NewParamSetPair(ParamStoreConfirmedOutgoingTxWindow, &p.ConfirmedOutgoingTxWindow, validateConfirmedOutgoingTxWindow), } }