Skip to content

Commit 15f849a

Browse files
committed
migrator
1 parent 18875b2 commit 15f849a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

x/epochstorage/keeper/migrations.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,25 @@ func (m Migrator) SetEpochHashForMigrator(ctx sdk.Context, epoch uint64, hash []
124124
panic(err)
125125
}
126126
}
127+
128+
// fix provider metadata to be consistent with the stake entries
129+
func (m Migrator) MigrateVersion8To9(ctx sdk.Context) error {
130+
allMetadata, err := m.keeper.GetAllMetadata(ctx)
131+
if err != nil {
132+
return err
133+
}
134+
135+
for _, metadata := range allMetadata {
136+
chains := []string{}
137+
for _, chainID := range metadata.Chains {
138+
stakeEntry, found := m.keeper.GetStakeEntryCurrent(ctx, chainID, metadata.Provider)
139+
if found {
140+
chains = append(chains, stakeEntry.Chain)
141+
}
142+
}
143+
metadata.Chains = chains
144+
m.keeper.SetMetadata(ctx, metadata)
145+
}
146+
147+
return nil
148+
}

x/epochstorage/module.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
135135
// panic:ok: at start up, migration cannot proceed anyhow
136136
panic(fmt.Errorf("%s: failed to register migration to v8: %w", types.ModuleName, err))
137137
}
138+
139+
// register v8 -> v9 migration
140+
if err := cfg.RegisterMigration(types.ModuleName, 8, migrator.MigrateVersion8To9); err != nil {
141+
panic(fmt.Errorf("%s: failed to register migration to v9: %w", types.ModuleName, err))
142+
}
138143
}
139144

140145
// RegisterInvariants registers the capability module's invariants.

0 commit comments

Comments
 (0)