Skip to content

Commit

Permalink
Add migration handler for disabling seqno (#394)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
Add migration handler to add new disable seqno parameter to chain. Note
that i verified that we already use default values so we can just set
the params to default instead of maintaining authParamsV1 and V2
## Testing performed to validate your change
- unit tests
- upgraded local chain, ensure that bank sends work
  • Loading branch information
philipsu522 authored Jan 11, 2024
1 parent 66364a5 commit 66854d0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions x/auth/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {

return iterErr
}

func (m Migrator) Migrate2to3(ctx sdk.Context) error {
defaultParams := types.DefaultParams()
m.keeper.SetParams(ctx, defaultParams)
return nil
}
28 changes: 28 additions & 0 deletions x/auth/keeper/v2_to_v3_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package keeper_test

import (
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"
"testing"
)

func TestMigrate2to3(t *testing.T) {
app, ctx := createTestApp(true)

prevParams := types.Params{
MaxMemoCharacters: types.DefaultMaxMemoCharacters,
TxSigLimit: types.DefaultTxSigLimit,
TxSizeCostPerByte: types.DefaultTxSizeCostPerByte,
SigVerifyCostED25519: types.DefaultSigVerifyCostED25519,
SigVerifyCostSecp256k1: types.DefaultSigVerifyCostSecp256k1,
}

app.AccountKeeper.SetParams(ctx, prevParams)
// migrate to default params
m := keeper.NewMigrator(app.AccountKeeper, app.GRPCQueryRouter())
err := m.Migrate2to3(ctx)
require.NoError(t, err)
params := app.AccountKeeper.GetParams(ctx)
require.Equal(t, params.DisableSeqnoCheck, false)
}
6 changes: 5 additions & 1 deletion x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err != nil {
panic(err)
}
err = cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3)
if err != nil {
panic(err)
}
}

// InitGenesis performs genesis initialization for the auth module. It returns
Expand All @@ -153,7 +157,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

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

// AppModuleSimulation functions

Expand Down

0 comments on commit 66854d0

Please sign in to comment.