diff --git a/protocol/app/upgrades/v8.0/upgrade.go b/protocol/app/upgrades/v8.0/upgrade.go index 9010906bfb3..12707b727b6 100644 --- a/protocol/app/upgrades/v8.0/upgrade.go +++ b/protocol/app/upgrades/v8.0/upgrade.go @@ -20,6 +20,11 @@ func migrateAccountplusAccountState(ctx sdk.Context, k accountpluskeeper.Keeper) iterator := storetypes.KVStorePrefixIterator(store, nil) defer iterator.Close() + var keysToDelete [][]byte + var accountStatesToSet []struct { + address sdk.AccAddress + accountState accountplustypes.AccountState + } for ; iterator.Valid(); iterator.Next() { key := iterator.Key() @@ -34,10 +39,21 @@ func migrateAccountplusAccountState(ctx sdk.Context, k accountpluskeeper.Keeper) panic(fmt.Sprintf("failed to unmarshal AccountState for key %X: %s", key, err)) } - // SetAccountState stores with prefix - k.SetAccountState(ctx, key, accountState) + accountStatesToSet = append(accountStatesToSet, struct { + address sdk.AccAddress + accountState accountplustypes.AccountState + }{key, accountState}) + + keysToDelete = append(keysToDelete, key) + } + + // Set prefixed keys + for _, item := range accountStatesToSet { + k.SetAccountState(ctx, item.address, item.accountState) + } - // Delete unprefixed key + // Delete unprefixed keys + for _, key := range keysToDelete { store.Delete(key) }