Skip to content

Commit 02f805a

Browse files
committed
Handle case when origin node received fail_malformed
1 parent 7c42921 commit 02f805a

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

src/ln/channelmanager.rs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,23 +1465,55 @@ impl ChannelManager {
14651465
/// still-available channels.
14661466
fn fail_htlc_backwards_internal(&self, mut channel_state_lock: MutexGuard<ChannelHolder>, source: HTLCSource, payment_hash: &[u8; 32], onion_error: HTLCFailReason) {
14671467
match source {
1468-
HTLCSource::OutboundRoute { .. } => {
1468+
HTLCSource::OutboundRoute { ref route, .. } => {
14691469
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
14731500
self.channel_state.lock().unwrap().pending_msg_events.push(
14741501
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),
14761514
}
14771515
);
14781516
}
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");
14851517
}
14861518
},
14871519
HTLCSource::PreviousHopData(HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret }) => {

0 commit comments

Comments
 (0)