Skip to content

Commit

Permalink
modify store outside of iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Oct 23, 2024
1 parent b2370d2 commit 8d8231a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions protocol/app/upgrades/v8.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
}

Expand Down

0 comments on commit 8d8231a

Please sign in to comment.