Skip to content

Commit

Permalink
Re-order migration double check
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Jun 22, 2023
1 parent d3e84d9 commit 2462dc9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,20 @@ export class Account {
const signed = await this.migrator.signNextMigration(this.address, status.version, wallet, nextConfig)
if (!signed) return false

await this.tracker.saveMigration(this.address, signed, this.contexts)

const nextImageHash = this.coders.config.imageHashOf(nextConfig)
// Make sure the tracker has a copy of the config
// before attempting to save the migration
// otherwise if this second step fails the tracker could end up
// with a migration to an unknown config
await this.tracker.saveWalletConfig({ config: nextConfig })
const nextCoder = universal.coderFor(nextConfig.version).config
const nextImageHash = nextCoder.imageHashOf(nextConfig as any)
const reverseConfig = await this.tracker.configOfImageHash({ imageHash: nextImageHash, noCache: true })
if (!reverseConfig || this.coders.config.imageHashOf(reverseConfig) !== nextImageHash) {
if (!reverseConfig || nextCoder.imageHashOf(reverseConfig as any) !== nextImageHash) {
throw Error(`Reverse lookup failed for imageHash ${nextImageHash}`)
}

await this.tracker.saveMigration(this.address, signed, this.contexts)

return true
}

Expand Down

0 comments on commit 2462dc9

Please sign in to comment.