Skip to content

Conversation

@mariocynicys
Copy link
Collaborator

@mariocynicys mariocynicys commented Mar 20, 2025

address_dir() will now default to dbdir() if the new-db-arch feature is disabled. That won't affect dev environment while working on this feature.

In this PR, a couple of dbdir() & ctx.sqlite_connection usages were replaces with address_dir() & address_db(). Suggesting to review each commit on its own.

TODO: Implement the global DB querying logic for new-db-arch targets.
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.

Base automatically changed from split-db to dev March 25, 2025 13:02
address available and easy to swap funcs
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
@mariocynicys
Copy link
Collaborator Author

mariocynicys commented Mar 25, 2025

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.

@borngraced borngraced closed this Mar 25, 2025
@borngraced borngraced deleted the split-db-temp branch March 25, 2025 14:07
@mariocynicys mariocynicys restored the split-db-temp branch March 25, 2025 14:12
@mariocynicys
Copy link
Collaborator Author

base branch deleted by mistake.

@mariocynicys mariocynicys reopened this Mar 25, 2025
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
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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

.await
#[cfg(not(target_arch = "wasm32"))]
let blocks_db = {
let cache_db_path = self.ctx.global_dir().join(format!("{}_cache.db", self.ticker));
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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
shamardy previously approved these changes May 20, 2025
Copy link
Collaborator

@shamardy shamardy left a 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.

onur-ozkan
onur-ozkan previously approved these changes May 20, 2025
Copy link
Collaborator

@onur-ozkan onur-ozkan left a 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());
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

@mariocynicys mariocynicys dismissed stale reviews from onur-ozkan and shamardy via 6d8328a May 20, 2025 06:18
@shamardy
Copy link
Collaborator

@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?

@shamardy shamardy merged commit b8b98cf into dev May 21, 2025
20 of 24 checks passed
@shamardy shamardy deleted the split-db-temp branch May 21, 2025 02:40
dimxy pushed a commit that referenced this pull request May 27, 2025
* dev:
  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)
dimxy pushed a commit that referenced this pull request May 28, 2025
* 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
  ...
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request Jun 8, 2025
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants