diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 7c86fb093390..81257ca02f35 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -99,9 +99,9 @@ type AccountKeeper struct { authority string // State - Schema collections.Schema - Params collections.Item[types.Params] - + Schema collections.Schema + Params collections.Item[types.Params] + AccountNumber collections.Sequence // Accounts key: AccAddr | value: AccountI | index: AccountsIndex Accounts *collections.IndexedMap[sdk.AccAddress, sdk.AccountI, AccountsIndexes] } @@ -135,6 +135,7 @@ func NewAccountKeeper( permAddrs: permAddrs, authority: authority, Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + AccountNumber: collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number"), Accounts: collections.NewIndexedMap(sb, types.AddressStoreKeyPrefix, "accounts", sdk.AccAddressKey, codec.CollInterfaceValue[sdk.AccountI](cdc), NewAccountIndexes(sb)), } schema, err := sb.Build() diff --git a/x/auth/keeper/migrations.go b/x/auth/keeper/migrations.go index 5b3418b99e65..3e8e17010fc4 100644 --- a/x/auth/keeper/migrations.go +++ b/x/auth/keeper/migrations.go @@ -3,7 +3,6 @@ package keeper import ( "context" - "cosmossdk.io/collections" v5 "cosmossdk.io/x/auth/migrations/v5" "cosmossdk.io/x/auth/types" @@ -13,16 +12,11 @@ import ( // Migrator is a struct for handling in-place store migrations. type Migrator struct { keeper AccountKeeper - // accNum is use in v4 to v5 and v5 to v6 migration - accNum collections.Sequence } // NewMigrator returns a new Migrator. func NewMigrator(keeper AccountKeeper) Migrator { - sb := collections.NewSchemaBuilder(keeper.Environment.KVStoreService) - accNumSeq := collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number") - - return Migrator{keeper: keeper, accNum: accNumSeq} + return Migrator{keeper: keeper} } // Migrate1to2 migrates from version 1 to 2. @@ -48,13 +42,13 @@ func (m Migrator) Migrate3to4(ctx context.Context) error { // It migrates the GlobalAccountNumber from being a protobuf defined value to a // big-endian encoded uint64, it also migrates it to use a more canonical prefix. func (m Migrator) Migrate4To5(ctx context.Context) error { - return v5.Migrate(ctx, m.keeper.KVStoreService, m.accNum) + return v5.Migrate(ctx, m.keeper.KVStoreService, m.keeper.AccountNumber) } // Migrate5To6 migrates the x/auth module state from the consensus version 5 to 6. // It migrates the GlobalAccountNumber from x/auth to x/accounts . func (m Migrator) Migrate5To6(ctx context.Context) error { - currentAccNum, err := m.accNum.Peek(ctx) + currentAccNum, err := m.keeper.AccountNumber.Peek(ctx) if err != nil { return err }