From 3ef34073cb47cb74dfb4bc09284c0704099b7e3c Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Wed, 12 Jun 2024 01:22:07 +0700 Subject: [PATCH] address comments --- simapp/upgrades.go | 3 ++- simapp/upgrades_test.go | 4 +++- x/auth/keeper/keeper.go | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/simapp/upgrades.go b/simapp/upgrades.go index 38206fb8360c..9433b94e37b4 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/core/appmodule" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/accounts" + authkeeper "cosmossdk.io/x/auth/keeper" epochstypes "cosmossdk.io/x/epochs/types" protocolpooltypes "cosmossdk.io/x/protocolpool/types" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -26,7 +27,7 @@ func (app SimApp) RegisterUpgradeHandlers() { UpgradeName, func(ctx context.Context, _ upgradetypes.Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) { // sync accounts and auth module account number - err := app.AuthKeeper.MigrateAccountNumberUnsafe(ctx) + err := authkeeper.MigrateAccountNumberUnsafe(ctx, &app.AuthKeeper) if err != nil { return nil, err } diff --git a/simapp/upgrades_test.go b/simapp/upgrades_test.go index 3b34120d791d..fb9e6da46607 100644 --- a/simapp/upgrades_test.go +++ b/simapp/upgrades_test.go @@ -4,6 +4,7 @@ import ( "testing" "cosmossdk.io/collections" + authkeeper "cosmossdk.io/x/auth/keeper" authtypes "cosmossdk.io/x/auth/types" cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" "github.com/stretchr/testify/require" @@ -37,7 +38,8 @@ func TestSyncAccountNumber(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(10), num) - app.AuthKeeper.MigrateAccountNumberUnsafe(ctx) + err = authkeeper.MigrateAccountNumberUnsafe(ctx, &app.AuthKeeper) + require.NoError(t, err) // make sure the DB entry for this key is deleted v, err = store.Get(bytesKey) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index ff30374e0f8d..00240e8f9a65 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -150,10 +150,10 @@ func NewAccountKeeper( return ak } -// RemoveLegacyAccountNumber is used for migration purpose only. It deletes the sequence in the DB +// removeLegacyAccountNumberUnsafe is used for migration purpose only. It deletes the sequence in the DB // and returns the last value used on success. // Deprecated -func (ak AccountKeeper) RemoveLegacyAccountNumber(ctx context.Context) (uint64, error) { +func (ak AccountKeeper) removeLegacyAccountNumberUnsafe(ctx context.Context) (uint64, error) { accNum, err := ak.accountNumber.Peek(ctx) if err != nil { return 0, err @@ -343,8 +343,8 @@ func (ak AccountKeeper) NonAtomicMsgsExec(ctx context.Context, signer sdk.AccAdd // and delete store entry for auth legacy GlobalAccountNumberKey. // // Should only use in an upgrade handler for migrating account number. -func (ak AccountKeeper) MigrateAccountNumberUnsafe(ctx context.Context) error { - currentAccNum, err := ak.RemoveLegacyAccountNumber(ctx) +func MigrateAccountNumberUnsafe(ctx context.Context, ak *AccountKeeper) error { + currentAccNum, err := ak.removeLegacyAccountNumberUnsafe(ctx) if err != nil { return fmt.Errorf("failed to migrate account number: %w", err) }