@@ -1465,23 +1465,55 @@ impl ChannelManager {
1465
1465
/// still-available channels.
1466
1466
fn fail_htlc_backwards_internal ( & self , mut channel_state_lock : MutexGuard < ChannelHolder > , source : HTLCSource , payment_hash : & [ u8 ; 32 ] , onion_error : HTLCFailReason ) {
1467
1467
match source {
1468
- HTLCSource :: OutboundRoute { .. } => {
1468
+ HTLCSource :: OutboundRoute { ref route , .. } => {
1469
1469
mem:: drop ( channel_state_lock) ;
1470
- if let & HTLCFailReason :: ErrorPacket { ref err } = & onion_error {
1471
- let ( channel_update, payment_retryable) = self . process_onion_failure ( & source, err. data . clone ( ) ) ;
1472
- if let Some ( update) = channel_update {
1470
+ match & onion_error {
1471
+ HTLCFailReason :: ErrorPacket { ref err } => {
1472
+ #[ cfg( test) ]
1473
+ let ( channel_update, payment_retryable, onion_error_code) = self . process_onion_failure ( & source, err. data . clone ( ) ) ;
1474
+ #[ cfg( not( test) ) ]
1475
+ let ( channel_update, payment_retryable, _) = self . process_onion_failure ( & source, err. data . clone ( ) ) ;
1476
+ if let Some ( update) = channel_update {
1477
+ self . channel_state . lock ( ) . unwrap ( ) . pending_msg_events . push (
1478
+ events:: MessageSendEvent :: PaymentFailureNetworkUpdate {
1479
+ update,
1480
+ }
1481
+ ) ;
1482
+ }
1483
+ self . pending_events . lock ( ) . unwrap ( ) . push (
1484
+ events:: Event :: PaymentFailed {
1485
+ payment_hash : payment_hash. clone ( ) ,
1486
+ rejected_by_dest : !payment_retryable,
1487
+ #[ cfg( test) ]
1488
+ error_code : onion_error_code
1489
+ }
1490
+ ) ;
1491
+ } ,
1492
+ HTLCFailReason :: Reason {
1493
+ #[ cfg( test) ]
1494
+ ref failure_code,
1495
+ #[ cfg( not( test) ) ]
1496
+ failure_code: _,
1497
+ data: _ } => {
1498
+ // we get a fail_malformed_htlc from the first hop
1499
+ // TODO: not bother trying parsing onion for now
1473
1500
self . channel_state . lock ( ) . unwrap ( ) . pending_msg_events . push (
1474
1501
events:: MessageSendEvent :: PaymentFailureNetworkUpdate {
1475
- update,
1502
+ update : msgs:: HTLCFailChannelUpdate :: ChannelClosed {
1503
+ short_channel_id : route. hops [ 0 ] . short_channel_id ,
1504
+ is_permanent : true ,
1505
+ }
1506
+ }
1507
+ ) ;
1508
+ self . pending_events . lock ( ) . unwrap ( ) . push (
1509
+ events:: Event :: PaymentFailed {
1510
+ payment_hash : payment_hash. clone ( ) ,
1511
+ rejected_by_dest : route. hops . len ( ) == 1 ,
1512
+ #[ cfg( test) ]
1513
+ error_code : Some ( * failure_code) ,
1476
1514
}
1477
1515
) ;
1478
1516
}
1479
- self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: PaymentFailed {
1480
- payment_hash : payment_hash. clone ( ) ,
1481
- rejected_by_dest : !payment_retryable,
1482
- } ) ;
1483
- } else {
1484
- panic ! ( "should have onion error packet here" ) ;
1485
1517
}
1486
1518
} ,
1487
1519
HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret } ) => {
0 commit comments