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

clears walletdb datastores during reset #3797

Merged
merged 2 commits into from
Apr 19, 2023
Merged

Conversation

hughy
Copy link
Contributor

@hughy hughy commented Apr 18, 2023

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.

  • clears each walletdb datastore, except accounts and meta, during 'reset'
  • adds missing datastores to cleanupDeletedAccounts

Testing Plan

manual testing:

  1. start with wallet on earlier version before network reset (e.g., v0.1.70)
  2. upgrade to v0.1.76
  3. run ironfish reset
  4. start the node

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.

[ ] Yes

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.

[ ] Yes

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
@hughy hughy requested a review from a team as a code owner April 18, 2023 00:13
Copy link
Contributor

@EvanJRichard EvanJRichard left a comment

Choose a reason for hiding this comment

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

Straightforward improvement. :shipit:

Comment on lines 83 to 102
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,
]

Copy link
Contributor

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

Copy link
Contributor Author

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
@hughy hughy merged commit b872b70 into staging Apr 19, 2023
@hughy hughy deleted the fix/ifl-653/reset-walletdb branch April 19, 2023 17:02
hughy added a commit that referenced this pull request Apr 19, 2023
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.
hughy added a commit that referenced this pull request Apr 19, 2023
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.
NullSoldier pushed a commit that referenced this pull request Apr 20, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants