Skip to content

Commit d5039f2

Browse files
authored
Report failed payments to Breez (#818)
1 parent 0e97df8 commit d5039f2

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

src/lib.rs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ pub use crate::swap::{FailedSwapInfo, ResolveFailedSwapInfo, SwapAddressInfo, Sw
7979
use crate::task_manager::TaskManager;
8080
use crate::util::unix_timestamp_to_system_time;
8181
use crate::util::LogIgnoreError;
82-
use breez_sdk_core::error::LnUrlWithdrawError;
82+
8383
pub use breez_sdk_core::error::ReceiveOnchainError as SwapError;
84-
use breez_sdk_core::error::ReceiveOnchainError;
84+
use breez_sdk_core::error::{LnUrlWithdrawError, ReceiveOnchainError, SendPaymentError};
8585
use breez_sdk_core::{
8686
parse, parse_invoice, BreezServices, GreenlightCredentials, GreenlightNodeConfig, InputType,
8787
ListPaymentsRequest, LnUrlPayRequest, LnUrlPayRequestData, LnUrlWithdrawRequest,
8888
LnUrlWithdrawRequestData, NodeConfig, OpenChannelFeeRequest, OpeningFeeParams, PaymentDetails,
8989
PaymentTypeFilter, PrepareRefundRequest, PrepareSweepRequest, ReceiveOnchainRequest,
90-
RefundRequest, SendPaymentRequest, SweepRequest,
90+
RefundRequest, ReportIssueRequest, ReportPaymentFailureDetails, SendPaymentRequest,
91+
SweepRequest,
9192
};
9293
use crow::{CountryCode, LanguageCode, OfferManager, TopupError, TopupInfo};
9394
pub use crow::{PermanentFailureCode, TemporaryFailureCode};
@@ -650,13 +651,27 @@ impl LightningNode {
650651
self.get_exchange_rate(),
651652
);
652653

653-
self.rt
654+
let result = self
655+
.rt
654656
.handle()
655657
.block_on(self.sdk.send_payment(SendPaymentRequest {
656658
bolt11: invoice_details.invoice,
657659
amount_msat,
658-
}))
659-
.map_err(map_send_payment_error)?;
660+
}));
661+
662+
if matches!(
663+
result,
664+
Err(SendPaymentError::Generic { .. }
665+
| SendPaymentError::PaymentFailed { .. }
666+
| SendPaymentError::PaymentTimeout { .. }
667+
| SendPaymentError::RouteNotFound { .. }
668+
| SendPaymentError::RouteTooExpensive { .. }
669+
| SendPaymentError::ServiceConnectivity { .. })
670+
) {
671+
self.report_send_payment_issue(invoice_details.payment_hash);
672+
}
673+
674+
result.map_err(map_send_payment_error)?;
660675
Ok(())
661676
}
662677

@@ -688,11 +703,14 @@ impl LightningNode {
688703
"LNURL server returned error: {}",
689704
data.reason
690705
),
691-
breez_sdk_core::LnUrlPayResult::PayError { data } => runtime_error!(
692-
LnUrlPayErrorCode::PaymentFailed,
693-
"Paying invoice for LNURL pay failed: {}",
694-
data.reason
695-
),
706+
breez_sdk_core::LnUrlPayResult::PayError { data } => {
707+
self.report_send_payment_issue(data.payment_hash);
708+
runtime_error!(
709+
LnUrlPayErrorCode::PaymentFailed,
710+
"Paying invoice for LNURL pay failed: {}",
711+
data.reason
712+
)
713+
}
696714
}?;
697715
self.store_payment_info(&payment_hash, None);
698716
Ok(payment_hash)
@@ -1535,6 +1553,19 @@ impl LightningNode {
15351553
.lock_unwrap()
15361554
.retrieve_latest_fiat_topup_info()
15371555
}
1556+
1557+
fn report_send_payment_issue(&self, payment_hash: String) {
1558+
debug!("Reporting failure of payment: {payment_hash}");
1559+
let data = ReportPaymentFailureDetails {
1560+
payment_hash,
1561+
comment: None,
1562+
};
1563+
let request = ReportIssueRequest::PaymentFailure { data };
1564+
self.rt
1565+
.handle()
1566+
.block_on(self.sdk.report_issue(request))
1567+
.log_ignore_error(Level::Warn, "Failed to report issue");
1568+
}
15381569
}
15391570

15401571
/// Accept lipa's terms and conditions. Should be called before instantiating a [`LightningNode`]

0 commit comments

Comments
 (0)