Skip to content

feat(legacy-stats): broadcast swap status for privacy coins#2648

Merged
shamardy merged 10 commits intostagingfrom
privacy-coins-stats
Oct 21, 2025
Merged

feat(legacy-stats): broadcast swap status for privacy coins#2648
shamardy merged 10 commits intostagingfrom
privacy-coins-stats

Conversation

@mariocynicys
Copy link
Copy Markdown
Collaborator

@mariocynicys mariocynicys commented Oct 13, 2025

This PR now includes a DB migration. Backup your DB before testing!

This PR allows broadcasting the swap status for privacy coins after hiding the identifying information from it (namely: my_persistent_pub).

We also decided to clear out MakerSwapData.taker_pubkey and TakerSwapData.maker_pubkey so not to reveal the other side's persistent pubkey. They can reveal it themselves when they want.

This PR also correct the stats db index pubkeys, where in the past we used to store one persistent pubkey for side X and htlc pubkey for side Y, but now we store persistent pubkey for side X and also the persistent pubkey for side Y. (X & Y here being the maker or taker interchangeably. such a behaviour mainly depended on who's status messages reached the stats node first)

@shamardy
Copy link
Copy Markdown
Collaborator

@mariocynicys can you change the target branch to staging?

@mariocynicys mariocynicys changed the base branch from dev to staging October 14, 2025 14:11
after hiding identifying info from it
each is hidden from the other parties side

these values also exist in the negotation messages but they seem to be mostly set to zeros (added a fixme for discussing that)
Comment thread mm2src/mm2_main/src/lp_swap/saved_swap.rs Outdated
the other party will send their status anyway to the stats node, and their pubkey will be present in `my_persistent_pub` if they every choose to include it
aside from the taker and maker gui and version, we now also grap the maker pubkey from the maker and the taker pubkey from the taker. (i.e. we won't rely on the taker to get the maker's pubkey). on the downside, if the maker has a modded kdf that doesn't send the status, then we won't get the maker's pubkey (which is their right anyway)
@mariocynicys
Copy link
Copy Markdown
Collaborator Author

@smk762 could u test if u get consistent pubkeys in this one? (the pubkeys that will be stored are the my_persistent_pubkeys from each side rather than the htlc pubkeys)

this migration replaces the htlc pubkeys with persistent pubkeys with the help of swap jsons. if a specific swap json can not be found, no action is performed and the pubkey stays as is (might be right or might be wrong)
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs Outdated
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs Outdated
this changes the migration system to use parameters of type SqlValue instead of plain Strings
@mariocynicys mariocynicys requested a review from shamardy October 16, 2025 08:57
Comment thread mm2src/mm2_main/src/database/my_swaps.rs Outdated
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs Outdated
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs Outdated
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs Outdated
Comment thread mm2src/mm2_main/src/lp_swap/maker_swap.rs Outdated
Comment thread mm2src/mm2_main/src/lp_swap/saved_swap.rs
Comment thread mm2src/mm2_main/src/lp_swap/taker_swap.rs Outdated
@smk762
Copy link
Copy Markdown

smk762 commented Oct 20, 2025

Tested a swap local kdf (as maker) and seednode running this version.

**On seednode: **

sqlite> select * from stats_swaps where uuid = '3808b964-9acb-4e0d-9d25-8a4325b59005';
id|maker_coin|taker_coin|uuid|started_at|finished_at|maker_amount|taker_amount|is_success|maker_coin_ticker|maker_coin_platform|taker_coin_ticker|taker_coin_platform|maker_coin_usd_price|taker_coin_usd_price|maker_pubkey|taker_pubkey|maker_gui|taker_gui|maker_version|taker_version
3454|ARRR|KMD|3808b964-9acb-4e0d-9d25-8a4325b59005|1760947786|1760950264|0.05|0.55|1|ARRR||KMD||0.3931083965|0.0366863638|000000000000000000000000000000000000000000000000000000000000000000||mm2_777||2.5.2-beta_c617a73|
  • SWAPS/STATS/MAKER/3808b964-9acb-4e0d-9d25-8a4325b59005.json has
          "my_persistent_pub": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "02bef0f3557873e359fcd858a80d1ab0cccd3b133de425f4edb2a69a9b96b74579",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
          "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "02120da1a42310ba95d6b69d24f2af074d89409c226ee7c82a82d45f4c74cadd21",
          "taker_coin_htlc_pubkey": "02ce5ac2b3e1ccf1ea3adc973ef687acb23fa46321ba6b836dbdb27b753b6947b8"

On local maker KDF:

sqlite> select * from stats_swaps where uuid = '3808b964-9acb-4e0d-9d25-8a4325b59005' ;
id|maker_coin|taker_coin|uuid|started_at|finished_at|maker_amount|taker_amount|is_success|maker_coin_ticker|maker_coin_platform|taker_coin_ticker|taker_coin_platform|maker_coin_usd_price|taker_coin_usd_price|maker_pubkey|taker_pubkey|maker_gui|taker_gui|maker_version|taker_version
19|ARRR|KMD|3808b964-9acb-4e0d-9d25-8a4325b59005|1760947786|1760950264|0.05|0.55|1|ARRR||KMD||0.3931083965|0.0366863638|000000000000000000000000000000000000000000000000000000000000000000||mm2_777||2.5.2-beta_c617a73|
  • SWAPS/STATS/MAKER/3808b964-9acb-4e0d-9d25-8a4325b59005.json has
smk@jarrah:~/Documents/.kdf/4874fc00e88b26b414ac4cc0d6e0b49d6d7ffc24$ cat ./SWAPS/STATS/MAKER/3808b964-9acb-4e0d-9d25-8a4325b59005.json | jq | grep pub
          "my_persistent_pub": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "02bef0f3557873e359fcd858a80d1ab0cccd3b133de425f4edb2a69a9b96b74579",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
          "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "02120da1a42310ba95d6b69d24f2af074d89409c226ee7c82a82d45f4c74cadd21",
          "taker_coin_htlc_pubkey": "02ce5ac2b3e1ccf1ea3adc973ef687acb23fa46321ba6b836dbdb27b753b6947b8"
  • SWAPS/MY/3808b964-9acb-4e0d-9d25-8a4325b59005.json has
smk@jarrah:~/Documents/.kdf/4874fc00e88b26b414ac4cc0d6e0b49d6d7ffc24$ cat ./SWAPS/MY/3808b964-9acb-4e0d-9d25-8a4325b59005.json | jq | grep pub
         "my_persistent_pub": "0371792f7a6846a0da28f3422501927ae103355c02750bc4c4d8430375329a09ac",
         "maker_coin_htlc_pubkey": "02bef0f3557873e359fcd858a80d1ab0cccd3b133de425f4edb2a69a9b96b74579",
         "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
         "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
         "maker_coin_htlc_pubkey": "02120da1a42310ba95d6b69d24f2af074d89409c226ee7c82a82d45f4c74cadd21",
         "taker_coin_htlc_pubkey": "02ce5ac2b3e1ccf1ea3adc973ef687acb23fa46321ba6b836dbdb27b753b6947b8"

my_persistent_pub matches output from get_public_key.

@mariocynicys
Copy link
Copy Markdown
Collaborator Author

mariocynicys commented Oct 20, 2025

@smk762 the thing is, for privacy coins, the persistent pubkey for the party who is running the privacy coin will not be disclosed (will be set to zeros), for their privacy.

the taker's persistent pubkey here also wasn't set (was NULL) because it seems that the taker didn't send their status (could you please confirm by checking whether SWAPS/STATS/TAKER/3808b964-9acb-4e0d-9d25-8a4325b59005.json exists). As I see that taker version and gui is also not set.

If the taker json exists, then could u please post the logs of this stats node.

edit:

Tested a swap local kdf (as maker) and seednode running this version.

if you mean here that the taker is running an old version, then this taker defiantly didn't send the swap status. because before this PR, if one of the coins in the swap (the maker here using ARRR) is a privacy coin, we don't send any status for stats.

@smk762
Copy link
Copy Markdown

smk762 commented Oct 20, 2025

Confirmed taker was on older version of KDF. I'll setup a pair on the latest commit of this branch for confirmation testing, and post here once complete.

Comment thread mm2src/mm2_main/src/database/stats_swaps.rs
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs Outdated
Comment thread mm2src/mm2_main/src/database/stats_swaps.rs Outdated
@smk762
Copy link
Copy Markdown

smk762 commented Oct 20, 2025

Under maker/taker, there appears to be a different value for my_persistent_pub between the json file under SWAPS/MY compared to SWAPS/STATS/{M,T}AKER.

UUID: e6851748-8fdb-42db-928e-f9fcdd6e5d20
Taker: 03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46
Maker: 0371792f7a6846a0da28f3422501927ae103355c02750bc4c4d8430375329a09ac
KDF commit: 2.5.2-beta_c617a73 (both sides & seednode)

seednode

$ cat ./.kdf/DB/a8768e7ff55c6c5041bf79d06b74aeed1bb7aa91/SWAPS/STATS/TAKER/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub`
          "my_persistent_pub": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46",
          "maker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f"

cat ./.kdf/DB/a8768e7ff55c6c5041bf79d06b74aeed1bb7aa91/SWAPS/STATS/MAKER/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub
          "my_persistent_pub": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
          "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46"

sqlite> select * from stats_swaps where uuid = 'e6851748-8fdb-42db-928e-f9fcdd6e5d20';

id|maker_coin|taker_coin|uuid|started_at|finished_at|maker_amount|taker_amount|is_success|maker_coin_ticker|maker_coin_platform|taker_coin_ticker|taker_coin_platform|maker_coin_usd_price|taker_coin_usd_price|maker_pubkey|taker_pubkey|maker_gui|taker_gui|maker_version|taker_version
3483|ARRR|KMD|e6851748-8fdb-42db-928e-f9fcdd6e5d20|1760961162|1760963489|0.0181818181818182|0.2|1|ARRR||KMD||0.396987|0.03699919|000000000000000000000000000000000000000000000000000000000000000000|03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46|mm2_777|MM2CLI|2.5.2-beta_c617a73|2.5.2-beta_c617a73

MAKER:

$ cat ./SWAPS/STATS/MAKER/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub
          "my_persistent_pub": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
          "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46"

$ cat ./SWAPS/STATS/TAKER/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub
          "my_persistent_pub": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46",
          "maker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f"

$ cat ./SWAPS/MY/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub
          "my_persistent_pub": "0371792f7a6846a0da28f3422501927ae103355c02750bc4c4d8430375329a09ac",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
          "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46"

sqlite> select * from stats_swaps where uuid = 'e6851748-8fdb-42db-928e-f9fcdd6e5d20';

id|maker_coin|taker_coin|uuid|started_at|finished_at|maker_amount|taker_amount|is_success|maker_coin_ticker|maker_coin_platform|taker_coin_ticker|taker_coin_platform|maker_coin_usd_price|taker_coin_usd_price|maker_pubkey|taker_pubkey|maker_gui|taker_gui|maker_version|taker_version
21|ARRR|KMD|e6851748-8fdb-42db-928e-f9fcdd6e5d20|1760961162|1760963489|0.0181818181818182|0.2|1|ARRR||KMD||0.396987|0.03699919|000000000000000000000000000000000000000000000000000000000000000000|03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46|mm2_777|MM2CLI|2.5.2-beta_c617a73|2.5.2-beta_c617a73

TAKER:

$ cat ./SWAPS/STATS/MAKER/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub
          "my_persistent_pub": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
          "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46"

$ cat ./SWAPS/STATS/TAKER/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub
          "my_persistent_pub": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46",
          "maker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f"

$ cat ./SWAPS/MY/e6851748-8fdb-42db-928e-f9fcdd6e5d20.json | jq | grep pub
          "my_persistent_pub": "0371792f7a6846a0da28f3422501927ae103355c02750bc4c4d8430375329a09ac",
          "maker_coin_htlc_pubkey": "0208ea037983db248ff91573efc449595f183a9fe8310cfb1e157647b2c65ea0d6",
          "taker_coin_htlc_pubkey": "027fe9594b1bf50cb0b34087d3cdb1b6ce1c351a050562daee87e5698b21f51b7f",
          "taker_pubkey": "000000000000000000000000000000000000000000000000000000000000000000",
          "maker_coin_htlc_pubkey": "03823cc600a347fad1e3c76f45c3780dc7b427a7d8b8aef93aacde870395d59df0",
          "taker_coin_htlc_pubkey": "03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46"

sqlite> select * from stats_swaps where uuid = 'e6851748-8fdb-42db-928e-f9fcdd6e5d20';

id|maker_coin|taker_coin|uuid|started_at|finished_at|maker_amount|taker_amount|is_success|maker_coin_ticker|maker_coin_platform|taker_coin_ticker|taker_coin_platform|maker_coin_usd_price|taker_coin_usd_price|maker_pubkey|taker_pubkey|maker_gui|taker_gui|maker_version|taker_version
21|ARRR|KMD|e6851748-8fdb-42db-928e-f9fcdd6e5d20|1760961162|1760963489|0.0181818181818182|0.2|1|ARRR||KMD||0.396987|0.03699919|000000000000000000000000000000000000000000000000000000000000000000|03f394a5c245230e9d2ee3d3fef89b2398e91621f008b6ba9256aaf98fd55c5d46|mm2_777|MM2CLI|2.5.2-beta_c617a73|2.5.2-beta_c617a73

@mariocynicys
Copy link
Copy Markdown
Collaborator Author

@smk762 yup that's the expected behavior.

let's not regard SWAPS/MY/ since it contains full info and comparing it to SWAPS/STATS/ at it is kinda cheating.

the info saved in stats jsons and stats DB is masked as expected (for privacy coins, persistent pubkeys shouldn't be leaked).

If you wanna test that persistent pubkeys are stored correctly for both taker and maker (in stats DB), then u gotta use two non-privacy coins in the swap so u can view both persistent pubkeys.

the stats this PR provide for the privacy coins exclude the persistent pubkey for the party using the privacy coin, since that defeats the anonymity aspect of using the privacy coin.

dunno if recreate_taker_swap even works due to this, but also my_persistent_pub might not be that useful after all for the party who is receiving the recreated swap since they already have hold of that public key already
@smk762 smk762 self-requested a review October 21, 2025 03:57
Copy link
Copy Markdown

@smk762 smk762 left a comment

Choose a reason for hiding this comment

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

Output matches expected, thanks.

Comment thread mm2src/common/log.rs
Copy link
Copy Markdown
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.

Thanks a lot for the fix!

@shamardy shamardy merged commit 52b76dd into staging Oct 21, 2025
19 of 25 checks passed
@shamardy shamardy deleted the privacy-coins-stats branch October 21, 2025 06:14
shamardy added a commit that referenced this pull request Oct 21, 2025
…staging-to-dev

chore(release): propagate #2648 (staging→dev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants