Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bank store migration #13821

Merged
merged 2 commits into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/bank/migrations/v3/store.go
Expand Up @@ -81,7 +81,7 @@ func migrateDenomMetadata(store sdk.KVStore, logger log.Logger) error {

for ; oldDenomMetaDataIter.Valid(); oldDenomMetaDataIter.Next() {
oldKey := oldDenomMetaDataIter.Key()
l := len(oldKey)/2 + 1
l := len(oldKey) / 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a changelog?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a changelog in the 0.46 branch then, so that I don't need to remove it from main later :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this code had a bug, can we add some code comments around whats going on here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ValarDragon v2.DenomMetadataPrefix byte is already cut out by the prefix store -> see line 77 (few lines above), so shouldn't be counted here.


newKey := make([]byte, len(types.DenomMetadataPrefix)+l)
// old key: prefix_bytes | denom_bytes | denom_bytes
Expand Down
6 changes: 3 additions & 3 deletions x/bank/migrations/v3/store_test.go
Expand Up @@ -89,8 +89,8 @@ func TestMigrateDenomMetaData(t *testing.T) {
denomMetadataStore := prefix.NewStore(store, v2.DenomMetadataPrefix)

for i := range []int{0, 1} {
key := append(v2.DenomMetadataPrefix, []byte(metaData[i].Base)...)
// keys before 0.45 had denom two times in the key
key := append([]byte{}, []byte(metaData[i].Base)...)
key = append(key, []byte(metaData[i].Base)...)
bz, err := encCfg.Codec.Marshal(&metaData[i])
require.NoError(t, err)
Expand All @@ -107,11 +107,11 @@ func TestMigrateDenomMetaData(t *testing.T) {
newKey := denomMetadataIter.Key()

// make sure old entry is deleted
oldKey := append(newKey, newKey[1:]...)
oldKey := append(newKey, newKey[0:]...)
bz := denomMetadataStore.Get(oldKey)
require.Nil(t, bz)

require.Equal(t, string(newKey)[1:], metaData[i].Base, "idx: %d", i)
require.Equal(t, string(newKey), metaData[i].Base, "idx: %d", i)
bz = denomMetadataStore.Get(denomMetadataIter.Key())
require.NotNil(t, bz)
err := encCfg.Codec.Unmarshal(bz, &result)
Expand Down