@@ -1402,9 +1402,11 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1402
1402
1403
1403
let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
1404
1404
1405
- if self . payment_store . contains ( & payment_hash) {
1406
- log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1407
- return Err ( Error :: DuplicatePayment ) ;
1405
+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1406
+ if payment. status != PaymentStatus :: SendingFailed {
1407
+ log_error ! ( self . logger, "Payment error: an invoice must not be paid twice." ) ;
1408
+ return Err ( Error :: DuplicatePayment ) ;
1409
+ }
1408
1410
}
1409
1411
1410
1412
let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
@@ -1437,18 +1439,24 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1437
1439
}
1438
1440
Err ( payment:: PaymentError :: Sending ( e) ) => {
1439
1441
log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
1440
-
1441
- let payment = PaymentDetails {
1442
- preimage : None ,
1443
- hash : payment_hash,
1444
- secret : payment_secret,
1445
- amount_msat : invoice. amount_milli_satoshis ( ) ,
1446
- direction : PaymentDirection :: Outbound ,
1447
- status : PaymentStatus :: Failed ,
1448
- } ;
1449
- self . payment_store . insert ( payment) ?;
1450
-
1451
- Err ( Error :: PaymentFailed )
1442
+ match e {
1443
+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1444
+ Err ( Error :: DuplicatePayment )
1445
+ }
1446
+ _ => {
1447
+ let payment = PaymentDetails {
1448
+ preimage : None ,
1449
+ hash : payment_hash,
1450
+ secret : payment_secret,
1451
+ amount_msat : invoice. amount_milli_satoshis ( ) ,
1452
+ direction : PaymentDirection :: Outbound ,
1453
+ status : PaymentStatus :: SendingFailed ,
1454
+ } ;
1455
+
1456
+ self . payment_store . insert ( payment) ?;
1457
+ Err ( Error :: PaymentSendingFailed )
1458
+ }
1459
+ }
1452
1460
}
1453
1461
}
1454
1462
}
@@ -1477,9 +1485,11 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1477
1485
}
1478
1486
1479
1487
let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
1480
- if self . payment_store . contains ( & payment_hash) {
1481
- log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1482
- return Err ( Error :: DuplicatePayment ) ;
1488
+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1489
+ if payment. status != PaymentStatus :: SendingFailed {
1490
+ log_error ! ( self . logger, "Payment error: an invoice must not be paid twice." ) ;
1491
+ return Err ( Error :: DuplicatePayment ) ;
1492
+ }
1483
1493
}
1484
1494
1485
1495
let payment_id = PaymentId ( invoice. payment_hash ( ) . into_inner ( ) ) ;
@@ -1532,17 +1542,24 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1532
1542
Err ( payment:: PaymentError :: Sending ( e) ) => {
1533
1543
log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
1534
1544
1535
- let payment = PaymentDetails {
1536
- hash : payment_hash,
1537
- preimage : None ,
1538
- secret : payment_secret,
1539
- amount_msat : Some ( amount_msat) ,
1540
- direction : PaymentDirection :: Outbound ,
1541
- status : PaymentStatus :: Failed ,
1542
- } ;
1543
- self . payment_store . insert ( payment) ?;
1544
-
1545
- Err ( Error :: PaymentFailed )
1545
+ match e {
1546
+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1547
+ Err ( Error :: DuplicatePayment )
1548
+ }
1549
+ _ => {
1550
+ let payment = PaymentDetails {
1551
+ hash : payment_hash,
1552
+ preimage : None ,
1553
+ secret : payment_secret,
1554
+ amount_msat : Some ( amount_msat) ,
1555
+ direction : PaymentDirection :: Outbound ,
1556
+ status : PaymentStatus :: SendingFailed ,
1557
+ } ;
1558
+ self . payment_store . insert ( payment) ?;
1559
+
1560
+ Err ( Error :: PaymentSendingFailed )
1561
+ }
1562
+ }
1546
1563
}
1547
1564
}
1548
1565
}
@@ -1559,6 +1576,13 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1559
1576
let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
1560
1577
let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
1561
1578
1579
+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1580
+ if payment. status != PaymentStatus :: SendingFailed {
1581
+ log_error ! ( self . logger, "Payment error: must not send duplicate payments." ) ;
1582
+ return Err ( Error :: DuplicatePayment ) ;
1583
+ }
1584
+ }
1585
+
1562
1586
let route_params = RouteParameters {
1563
1587
payment_params : PaymentParameters :: from_node_id (
1564
1588
node_id,
@@ -1593,17 +1617,24 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
1593
1617
Err ( e) => {
1594
1618
log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
1595
1619
1596
- let payment = PaymentDetails {
1597
- hash : payment_hash,
1598
- preimage : Some ( payment_preimage) ,
1599
- secret : None ,
1600
- status : PaymentStatus :: Failed ,
1601
- direction : PaymentDirection :: Outbound ,
1602
- amount_msat : Some ( amount_msat) ,
1603
- } ;
1604
- self . payment_store . insert ( payment) ?;
1605
-
1606
- Err ( Error :: PaymentFailed )
1620
+ match e {
1621
+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1622
+ Err ( Error :: DuplicatePayment )
1623
+ }
1624
+ _ => {
1625
+ let payment = PaymentDetails {
1626
+ hash : payment_hash,
1627
+ preimage : Some ( payment_preimage) ,
1628
+ secret : None ,
1629
+ status : PaymentStatus :: SendingFailed ,
1630
+ direction : PaymentDirection :: Outbound ,
1631
+ amount_msat : Some ( amount_msat) ,
1632
+ } ;
1633
+
1634
+ self . payment_store . insert ( payment) ?;
1635
+ Err ( Error :: PaymentSendingFailed )
1636
+ }
1637
+ }
1607
1638
}
1608
1639
}
1609
1640
}
0 commit comments