@@ -1143,9 +1143,11 @@ impl Node {
11431143
11441144 let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
11451145
1146- if self . payment_store . contains ( & payment_hash) {
1147- log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1148- return Err ( Error :: DuplicatePayment ) ;
1146+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1147+ if payment. status != PaymentStatus :: SendingFailed {
1148+ log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1149+ return Err ( Error :: DuplicatePayment ) ;
1150+ }
11491151 }
11501152
11511153 let payment_secret = Some ( * invoice. payment_secret ( ) ) ;
@@ -1185,11 +1187,16 @@ impl Node {
11851187 secret : payment_secret,
11861188 amount_msat : invoice. amount_milli_satoshis ( ) ,
11871189 direction : PaymentDirection :: Outbound ,
1188- status : PaymentStatus :: Failed ,
1190+ status : PaymentStatus :: SendingFailed ,
11891191 } ;
11901192 self . payment_store . insert ( payment) ?;
11911193
1192- Err ( Error :: PaymentFailed )
1194+ match e {
1195+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1196+ Err ( Error :: DuplicatePayment )
1197+ }
1198+ _ => Err ( Error :: PaymentSendingFailed ) ,
1199+ }
11931200 }
11941201 }
11951202 }
@@ -1218,9 +1225,11 @@ impl Node {
12181225 }
12191226
12201227 let payment_hash = PaymentHash ( ( * invoice. payment_hash ( ) ) . into_inner ( ) ) ;
1221- if self . payment_store . contains ( & payment_hash) {
1222- log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1223- return Err ( Error :: DuplicatePayment ) ;
1228+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1229+ if payment. status != PaymentStatus :: SendingFailed {
1230+ log_error ! ( self . logger, "Payment error: an invoice must not get paid twice." ) ;
1231+ return Err ( Error :: DuplicatePayment ) ;
1232+ }
12241233 }
12251234
12261235 let payment_id = PaymentId ( invoice. payment_hash ( ) . into_inner ( ) ) ;
@@ -1279,11 +1288,16 @@ impl Node {
12791288 secret : payment_secret,
12801289 amount_msat : Some ( amount_msat) ,
12811290 direction : PaymentDirection :: Outbound ,
1282- status : PaymentStatus :: Failed ,
1291+ status : PaymentStatus :: SendingFailed ,
12831292 } ;
12841293 self . payment_store . insert ( payment) ?;
12851294
1286- Err ( Error :: PaymentFailed )
1295+ match e {
1296+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1297+ Err ( Error :: DuplicatePayment )
1298+ }
1299+ _ => Err ( Error :: PaymentSendingFailed ) ,
1300+ }
12871301 }
12881302 }
12891303 }
@@ -1300,6 +1314,13 @@ impl Node {
13001314 let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
13011315 let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
13021316
1317+ if let Some ( payment) = self . payment_store . get ( & payment_hash) {
1318+ if payment. status != PaymentStatus :: SendingFailed {
1319+ log_error ! ( self . logger, "Payment error: must not send duplicate payments." ) ;
1320+ return Err ( Error :: DuplicatePayment ) ;
1321+ }
1322+ }
1323+
13031324 let route_params = RouteParameters {
13041325 payment_params : PaymentParameters :: from_node_id (
13051326 node_id,
@@ -1338,13 +1359,18 @@ impl Node {
13381359 hash : payment_hash,
13391360 preimage : Some ( payment_preimage) ,
13401361 secret : None ,
1341- status : PaymentStatus :: Failed ,
1362+ status : PaymentStatus :: SendingFailed ,
13421363 direction : PaymentDirection :: Outbound ,
13431364 amount_msat : Some ( amount_msat) ,
13441365 } ;
13451366 self . payment_store . insert ( payment) ?;
13461367
1347- Err ( Error :: PaymentFailed )
1368+ match e {
1369+ channelmanager:: RetryableSendFailure :: DuplicatePayment => {
1370+ Err ( Error :: DuplicatePayment )
1371+ }
1372+ _ => Err ( Error :: PaymentSendingFailed ) ,
1373+ }
13481374 }
13491375 }
13501376 }
0 commit comments