-
Notifications
You must be signed in to change notification settings - Fork 113
fix(HD-Wallet): store & load correct HD Accounts #2537
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
base: dev
Are you sure you want to change the base?
Conversation
as it's gonna be used as the identifier for the wallet instead of coin ticker
update the schema to include purpose and coin_type integers. currently also the same migration deletes the hd_account table where purpose=0 (and since purpose was just added, then the migration deletes all rows). we can rethink that before merging this PR. we can leave a leehway where marking purpose=0 means that this entry is carried over from an old mm2 version and we keep waiting until the user ever decides to enable the coin and we check the xpub and find it the one matching in the DB, only then do we assign the purpose and coin values to the correct values gotten from the recent enablement. this solution ofc doesn't work for HW wallets, otherwise we gonna ask HW wallets to derive xpubs all the time which is the bad UX we tryna avoid
this clears the object store, deletes the indexes and reinitailzes the new indexes with the proper fields using the same indexes names.
… hd_wallet_storage
|
Quoting myself (from DMs):
@shamardy this PR doesn't do that. I opted to not do that for perf reasons. not a strong opinion tho, so we can impl this if you want. |
|
heck no... not this |
@mariocynicys can you please write a test case for @smk762 to test this and know how GUIs should handle this. |
But all testnet coins should use the same |
thanks! didn't know that. |
|
discussed over DM with @shamardy: we can set the purpose and coin_type to |
this step is supposed to look for bad accounts and fix them to (replace them by) good accounts by setting the correct purpose and coin_types. a bad account is fixed into a good one only if the derived xpub matches the one stored in the bad account. if they don't match, this means the current purpose and coin_type of the coin don't match the ones who were used to create the bad account. this commit has compilation errors for multiple reasons. but still separating it away to be coherent. fixing the compilation errors in the next commits
as it has more (friendly) methods to deal with data inside the object store
because it was infunctionally written (doesn't wait on the IDBRequest to complete) and it already exists in IdbObjectStoreImpl that was added inside the table upgrader the previous commit
f975372 to
1079f11
Compare
|
im still working on creating the ability to do updates while |
they keep spitting annoying warnings :/
this looks unsafe compilation-wise due to the Send + Sync unsafe impls on DbUpgrader. but in reality this should be fine since the upgrades are being ran in a single threaded fashion (one after the other)
shamardy
left a comment
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.
Next review iteration!
| const DB_VERSION: u32 = 1; | ||
|
|
||
| const CREATE_MIGRATIONS_TABLE: &str = | ||
| "CREATE TABLE IF NOT EXISTS migration (current_migration INTEGER NOT_NULL UNIQUE);"; |
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.
NOT_NULL should be NOT NULL
| pub fn default_for_test(coin_type: u32) -> HDPathToCoin { | ||
| HDPathToCoin { | ||
| value: Bip32PurposeValue { | ||
| purpose: Bip43Purpose::Bip84, |
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.
Why would Bip84 be default for tests?
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.
I want some default value for tests to use it here: https://github.com/KomodoPlatform/komodo-defi-framework/blob/629fdeabb69e815bb9bd0078d731468f27c2b76b/mm2src/coins/hd_wallet/storage/mod.rs#L249
but also want the coin_type to be variable, that's why this doesn't fit as a impl Default.
i might just call it for_test instead?
as for why Bip84 specifically: it's not a default but maybe later we will add it as a parameter.
| // FIXME: Here instead of clearing the table, you need to access the table and set every purpose and coin_type field to -1. | ||
| // let items = table.object_store_impl.get_all_items().await; (we need this current method to be async) |
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.
When are you planning to work on this FIXME?
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.
done :D
we can now do data-manipulation migrations on the fly through on_upgrade_needed
this could be utilized in saved_swaps 3819d8e (left a todo for it)
we also don't really need the Send, we just need the Sync to be able to Send a reference of DbUpgrader
add the datastore mutation code on upgrade callback. this still fails though because these calls aren't Send which on_upgrade_needed needs them to be
looks like we never needed the Send requirement from BoxFuture after all :)
including the Sync where the reference was needed to be Send
|
@smk762 |
|
@smk762 |
|
@smk762 |
|
@smk762 |
|
@smk762 |
7 similar comments
|
@smk762 |
|
@smk762 |
|
@smk762 |
|
@smk762 |
|
@smk762 |
|
@smk762 |
|
@smk762 |
This PR makes it so that
HDPathToCoinis a fieled ofHDWalletCoinStorageand integrates it inside the databases.HDWalletCoinStorageused to represent a selective set of the DB rows that match the samehd_wallet_rmd160andcoin(ticker).This has changed to
hd_wallet_rmd160andpurposeandcoin_type(sincepurpose+coin_typedefine the coin uniquely*).coinfield is still stored in the DB but is not used. This is more for convenience.This PR at the current state will purge your HD Wallet DB via a migration when run, so take a backup of it before running this code.
Will discuss a mitigation (easy for native, a little harder/tedious for wasm) for this side-effect in the review.
*: This isn't entirely true. All test coins use the same
coin_type=1.How to test this (please backup your
MM2-shared.dbDB first):purpose&coin_typein the DB selector/updater query (this doesn't really have any effect from the user facing side). So methods likecreate_new_accountandgenerate_new_addressshould do such things.supersedes #2482
closes #2470