@@ -1402,9 +1402,11 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14021402
14031403 let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
14041404
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+ }
14081410 }
14091411
14101412 let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
@@ -1437,18 +1439,24 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14371439 }
14381440 Err ( payment:: PaymentError :: Sending ( e) ) => {
14391441 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+ }
14521460 }
14531461 }
14541462 }
@@ -1477,9 +1485,11 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14771485 }
14781486
14791487 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+ }
14831493 }
14841494
14851495 let payment_id = PaymentId ( invoice. payment_hash ( ) . into_inner ( ) ) ;
@@ -1532,17 +1542,24 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
15321542 Err ( payment:: PaymentError :: Sending ( e) ) => {
15331543 log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
15341544
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+ }
15461563 }
15471564 }
15481565 }
@@ -1559,6 +1576,13 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
15591576 let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
15601577 let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
15611578
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+
15621586 let route_params = RouteParameters {
15631587 payment_params : PaymentParameters :: from_node_id (
15641588 node_id,
@@ -1593,17 +1617,24 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
15931617 Err ( e) => {
15941618 log_error ! ( self . logger, "Failed to send payment: {:?}" , e) ;
15951619
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+ }
16071638 }
16081639 }
16091640 }
0 commit comments