-
Notifications
You must be signed in to change notification settings - Fork 84
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
feat(core): multi-pubkey DB support #2093
base: dev
Are you sure you want to change the base?
Conversation
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
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 think tendermint_tx_history_v2
also needs some magic in order to keep the history data separated between inner-external accounts 🫤 I hope I am wrong.. A confirmation from GUI team or QA team could be nice.
@borngraced docker tests timeout after 90 minutes, my guess is that there is a test that uses the db that now runs forever after the current changes. can you please find the problem and try to fix it? |
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.
Huge work! First review iteration where I cover most of the todo notes :)
// TODO: db_id | ||
let db_id: Option<String> = None; |
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 easy to fix I think, we should use the enabled platform coin db_id
. Similar to here
komodo-defi-framework/mm2src/coins/nft.rs
Lines 1656 to 1657 in 24774a4
let db_id = coin.inner.account_db_id().unwrap_or_else(|| ctx.rmd160_hex()); | |
let entry = active_id_chains.entry(db_id).or_insert_with(Vec::new); |
I think you should start implementing
account_db_id
for all coins, this is needed for hd wallet (in utxo and eth) where the db_id
will be the enabled_address
one.
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.
c.c. @laruh
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 easy to fix I think, we should use the enabled platform coin db_id
Speaking in general (not about should we use platform coin db_id or id of enabled_address): if to fix this in clear_nft_db
you need to require Nft activation, then please do it. Its not a problem, since most of NFT RPC already ask about it.
I think you should start implementing account_db_id for all coins, this is needed for hd wallet (in utxo and eth) where the db_id will be the enabled_address one.
need to do a deeper review of how current multi-pubkey feature work, to answer this question.
But now my answer is we should treat global NFT the same way as erc20 token (in general implementations), it is just not registered inerc20_tokens_infos
platform coin field. So nft behavior should not interfere with the implementation of suggested idea.
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 think you should start implementing account_db_id for all coins, this is needed for hd wallet (in utxo and eth) where the db_id will be the enabled_address one.
This was a comment for @borngraced so no need to do a deeper review, thanks for your input :)
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 think you should start implementing account_db_id for all coins, this is needed for hd wallet (in utxo and eth) where the db_id will be the enabled_address one.
This is not done yet.
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
// TODO: Return public_key_hash for all available and active unique pubkeys | ||
pub async fn get_public_key_hash(ctx: MmArc, _req: Json) -> GetPublicKeyRpcResult<GetPublicKeyHashResponse> { |
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.
Same here, add this to a checklist to do in another PR. The enhancement can be to get a specific enabled coin pubkeyhash
which is the enabled db_id
.
let req: OrderStatusReq = try_s!(json::from_value(req)); | ||
|
||
let db_id: Option<String> = None; // TODO |
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 is tricky and not easy to solve, we need to search for a uuid across all databases. We need to check how this is used in GUIs if we want to simplify it.
For QA reference, I'll list a few things here to be tested. Please add to the list (or tell me to remove) any items which are missing/not required. With new HD wallet:
DB migration tests: with old HD wallet (use master branch to generate some activity, then update to this branch):
Regression testing
Stress testing:
With CLI:
With Web:
Outside the scope of testing
Related issues for context |
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.
Only 2 comments in this review iteration!
// TODO: db_id | ||
let db_id: Option<String> = None; |
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 think you should start implementing account_db_id for all coins, this is needed for hd wallet (in utxo and eth) where the db_id will be the enabled_address one.
This is not done yet.
coin.start_history_background_fetching( | ||
self.ctx.metrics.clone(), | ||
TxHistoryStorageBuilder::new(&self.ctx).build()?, | ||
TxHistoryStorageBuilder::new(&self.ctx, coin_clone.into().account_db_id()).build()?, |
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.
Transaction history for HD wallet gets all transactions for all activated addresses, in my_tx_history_v2_impl
the user specifies which address or addresses they want to see. We should used shared db for it but I see that this also create problems since activating the same address in non HD mode will lead to not knowing the shared db id. For now we can have redundancy for data where it will be fetched for both dbs, we use account_shared_db_id
which should be called just shared_db_id
komodo-defi-framework/mm2src/coins/lp_coins.rs
Line 3212 in fbfe747
fn account_shared_db_id(&self) -> Option<H160> { None } |
And in it's implementation we get either the shared_db_id of the hd wallet or the
pubkeyhash
(db_id) of other wallets depending on the activation mode.P.S. I still need to examine this solution further to make sure it won't create any problems. Feel free to look at it also to make sure it will work fine.
This pull request enables support for managing multiple public keys in mm2 databases. Initially, a single database instance is generated using the startup public key rmd160. With this update, the
mm_ctx
will manage multiple database instances by leveraging the public key fromMmCoin::account_db_id
if defined, or defaulting to the mm2 startup public key.Completed
sql_connection_pool
for managing all instances of shared and sqlite connections from one placeasync_sql_connection_pool
for managing all instances of async sqlite connections from one placeindexeddb
driver implementation to allow multi pubkey supportSwapContext
,MySwapStorage
,MakerSwapStorage
,TakerSwapStorage
NftCtx
,UtxoBlockHeaderStorage
,Zcoin storages(web only)
,lp_ordermatch
and other storage impl to support multipubkeyComplex Todos:
kick_start
unfinished swap upon new database instance creation or account activation using a custom public key.Checklists for next PR
get_public_key
,get_public_key_hash
,show_priv_key
rpc for multi pubkey dbs