Skip to content
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

[r2r] Include maker/taker pubkeys in MM2.db stats_swaps table #1665

Merged
merged 22 commits into from Mar 14, 2023

Conversation

borngraced
Copy link
Member

resolves: #1646

Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

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

Thank you for the great enhancement! I have one important question

taker_coin_swap_contract: Vec<u8>,
maker_coin_htlc_pub: Vec<u8>,
taker_coin_htlc_pub: Vec<u8>,
persistent_pubkey: Vec<u8>,

Choose a reason for hiding this comment

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

Please try to avoid adding NegotiationDataV4 message. I even think this new variant might break backwards compatibility.
I personally think it's better to store maker_coin_htlc_pub as maker_pubkey and taker_coin_htlc_pub as taker_pubkey. @shamardy what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

waiting for @shamardy feedback on this...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with @sergeyboyko0791 here. Using persistent_pubkey also leaks private information for private ARRR swaps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@borngraced is this PR ready for review? NegotiationDataV4 is still not removed from the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh sorry, I missed that! and yes it's ready for review.

@borngraced borngraced changed the title [wip] Include maker/taker pubkeys in MM2.db stats_swaps table [r2r] Include maker/taker pubkeys in MM2.db stats_swaps table Feb 20, 2023
@borngraced borngraced mentioned this pull request Feb 20, 2023
onur-ozkan
onur-ozkan previously approved these changes Feb 21, 2023
Copy link
Member

@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, 1 question

Comment on lines +59 to +60
"ALTER TABLE stats_swaps ADD COLUMN maker_pubkey VARCHAR(255);",
"ALTER TABLE stats_swaps ADD COLUMN taker_pubkey VARCHAR(255);",
Copy link
Member

Choose a reason for hiding this comment

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

Can't just "ALTER TABLE stats_swaps ADD COLUMN maker_pubkey VARCHAR(255), ADD COLUMN taker_pubkey VARCHAR(255); work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Signed-off-by: borngraced <samiodev@icloud.com>
@borngraced borngraced changed the title [r2r] Include maker/taker pubkeys in MM2.db stats_swaps table [wip] Include maker/taker pubkeys in MM2.db stats_swaps table Feb 24, 2023
Signed-off-by: borngraced <samiodev@icloud.com>
@borngraced borngraced changed the title [wip] Include maker/taker pubkeys in MM2.db stats_swaps table [r2r] Include maker/taker pubkeys in MM2.db stats_swaps table Feb 25, 2023
Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
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.

Good start :)
First review iteration, we just need to be all inline about implementation details at this point.

const TAKER_PAYMENT_SPEND_SEARCH_INTERVAL: f64 = 10.;

pub const TAKER_SUCCESS_EVENTS: [&str; 11] = [
"Started",
"Negotiated",
"TakerFeeSent",
"TakerPaymentInstructionsReceived",
"TakerPaymentInstructionscReceived",
Copy link
Collaborator

Choose a reason for hiding this comment

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

You seem to have changed this event unintentionally

@@ -1702,6 +1704,7 @@ impl MakerSwapStatusChanged {
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MakerSavedSwap {
pub uuid: Uuid,
pub my_persistence_pub: Option<H264Json>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please explain why you added my_persistence_pub to MakerSavedSwap/TakerSavedSwap. Isn't it available in TakerSwapData/MakerSwapDatahttps://github.com/KomodoPlatform/atomicDEX-API/blob/f39c52dff9bdad9b1b600722b88c8823f8bd0147/mm2src/mm2_main/src/lp_swap/taker_swap.rs#L513 https://github.com/KomodoPlatform/atomicDEX-API/blob/f39c52dff9bdad9b1b600722b88c8823f8bd0147/mm2src/mm2_main/src/lp_swap/maker_swap.rs#L143 I really just think we should add maker_coin_htlc_pubkeyand taker_coin_htlc_pubkey to the DB as is, there should be 4 pubkeys in this case (maker_pubkey_for_maker_coin, maker_pubkey_for_taker_coin, taker_pubkey_for_maker_coin, taker_pubkey_for_taker_coin), please note that these 4 can be different when using HD wallet functionality, we can get @sergeyboyko0791 input on this.

@cipig which exact pubkey do you parse from the json files? I can see that in stats_swaps in seednodes there will be either a MakerSavedSwap or TakerSavedSwap so I guess you use my_persistence_pub and one of maker_coin_htlc_pubkey/taker_coin_htlc_pubkey from MakerNegotiationData/TakerNegotiationData

Copy link
Member Author

Choose a reason for hiding this comment

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

@shamardy, with the help of Sergey's input, I got this context

There can be multiple cases. Let's consider the Maker side only:

  1. Maker sends NegotiationDataV1 or NegotiationDataV2 where NegotiationDataV1/2::persistent_pubkey is considered as maker_pubkey (its persistent pubkey that identifiers him uniquely)
  2. Maker sends NegotiationDataV3 where NegotiationDataV3::maker_coin_htlc_pub and NegotiationDataV3::taker_coin_htlc_pub are the same. If the maker_coin and taker_coin tickers are not ARRR (or other private coin), we can consider NegotiationDataV3::m/taker_coin_htlc_pub as maker_pubkey (its persistent pubkey that identifiers him uniquely)
  3. Maker sends NegotiationDataV3 where NegotiationDataV3::maker_coin_htlc_pub and NegotiationDataV3::taker_coin_htlc_pub are different. In that case we probably should try to figure out what coin is private in the swap, and what coin is not. The private coin pubkey should have a random m/taker_coin_htlc_pub that is unique between all swaps. But the public coin should have the same public key as the persistent_pubkey

and also the data in

 pub my_persistence_pub: Option<H264Json>,

Is the persistence_pub from T/MakerSwap
https://github.com/KomodoPlatform/atomicDEX-API/blob/a6f9a0ea383d6f87f2157bb6598a76eb7fa10071/mm2src/mm2_main/src/lp_swap/taker_swap.rs#L464

Choose a reason for hiding this comment

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

As we discussed DM, there can be the case when it's better not to share the persistent public key. For example, when you exchange two private coins (like ARRR).
But on the other hand, I am not sure if maker_coin_maker_htlc_pubkey, maker_coin_taker_htlc_pubkey, taker_coin_maker_htlc_pubkey, taker_coin_taker_htlc_pubkey pubkeys can be useful as they can be different, and we can't recognise a node that performed the swaps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

As we discussed DM, there can be the case when it's better not to share the persistent public key. For example, when you exchange two private coins (like ARRR).
But on the other hand, I am not sure if maker_coin_maker_htlc_pubkey, maker_coin_taker_htlc_pubkey, taker_coin_maker_htlc_pubkey, taker_coin_taker_htlc_pubkey pubkeys can be useful as they can be different, and we can't recognise a node that performed the swaps.

@smk762 @ca333 We need your inputs on this, it all comes down to if we want to track one pubkey for all swap operations related to a node, or track the pubkeys related to the used HD account for the swap. This can be considered another issue different from the current one. As for the current one I think we should just use the pubkeys @cipig used to parse from the json files.

Copy link

Choose a reason for hiding this comment

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

Perhaps we can use the PeerID for private coins?
The reason for the request was to gather stats on most active users (and able to delineate maker/taker activity), so for HD perhaps a single identifier for the node would be best.

Signed-off-by: borngraced <samiodev@icloud.com>
@borngraced borngraced changed the title [r2r] Include maker/taker pubkeys in MM2.db stats_swaps table [wip] Include maker/taker pubkeys in MM2.db stats_swaps table Mar 1, 2023
Signed-off-by: borngraced <samiodev@icloud.com>
Signed-off-by: borngraced <samiodev@icloud.com>
@borngraced borngraced changed the title [wip] Include maker/taker pubkeys in MM2.db stats_swaps table [r2r] Include maker/taker pubkeys in MM2.db stats_swaps table Mar 3, 2023
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.

Next iteration! We need a unit test added to make sure that the right pubkeys are saved.

Comment on lines 1885 to 1886
swap_pubkeys.maker = Some(started.my_persistent_pub);
swap_pubkeys.taker = started.maker_coin_htlc_pubkey;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't those 2 pubkeys the maker's? can you please add a unit test to test that the right pubkeys are saved to DB? you should use 3 nodes for the test (taker/maker/seednode) and use stats_swap_status RPC to check that the right pubkeys are saved to the seednode's DB.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

Comment on lines 311 to 312
swap_pubkeys.maker = started.maker_coin_htlc_pubkey;
swap_pubkeys.taker = Some(started.my_persistent_pub);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for those 2 pubkeys, aren't they both the taker's?

Copy link
Member Author

Choose a reason for hiding this comment

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

@shamardy this is ready for another round of review!

@borngraced borngraced changed the title [r2r] Include maker/taker pubkeys in MM2.db stats_swaps table [wip] Include maker/taker pubkeys in MM2.db stats_swaps table Mar 7, 2023
Signed-off-by: borngraced <samuelonoja970@gmail.com>
@borngraced borngraced changed the title [wip] Include maker/taker pubkeys in MM2.db stats_swaps table [r2r] Include maker/taker pubkeys in MM2.db stats_swaps table Mar 8, 2023
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
# Conflicts:
#	mm2src/mm2_main/src/lp_swap/maker_swap.rs
#	mm2src/mm2_main/src/lp_swap/taker_swap.rs
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.

Next iteration! Probably the last one :)

mm2src/mm2_main/src/lp_swap/maker_swap.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs Outdated Show resolved Hide resolved
borngraced and others added 2 commits March 12, 2023 06:02
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
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.

Final review :)
Just some minor stuff left, otherwise everything else looks good.

mm2src/mm2_main/src/lp_swap.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs Outdated Show resolved Hide resolved
Signed-off-by: borngraced <samuelonoja970@gmail.com>
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.

Thank you for your patience on this PR. LGTM!

@shamardy shamardy merged commit 5faec02 into dev Mar 14, 2023
@shamardy shamardy deleted the add-pubkeys-to-stats-swap branch March 14, 2023 12:31
shamardy added a commit that referenced this pull request Mar 14, 2023
shamardy added a commit that referenced this pull request Mar 14, 2023
* add change logs for PRs merged to dev only

* remove {version} - {date} and add dev branch instead

* add ibc transfer change logs

* add lightning PR #1655 to change logs

* add changelog for #1706

* add changelog for #1694, #1665

---------

Reviewed-by: laruh, caglaryucekaya <caglaryucekaya@gmail.com>
@ca333 ca333 mentioned this pull request Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants