Skip to content

Commit

Permalink
Merge pull request #541 from PeggyJV/collin/v3-upgrade
Browse files Browse the repository at this point in the history
Consensus version 3 upgrade/migration
  • Loading branch information
EricBolten authored Aug 18, 2023
2 parents 76006da + 9b28b3e commit 143c0cb
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 4 deletions.
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"
"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

* 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.ParamStoreEthereumEventVoteWindow) {
subspace.Set(ctx, types.ParamStoreEthereumEventVoteWindow, types.DefaultParams().EthereumEventVoteWindow)
}

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))
}
6 changes: 5 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,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.
Expand Down
6 changes: 3 additions & 3 deletions module/x/gravity/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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),
}
}
Expand Down

0 comments on commit 143c0cb

Please sign in to comment.