Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 committed Jun 11, 2024
1 parent eae8154 commit 3ef3407
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion simapp/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions x/auth/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3ef3407

Please sign in to comment.