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

Verify and claim swap if not verifiable in swap loop #681

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dangeross
Copy link
Collaborator

@dangeross dangeross commented Jan 20, 2025

This PR:

  • verifies the lockup tx amount
  • claims any ongoing local receive swaps with a lockup tx but no claim tx.

Fixes #675

Testing Notes:

  • Lockup amount verification: Cannot be tested unless you co-opt with the swapper to underpay the lockup
  • Lockup tx verification: Test the receive swap is always claimed (completed) and doesn't hang until restarting the app

Copy link
Contributor

@danielgranhao danielgranhao 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! Left just a comment about a potential efficiency issue.

Tested on the CLI by commenting out the regular claim paths and it worked well.

lib/core/src/receive_swap.rs Outdated Show resolved Hide resolved
Copy link
Member

@hydra-yse hydra-yse left a comment

Choose a reason for hiding this comment

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

Nice and simple, the BlockListener comes in real handy here 👍

Copy link
Member

@roeierez roeierez 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.

lib/core/src/receive_swap.rs Show resolved Hide resolved
lib/core/src/receive_swap.rs Show resolved Hide resolved
Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

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

LGTM

@roeierez roeierez added this to the v0.7.0 milestone Jan 22, 2025
.map(|o| o.value)?;
let expected_lockup_amount_sat =
receive_swap.receiver_amount_sat + receive_swap.claim_fees_sat;
if expected_lockup_amount_sat != lockup_amount_sat {
Copy link
Member

Choose a reason for hiding this comment

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

Should be more tolerant here: expected_lockup_amount_sat <= lockup_amount_sat

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed a675bf3

Ok(ReceiveSwapImmutableData {
swap_id,
swap_timestamp: swap.created_at,
timeout_block_height: create_response.timeout_block_height,
blinding_key,
Copy link
Member

Choose a reason for hiding this comment

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

Not for the scope of this PR of course, just adding a note here that perhaps we consider to set the swap object itself instead of keep adding fields.

"Failed to verify lockup amount for Receive Swap {}: {} sat vs {} sat",
swap_id, expected_lockup_amount_sat, lockup_amount_sat
);
recovered_data.lockup_tx_id = None;
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we can simplify the recoverer by not making it responsible for validating the lockup amount?
If we prevent claiming the wrong amount isn't that enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The swap/payment would be set to Pending if we don't. Especially for non-local swaps

Copy link
Member

Choose a reason for hiding this comment

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

Right but since this is an edge case (where the swOpers cheats) doesn't it worth the simplicity? Worst case the payment stays pending untill expiration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Simplified 0cb9ca1

@dangeross dangeross force-pushed the savage-receive-claim-check branch from c377e36 to 0cb9ca1 Compare January 23, 2025 12:41
@dangeross dangeross requested a review from roeierez January 23, 2025 12:48
Copy link
Contributor

@danielgranhao danielgranhao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to commit this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope 😅

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.

Receive swap not claimed if TransactionConfirmed cannot verify lockup
4 participants