-
Notifications
You must be signed in to change notification settings - Fork 112
feat(db-arch): more dbdir to address_dir replacements #2398
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
Conversation
58f8c64 to
daec676
Compare
address available and easy to swap funcs
…on compilation features
also fixes non-set own script pubkey for recently spent output tracking on trezor
the gist of this commit is moving my_z_addr calcuations to ZCoinBuilder::new instead of ZCoinBuilder::build. this makes it so we can have a `my_z_addr_encoded` field in the builder, and we can use it to find the db path for wallet and cache dbs
remove an unused arg
and not pass it via func args
daec676 to
97d9849
Compare
|
these are ready for review. please review it commit by commit, otherwise u lose coherency and merge unrelated contexts. i wanted to stop the PR here and create a new one so to keep them small, but since it should be reviewed in a commit-by-commit fashion anyway, i will just add new commits onto here. i won't rebase already committed commits. |
|
base branch deleted by mistake. |
this is simpiler - than having to require a specific address directory - and has no down side
we call address_dir() and then join the retruned pathbuf with other directory(s), i.e. nesting more directories (see e.g. eth_trace_path() or ln_data_dir()). this means we really need to also create not just the address directory but the directories we nest on top. this commit removes the directory creation in address_dir() and makes this method infallible, this simplifies it's usage. BUT, now the caller needs to create the address directory (or make sure it's created) and any nested directories needed on top before using that directory or accessing any files in it
to follow: 1- correctly set the address_dir for SavedSwap on initialization, i.e., set it to address_from_pubkey(maker_htlc_pubkey) instead of String::new() that is currenlty set. 2- allow load_my_swap_from_db to accept an optional address_dir to shortcut the roundtrip to the global DB if possible (sometiems in the code we already have the address_dir and we don't need to hit the global DB for that). 3- implemented the global DB swap address querying logic
…m DB this serves as a shortcut so we don't have to query the global DB to find the address directory of that UUID in question
just like global and address dir
Co-authored-by: Samuel Onoja <[email protected]>
| let swap = match SavedSwap::load_my_swap_from_db(ctx, swap.uuid).await { | ||
| let maker_coin_pub = swap.my_maker_coin_htlc_pub(); | ||
| let maker_coin_address = try_s!(swap.maker_coin.address_from_pubkey(&maker_coin_pub)); | ||
| let swap = match SavedSwap::load_my_swap_from_db(ctx, Some(&maker_coin_address), swap.uuid).await { |
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 see here we pass some address to load_my_swap_from_db in the save_my_maker_swap_event fn and looks like we pass some only when we storing swaps.
I could not find where we pass Some(address) in functions where we actually read swaps, like load_from_db_by_uuid active_swaps_rpc. We always pass None there.
Is this correct?
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.
so when an address is passed, this just skips the global DB query to find the address. the global DB hosts a uuid to address mapping. but if we already know the address, we can skip that.
mm2src/coins/z_coin.rs
Outdated
| .await | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| let blocks_db = { | ||
| let cache_db_path = self.ctx.global_dir().join(format!("{}_cache.db", self.ticker)); |
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.
We have directory functions and subpath consts like "{}_cache.db" "TX_CACHE" "SWAPS" etc in different places in several sources.
I am thinking of a single DirectoryManager object which would encapsulate all such consts inside and provide methods to access all required dirs
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.
okay it's a TODO for now
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.
thanks, will put the todo in the coming PR.
…global dir This partially reverts commit 6149dbc. and puts tx cache in global direcotry.
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.
🔥 ! Only non-blockers below.
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.
LGTM other than simple questions.
| taker_swap.maker_address = negotiated_event | ||
| .maker_coin_htlc_pubkey | ||
| .and_then(|pubkey| maker_coin.address_from_pubkey(&pubkey).ok()) | ||
| .unwrap_or("Couldn't get the maker coin address. Please set it manually.".to_string()); |
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.
Shouldn't this be expect instead?
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.
so this goes as follows: if we aren't able to get the address from pubkey for any reason. we will print this message in the resulting json as a placeholder, instead of failing.
who ever is importing the swap should manually edit the [m/t]aker_address to their own correct address to get a valid [M/T]akerSavedSwap.
this is only temporary, i plan in the future to include only the htlc pubkey (which is nonfallible), and let the importer of the recreated-swap convert such pubkey to an address. this avoids the cases where we can't generate the address from a simple pubkey (like zcoin) and the cases where we don't currently have this coin enabled to convert its pubkey to an address.
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.
Thanks, let's keep this "unresolved" to keep it visible as a future ref.
|
@dimxy please check if all your comments were resolved and you have no more comments so that I can merge this PR. @mariocynicys can you please fix the conflicts? |
* dev: (29 commits) fix(p2pk): validate expected pubkey correctly for p2pk inputs (#2408) chore(docs): update old urls referencing atomicdex or old docs pages (#2428) improvement(p2p): remove hardcoded seeds (#2439) fix(evm-api): find enabled erc20 token using platform ticker (#2445) chore(docs): add DeepWiki badge to README (#2463) chore(core): organize deps using workspace.dependencies (#2449) feat(db-arch): more dbdir to address_dir replacements (#2398) chore(build-artifacts): remove duplicated mm2 build artifacts (#2448) feat(pubkey-banning): expirable bans (#2455) fix(eth-balance-events): serialize eth address using AddrToString (#2440) chore(deps): remove base58 and replace it completely with bs58 (#2427) feat(tron): initial groundwork for full TRON integration (#2425) fix(UTXO): improve tx fee calculation and min relay fee handling (#2316) deps(timed-map): bump to 1.3.1 (#2413) improvement(tendermint): safer IBC channel handler (#2298) chore(release): complete v2.4.0-beta changelogs (#2436) fix(event-streaming): initial addresses registration in utxo balance streaming (#2431) improvement(watchers): re-write use-watchers handling (#2430) fix(evm): make withdraw_nft work in HD mode (#2424) feat(taproot): support parsing taproot output address types ...
* lr-swap-wip: (37 commits) fix custom token error name fix getting chain_id from protocol_data refactor (review): use dedicated large error cfg, add new fn to FromApiValueError, fix TODO, use experimental namespace for lr rpc, more Ticker alias feat(walletconnect): add WalletConnect v2 support for EVM and Cosmos (GLEECBTC#2223) feat(ibc-routing-part-1): supporting entire Cosmos network for swaps (GLEECBTC#2459) fix(test): fix HD Wallet message signing tests (GLEECBTC#2474) improvement(builds): enable static CRT linking for MSVC builds (GLEECBTC#2464) feat(wallet): implement HD multi-address support for message signing (GLEECBTC#2432) fix(p2pk): validate expected pubkey correctly for p2pk inputs (GLEECBTC#2408) chore(docs): update old urls referencing atomicdex or old docs pages (GLEECBTC#2428) improvement(p2p): remove hardcoded seeds (GLEECBTC#2439) fix(evm-api): find enabled erc20 token using platform ticker (GLEECBTC#2445) chore(docs): add DeepWiki badge to README (GLEECBTC#2463) chore(core): organize deps using workspace.dependencies (GLEECBTC#2449) feat(db-arch): more dbdir to address_dir replacements (GLEECBTC#2398) chore(build-artifacts): remove duplicated mm2 build artifacts (GLEECBTC#2448) feat(pubkey-banning): expirable bans (GLEECBTC#2455) fix(eth-balance-events): serialize eth address using AddrToString (GLEECBTC#2440) chore(deps): remove base58 and replace it completely with bs58 (GLEECBTC#2427) feat(tron): initial groundwork for full TRON integration (GLEECBTC#2425) ...
address_dir()will now default todbdir()if thenew-db-archfeature is disabled. That won't affect dev environment while working on this feature.In this PR, a couple of
dbdir()&ctx.sqlite_connectionusages were replaces withaddress_dir()&address_db(). Suggesting to review each commit on its own.TODO: Implement the global DB querying logic fornew-db-archtargets.Doing this in the next iteration/PR as I don't want to grow this one excessively and increase the review time.
NOTE: Please open a discussion regarding the
FIXMEs in this PR and reply to the questions in them if possible.