From 6f5d86281dac11901dad4557d912c29992387d01 Mon Sep 17 00:00:00 2001 From: Philip Su Date: Thu, 11 Jan 2024 10:38:32 -0800 Subject: [PATCH 1/2] Add migration handler for disabling seqno --- x/auth/keeper/migrations.go | 6 ++++++ x/auth/keeper/v2_to_v3_test.go | 28 ++++++++++++++++++++++++++++ x/auth/module.go | 6 +++++- x/params/types/subspace.go | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 x/auth/keeper/v2_to_v3_test.go diff --git a/x/auth/keeper/migrations.go b/x/auth/keeper/migrations.go index d3ad7a2f8..4e16d9288 100644 --- a/x/auth/keeper/migrations.go +++ b/x/auth/keeper/migrations.go @@ -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 +} diff --git a/x/auth/keeper/v2_to_v3_test.go b/x/auth/keeper/v2_to_v3_test.go new file mode 100644 index 000000000..92b3e631b --- /dev/null +++ b/x/auth/keeper/v2_to_v3_test.go @@ -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) +} diff --git a/x/auth/module.go b/x/auth/module.go index ef13f74a5..ef2d1f2e2 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -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 @@ -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 diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index 51b335ec6..5f8bc4459 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -219,6 +219,7 @@ func (s Subspace) Update(ctx sdk.Context, key, value []byte) error { // in the ParamSetPair by calling Subspace#Get. func (s Subspace) GetParamSet(ctx sdk.Context, ps ParamSet) { for _, pair := range ps.ParamSetPairs() { + fmt.Printf("PSUDEBUG - pairs: %s\n", pair) s.Get(ctx, pair.Key, pair.Value) } } From 85d37d9b719422a44b51d4f0d8ee9355ca81e9a6 Mon Sep 17 00:00:00 2001 From: Philip Su Date: Thu, 11 Jan 2024 11:25:46 -0800 Subject: [PATCH 2/2] rm printf --- x/params/types/subspace.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index 5f8bc4459..51b335ec6 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -219,7 +219,6 @@ func (s Subspace) Update(ctx sdk.Context, key, value []byte) error { // in the ParamSetPair by calling Subspace#Get. func (s Subspace) GetParamSet(ctx sdk.Context, ps ParamSet) { for _, pair := range ps.ParamSetPairs() { - fmt.Printf("PSUDEBUG - pairs: %s\n", pair) s.Get(ctx, pair.Key, pair.Value) } }