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

Consensus version 3 upgrade/migration #541

Merged
merged 12 commits into from
Aug 18, 2023
9 changes: 9 additions & 0 deletions module/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
EricBolten marked this conversation as resolved.
Show resolved Hide resolved
"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"
Expand Down Expand Up @@ -840,4 +841,12 @@ func (app *Gravity) setupUpgradeHandlers() {
app.bankKeeper,
),
)

app.upgradeKeeper.SetUpgradeHandler(
v3.UpgradeName,
v3.CreateUpgradeHandler(
app.mm,
app.configurator,
),
)
}
21 changes: 21 additions & 0 deletions module/app/upgrades/v3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# v3 upgrade

This upgrade moves the gravity module from consensus version 2 to 3.

## Summary of changes
EricBolten marked this conversation as resolved.
Show resolved Hide resolved

* 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

4 changes: 4 additions & 0 deletions module/app/upgrades/v3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package v3

// UpgradeName defines the on-chain upgrade name for the Gravity v3 upgrade
const UpgradeName = "v3"
18 changes: 18 additions & 0 deletions module/app/upgrades/v3/upgrades.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions module/app/upgrades/v3/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package v3
6 changes: 6 additions & 0 deletions module/x/gravity/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
19 changes: 19 additions & 0 deletions module/x/gravity/migrations/v2/store.go
Original file line number Diff line number Diff line change
@@ -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.ParamStoreEventVoteWindow) {
subspace.Set(ctx, types.ParamStoreEventVoteWindow, types.DefaultParams().EthereumEventVoteWindow)
EricBolten marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
}
37 changes: 37 additions & 0 deletions module/x/gravity/migrations/v2/store_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
7 changes: 6 additions & 1 deletion module/x/gravity/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (AppModule) Name() string {

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 {
return 2
return 3
}

// RegisterInvariants implements app module
Expand Down Expand Up @@ -137,6 +137,11 @@ 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))
}

// The 2-to-3 migration is a no-op because there are no required store migration steps
EricBolten marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
Loading