-
Notifications
You must be signed in to change notification settings - Fork 573
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
clears walletdb datastores during reset #3797
Conversation
following a network reset the walletdb may have data that is incompatible with database schemas. for instance, if asset identifiers in transactions or notes change, then any datastores that encode that data must be migrated or cleared. we avoid deleting the walletdb during 'reset' so that we do not delete user keys. however, the node will fail to start if it needs to apply migrations on incompatible data or even if it needs to deserialize incompatible data in the course of deleting it. to resolve this we can use 'clear' on each walletdb datastore during the 'reset' command. clear will delete all keys within a range without deserializing the values. note that clear soft-deletes data that is cleanup up later during database compactions rather than deleting immediately. - clears each walletdb datastore, except accounts and meta, during 'reset' - adds missing datastores to cleanupDeletedAccounts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Straightforward improvement.
ironfish-cli/src/commands/reset.ts
Outdated
const node = await this.sdk.node() | ||
const walletDb = node.wallet.walletDb | ||
|
||
const walletDbStores: IDatabaseStore<{ | ||
key: Readonly<unknown> | ||
value: unknown | ||
}>[] = [ | ||
walletDb.decryptedNotes, | ||
walletDb.nullifierToNoteHash, | ||
walletDb.sequenceToNoteHash, | ||
walletDb.nonChainNoteHashes, | ||
walletDb.transactions, | ||
walletDb.sequenceToTransactionHash, | ||
walletDb.pendingTransactionHashes, | ||
walletDb.timestampToTransactionHash, | ||
walletDb.assets, | ||
walletDb.nullifierToTransactionHash, | ||
walletDb.unspentNoteHashes, | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this list isn't reused anywhere right? was wondering if it's worth setting it up as a constant (or something like that) somewhere, but if this is the only place it's used, no point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in walletDb.cleanupDeletedAccounts
, too.
I think it's a good idea to define it as a walletDb property!
this is the list of stores that cache and/or index decrypted chain data that must be cleared when resetting the wallet or deleting an account
adds changes from #3797 into 'mainnet' command. clears old chain data from the walletdb that cannot be migrated or deleted by key following changes from network reset.
adds changes from #3797 into 'mainnet' command. clears old chain data from the walletdb that cannot be migrated or deleted by key following changes from network reset.
adds changes from #3797 into 'mainnet' command. clears old chain data from the walletdb that cannot be migrated or deleted by key following changes from network reset.
Summary
following a network reset the walletdb may have data that is incompatible with database schemas. for instance, if asset identifiers in transactions or notes change, then any datastores that encode that data must be migrated or cleared.
we avoid deleting the walletdb during 'reset' so that we do not delete user keys. however, the node will fail to start if it needs to apply migrations on incompatible data or even if it needs to deserialize incompatible data in the course of deleting it.
to resolve this we can use 'clear' on each walletdb datastore during the 'reset' command. clear will delete all keys within a range without deserializing the values.
note that clear soft-deletes data that is cleanup up later during database compactions rather than deleting immediately.
Testing Plan
manual testing:
ironfish reset
tested with pool account from phase 3 (~10k transactions and ~10k notes) and resetting wallet data using these changes took less than 10s.
Documentation
Does this change require any updates to the Iron Fish Docs (ex. the RPC API
Reference)? If yes, link a
related documentation pull request for the website.
Breaking Change
Is this a breaking change? If yes, add notes below on why this is breaking and
what additional work is required, if any.