Skip to content

Commit

Permalink
resets account heads and birthdays in reset command
Browse files Browse the repository at this point in the history
the 'ironfish reset' command deletes the chain database and most wallet
datastores

however, it does not clear the 'heads' store. this prevents the wallet from
starting the next time the node starts because the account head will reference a
block that is missing from the chain

updates 'ironfish reset' to use 'wallet.reset' to reset all database stores,
including the heads store

adds arguments to reset, resetAccounts to optionally reset the 'createdAt' field
on each account

resets account 'createdAt' field in 'ironfish reset' if the command is used to
change from one network to another because the createdAt field will reference a
block on a different chain after changing networks
  • Loading branch information
hughy committed Sep 1, 2023
1 parent 5be7b28 commit ccf2f0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 4 additions & 7 deletions ironfish-cli/src/commands/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,17 @@ export default class Reset extends IronfishCommand {
fsAsync.rm(hostFilePath, { recursive: true, force: true }),
])

let networkChanged = false
if (flags.networkId != null && flags.networkId !== existingId) {
this.sdk.internal.set('networkId', flags.networkId)
networkChanged = true
}
this.sdk.internal.set('isFirstRun', true)
await this.sdk.internal.save()

const node = await this.sdk.node()
const walletDb = node.wallet.walletDb

await walletDb.db.open()

for (const store of walletDb.cacheStores) {
await store.clear()
}
await node.wallet.open()
await node.wallet.reset({ resetCreatedAt: networkChanged })

CliUx.ux.action.stop('Databases deleted successfully')
}
Expand Down
11 changes: 7 additions & 4 deletions ironfish/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,18 @@ export class Wallet {
}
}

async reset(): Promise<void> {
await this.resetAccounts()
async reset(options?: { resetCreatedAt?: boolean }): Promise<void> {
await this.resetAccounts(options)

this.chainProcessor.hash = null
}

private async resetAccounts(tx?: IDatabaseTransaction): Promise<void> {
private async resetAccounts(options?: {
tx?: IDatabaseTransaction
resetCreatedAt?: boolean
}): Promise<void> {
for (const account of this.listAccounts()) {
await this.resetAccount(account, { tx })
await this.resetAccount(account, options)
}
}

Expand Down

0 comments on commit ccf2f0f

Please sign in to comment.