Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 committed Jun 11, 2024
1 parent 5f9818b commit 053ae26
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
9 changes: 2 additions & 7 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,10 @@ For modules that have migrated, verify you are checking against `collections.Err

#### `x/accounts`

Accounts's AccountNumber will be used as a global account number tracking replacing Auth legacy AccountNumber. Must set accounts's AccountNumber with auth's AccountNumber value in upgrade handler:
Accounts's AccountNumber will be used as a global account number tracking replacing Auth legacy AccountNumber. Must set accounts's AccountNumber with auth's AccountNumber value in upgrade handler. This is done through auth keeper MigrateAccountNumber function.

```go
currentAccNum, err := app.AuthKeeper.RemoveLegacyAccountNumber(ctx)
if err != nil {
return nil, err
}

err = app.AccountsKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)
err := app.AuthKeeper.MigrateAccountNumber(ctx)
if err != nil {
return nil, err
}
Expand Down
13 changes: 1 addition & 12 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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.syncAccountNumber(ctx)
err := app.AuthKeeper.MigrateAccountNumberUnsafe(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -56,14 +56,3 @@ func (app SimApp) RegisterUpgradeHandlers() {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

func (app SimApp) syncAccountNumber(ctx context.Context) error {
currentAccNum, err := app.AuthKeeper.RemoveLegacyAccountNumber(ctx)
if err != nil {
return err
}

err = app.AccountsKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)

return err
}
2 changes: 1 addition & 1 deletion simapp/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSyncAccountNumber(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(10), num)

app.syncAccountNumber(ctx)
app.AuthKeeper.MigrateAccountNumberUnsafe(ctx)

// make sure the DB entry for this key is deleted
v, err = store.Get(bytesKey)
Expand Down
15 changes: 15 additions & 0 deletions x/auth/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,18 @@ func (ak AccountKeeper) NonAtomicMsgsExec(ctx context.Context, signer sdk.AccAdd

return msgResponses, nil
}

// MigrateAccountNumberUnsafe migrates auth's account number to accounts's account number
// and delete store entry for auth legacy GlobalAccountNumberKey.
//
// Should only use in an upgrade handler for migrate process.
func (ak AccountKeeper) MigrateAccountNumberUnsafe(ctx context.Context) error {
currentAccNum, err := ak.RemoveLegacyAccountNumber(ctx)
if err != nil {
return err
}

err = ak.AccountsModKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)

return err
}

0 comments on commit 053ae26

Please sign in to comment.