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] Extend swap watcher node functionality for UTXO #1496

Merged
merged 92 commits into from
Oct 26, 2022
Merged

Conversation

caglaryucekaya
Copy link

@caglaryucekaya caglaryucekaya commented Oct 10, 2022

The second PR for the swap watcher nodes adds the following improvements as part of #1431:

  • State machine implementation
  • Refund taker payment functionality
  • Check if the maker payment is already spent or refunded
  • Wait for the takers before spending the maker payment
  • Keep track of running watchers using TimeCache
  • Error handling with ValidatePaymentError
  • Validate the public key of the source of the watcher message
  • Prevent spam attacks by validating the taker fee

@caglaryucekaya caglaryucekaya changed the title [wip] Extend swap watcher node functionality for UTXO [r2r] Extend swap watcher node functionality for UTXO Oct 22, 2022
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.

Thanks for the fixes! Just a few notes

@@ -616,6 +598,56 @@ impl SwapOps for SolanaCoin {
fn validate_other_pubkey(&self, _raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { unimplemented!() }
}

#[allow(clippy::forget_ref, clippy::forget_copy, clippy::cast_ref_to_mut)]

Choose a reason for hiding this comment

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

Is this required? If I'm not mistaken, it's needed if a trait or a struct is mockable, but not sure

Choose a reason for hiding this comment

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

Could you please also check the other places where #[allow(clippy::forget_ref, clippy::forget_copy, clippy::cast_ref_to_mut)] is used.

@@ -786,6 +769,56 @@ impl SwapOps for TendermintCoin {
fn validate_other_pubkey(&self, _raw_pubkey: &[u8]) -> MmResult<(), ValidateOtherPubKeyErr> { todo!() }
}

#[async_trait]
#[allow(unused_variables)]

Choose a reason for hiding this comment

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

How about marking unused variables with _ prefix?

let duration = (self.r().data.lock_duration * 4) / 5;
let timeout = self.r().data.started_at + duration;

let timeout = wait_for_taker_payment_conf_until(self.r().data.started_at, self.r().data.lock_duration);

Choose a reason for hiding this comment

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

This is the reason why I thought about step_1, step_2 initially. At the spend_taker_payment we should have gotten the required taker payment confirmations already, and wait_for_taker_payment_conf_until looks a bit weird.
Let's leave it as it is, but I think it's worth to rename this function somehow.

Copy link
Member

Choose a reason for hiding this comment

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

step_1/step_2/... is not informative and possible cause for a mess in the future: if a step is added or deleted, one can have a hard time figuring out the renumbering of the steps.
But I agree that wait_for_taker_payment_conf_until is not a good match to use in spend_taker_payment. I assume an appropriate name would be like taker_payment_spend_deadline.

self.w().taker_spends_maker_payment_preimage = preimage_hex
TakerSwapEvent::WatcherMessageSent(taker_spends_maker_payment, taker_refunds_payment) => {
self.w().taker_spends_maker_payment_preimage = taker_spends_maker_payment;
self.w().taker_refunds_payment = taker_refunds_payment;

Choose a reason for hiding this comment

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

Shouldn't taker_refunds_payment name similarly to taker_spends_maker_payment_preimage? I mean taker_refunds_payment_preimage.

@caglaryucekaya caglaryucekaya changed the title [r2r] Extend swap watcher node functionality for UTXO [wip] Extend swap watcher node functionality for UTXO Oct 24, 2022
@artemii235
Copy link
Member

artemii235 commented Oct 25, 2022

@caglaryucekaya As I can see, only minor notes are left. Could you please push the current state of this PR and add leftover items to the checklist, similar to #1432 (comment)?

UPD Link to the checklist: #1431 (comment)

artemii235
artemii235 previously approved these changes Oct 25, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

Approving with one TODO for the next sprint.

let mut attempts = 0;
let taker_fee_hash = H256Json::from(taker_fee_hash.as_slice());
loop {
let taker_fee_tx = match coin
Copy link
Member

Choose a reason for hiding this comment

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

Please add more validations that are done in utxo_common::validate_fee on the next iteration. As of now, a trading party can submit any transaction signed by its pubkey, and it will pass the validation. It might be not even a dex fee transaction.

Copy link
Author

Choose a reason for hiding this comment

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

Alright you can merge the current state. I was working on making the watchers periodically check if the taker already spent the maker payment, thought I could make it in this sprint but that also requires some review so it's better I leave it to the next sprint, together with the final notes here I didn't work on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should also check for the transaction time or block height since a trading party can reuse an old fee transaction signed by his pub and it will also pass validation without this check.

@caglaryucekaya caglaryucekaya changed the title [wip] Extend swap watcher node functionality for UTXO [r2r] Extend swap watcher node functionality for UTXO Oct 25, 2022
shamardy
shamardy previously approved these changes Oct 25, 2022
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.

Great Work! Only 2 comments for next sprint :)

@@ -271,6 +271,10 @@ where
}

pub fn contains(&mut self, key: &Key) -> bool { self.0.contains_key(key) }

Copy link
Collaborator

Choose a reason for hiding this comment

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

let mut attempts = 0;
let taker_fee_hash = H256Json::from(taker_fee_hash.as_slice());
loop {
let taker_fee_tx = match coin
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should also check for the transaction time or block height since a trading party can reuse an old fee transaction signed by his pub and it will also pass validation without this check.

@artemii235
Copy link
Member

artemii235 commented Oct 25, 2022

@ozkanonur @sergeyboyko0791 @borngraced Could you please check if you have something to add?
@caglaryucekaya Could you please then put all leftover review notes to the checklist here? #1431 (comment)

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.

@caglaryucekaya @artemii235 I don't have more notes. Please fix the comments from the last review at the next iteration.
Anyway, the last comments are more cosmetic, so great job 🔥

borngraced
borngraced previously approved these changes Oct 25, 2022
Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

LGTM!! 👏👏👏

laruh
laruh previously approved these changes Oct 26, 2022
Copy link
Member

@laruh laruh left a comment

Choose a reason for hiding this comment

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

Looks good to me! 🚀

@artemii235
Copy link
Member

@caglaryucekaya IRIS swaps PR is merged. Could you solve git conflicts, please?

onur-ozkan
onur-ozkan previously approved these changes Oct 26, 2022
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.

🔥

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.

LGTM! 🔥

@sergeyboyko0791 sergeyboyko0791 merged commit 4d2071f into dev Oct 26, 2022
@sergeyboyko0791 sergeyboyko0791 deleted the watchtower branch October 26, 2022 11:35
@sergeyboyko0791 sergeyboyko0791 mentioned this pull request Jan 9, 2023
8 tasks
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.

7 participants