@@ -1297,9 +1297,11 @@ impl Node {
12971297
12981298 let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
12991299
1300- if self . payment_store . contains ( & payment_hash) {
1301- log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1302- return Err ( Error :: DuplicatePayment ) ;
1300+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1301+ if payment. status != PaymentStatus :: SendingFailed {
1302+ log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1303+ return Err ( Error :: DuplicatePayment ) ;
1304+ }
13031305 }
13041306
13051307 let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
@@ -1339,11 +1341,16 @@ impl Node {
13391341 secret : payment_secret,
13401342 amount_msat : invoice. amount_milli_satoshis ( ) ,
13411343 direction : PaymentDirection :: Outbound ,
1342- status : PaymentStatus :: Failed ,
1344+ status : PaymentStatus :: SendingFailed ,
13431345 } ;
13441346 self . payment_store . insert ( payment) ?;
13451347
1346- Err ( Error :: PaymentFailed )
1348+ match e {
1349+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1350+ Err ( Error :: DuplicatePayment )
1351+ }
1352+ _ => Err ( Error :: PaymentSendingFailed ) ,
1353+ }
13471354 }
13481355 }
13491356 }
@@ -1372,9 +1379,11 @@ impl Node {
13721379 }
13731380
13741381 let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
1375- if self . payment_store . contains ( & payment_hash) {
1376- log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1377- return Err ( Error :: DuplicatePayment ) ;
1382+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1383+ if payment. status != PaymentStatus :: SendingFailed {
1384+ log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1385+ return Err ( Error :: DuplicatePayment ) ;
1386+ }
13781387 }
13791388
13801389 let payment_id = PaymentId ( invoice. payment_hash ( ) . into_inner ( ) ) ;
@@ -1433,11 +1442,16 @@ impl Node {
14331442 secret : payment_secret,
14341443 amount_msat : Some ( amount_msat) ,
14351444 direction : PaymentDirection :: Outbound ,
1436- status : PaymentStatus :: Failed ,
1445+ status : PaymentStatus :: SendingFailed ,
14371446 } ;
14381447 self . payment_store . insert ( payment) ?;
14391448
1440- Err ( Error :: PaymentFailed )
1449+ match e {
1450+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1451+ Err ( Error :: DuplicatePayment )
1452+ }
1453+ _ => Err ( Error :: PaymentSendingFailed ) ,
1454+ }
14411455 }
14421456 }
14431457 }
@@ -1454,6 +1468,13 @@ impl Node {
14541468 let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
14551469 let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
14561470
1471+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1472+ if payment. status != PaymentStatus :: SendingFailed {
1473+ log_error ! ( self . logger, "Payment error: must not send duplicate payments." ) ;
1474+ return Err ( Error :: DuplicatePayment ) ;
1475+ }
1476+ }
1477+
14571478 let route_params = RouteParameters {
14581479 payment_params : PaymentParameters :: from_node_id (
14591480 node_id,
@@ -1492,13 +1513,18 @@ impl Node {
14921513 hash : payment_hash,
14931514 preimage : Some ( payment_preimage) ,
14941515 secret : None ,
1495- status : PaymentStatus :: Failed ,
1516+ status : PaymentStatus :: SendingFailed ,
14961517 direction : PaymentDirection :: Outbound ,
14971518 amount_msat : Some ( amount_msat) ,
14981519 } ;
14991520 self . payment_store . insert ( payment) ?;
15001521
1501- Err ( Error :: PaymentFailed )
1522+ match e {
1523+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1524+ Err ( Error :: DuplicatePayment )
1525+ }
1526+ _ => Err ( Error :: PaymentSendingFailed ) ,
1527+ }
15021528 }
15031529 }
15041530 }
0 commit comments