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

Return success on failure to decrypt AES success action #637

Merged
merged 3 commits into from
Nov 25, 2023

Conversation

andrei-21
Copy link
Contributor

@andrei-21 andrei-21 commented Nov 23, 2023

If there is an AES success action in payRequest (LUD-10) then failure to decrypt ciphertext should not fail the payment, since the funds were actually sent and the lightning payment has succeeded.

Solves #632.

@@ -236,7 +236,9 @@ pub(crate) mod model {
/// See [SuccessAction::Aes] for received payload
///
/// See [AesSuccessActionDataDecrypted] for decrypted payload
Aes { data: AesSuccessActionDataDecrypted },
Aes {
result: Result<AesSuccessActionDataDecrypted, String>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it a good idea to use Reslut for that? If yes, how do I convert it into dart?

Copy link
Contributor

@ok300 ok300 Nov 23, 2023

Choose a reason for hiding this comment

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

Result is a good direction, try to use aResult-like enum with an inner field. These play better with bindings and uniffi AFAIK.

Something like

    pub enum AesSuccessActionDataResult {
        Decrypted { data: AesSuccessActionDataDecrypted },
        Error { data: String }
    }

To propagate the changes to the bindings for other languages, you'd have to

If there is an AES success action in `payRequest` (LUD-10) then
failure to decrypt ciphertext should not fail the payment, since the
funds were actually sent and the lightning payment has succeeded.
@andrei-21
Copy link
Contributor Author

The PR is ready for review, I went with ErrorStatus not Error because it is a keyword in UDL:

    pub enum AesSuccessActionDataResult {
        Decrypted { data: AesSuccessActionDataDecrypted },
        ErrorStatus { data: String },
    }

Bindings and other stuff were generated with some help from @dleutenegger.

@andrei-21 andrei-21 marked this pull request as ready for review November 24, 2023 11:13
Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

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

Overall looks good I think, just some comments around the error variant variables

#[derive(PartialEq, Eq, Debug, Clone, Deserialize, Serialize)]
pub enum AesSuccessActionDataResult {
Decrypted { data: AesSuccessActionDataDecrypted },
ErrorStatus { data: String },
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 it's more consistent to call this reason instead of data with a string

Suggested change
ErrorStatus { data: String },
ErrorStatus { reason: String },

or use LnUrlErrorData like in LnUrlWithdrawResult and LnUrlCallbackStatus

Suggested change
ErrorStatus { data: String },
ErrorStatus { data: LnUrlErrorData },

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed data to reason. There is no need to use LnUrlErrorData here, because the payment hash will be returned in:

                Ok(LnUrlPayResult::EndpointSuccess {
                    data: LnUrlPaySuccessData {
                        payment_hash: details.payment_hash.clone(),
                        success_action: maybe_sa_processed,
                    },
                })

and maybe_sa_processed will have AesSuccessActionDataResult::ErrorStatus.

Copy link
Collaborator

@dangeross dangeross 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

@ok300 ok300 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!

Could you please also add a short test case for when decryption fails?

There is test_lnurl_pay_aes_success_action that covers the success scenario, I imagine a similar one can check the new result type in case of failed decryption.

@andrei-21
Copy link
Contributor Author

Looks good!

Could you please also add a short test case for when decryption fails?

There is test_lnurl_pay_aes_success_action that covers the success scenario, I imagine a similar one can check the new result type in case of failed decryption.

I added test_lnurl_pay_aes_success_action_fail_to_decrypt for that.

Copy link
Contributor

@ok300 ok300 left a comment

Choose a reason for hiding this comment

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

My bad, I missed it.

Then it's all good!

@andrei-21
Copy link
Contributor Author

You haven't missed it, I added it after you asked. Do not trust git commit time ;)

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 merged commit 1fb19af into breez:main Nov 25, 2023
7 checks passed
@andrei-21 andrei-21 deleted the fix/decoding-aes-error branch November 25, 2023 14:01
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

4 participants