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

fix: Watch for specific r_hash #2574

Merged
merged 5 commits into from
May 29, 2024
Merged

Conversation

holzeis
Copy link
Contributor

@holzeis holzeis commented May 28, 2024

This PR fixes two issues.

  1. Any paid invoice that has been created by the coordinator will produce a LnPaymentReceived event. Before that change we would have simply assumed that this was the payment we've been waiting for. But it could have happened that the users went back and forth multiple times and thus created multiple invoices. So if an old invoice would have been paid, we would have triggered the order creation which would have failed, because the shared pre-image would have been incorrect. We do now verify that the received r_hash is equal to the watched r_hash.

  2. On every creation of a hodl invoice we subscribed the InvoiceWatcher for LnPaymentReceived events. These subscribers lived forever and never got cancelled, producing various error messages since the receiver has already been gone. The invoice watcher is now subscribed at the app startup and the broadcast::Sender is stored in the apps state - so that only a single Subscriber can do the job.

@holzeis holzeis requested review from bonomat and luckysori May 28, 2024 15:56
@holzeis holzeis self-assigned this May 28, 2024
This patch fixes two issues.

1. Any paid invoice that has been created by the coordinator will produce a `LnPaymentReceived` event. Before that change we would have simply assumed that this was the payment we've been waiting for. But it could have happened that the users went back and forth multiple times and thus created multiple invoices. So if an old invoice would have been paid, we would have triggered the order creation which would have failed, because the shared pre-image would have been incorrect. We do now verify that the received r_hash is equal to the watched r_hash.

2. On every creation of a hodl invoice we subscribed the `InvoiceWatcher` for `LnPaymentReceived` events. These subscribers lived forever and never got cancelled, producing various error messages since the receiver has already been gone. The invoice watcher is now subscribed at the app startup and the broadcast::Sender is stored in the apps state - so that only a single Subscriber can do the job.
@holzeis holzeis force-pushed the fix/check-r-hash-on-payment-received branch from c511305 to c02a736 Compare May 28, 2024 15:57
Allows the mock to dynamically respond with the correct hash.
Base automatically changed from fix/resilient-onboarding to main May 29, 2024 01:58
Copy link
Contributor

@luckysori luckysori left a comment

Choose a reason for hiding this comment

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

Nice, LGTM!

let message = serde_json::to_string(&InvoiceResult {
result: Invoice {
memo: "".to_string(),
expiry: 0,
amt_paid_sat: 0,
state: InvoiceState::Accepted,
payment_request: "".to_string(),
r_hash: "".to_string(),
r_hash: state.read().expect("").to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

🙃 Just allow unwrap in this crate or in this file if you don't want to deal with expect.

@holzeis holzeis added this pull request to the merge queue May 29, 2024
Merged via the queue into main with commit 79887b9 May 29, 2024
23 checks passed
@holzeis holzeis deleted the fix/check-r-hash-on-payment-received branch May 29, 2024 05:41
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.

2 participants