Skip to content

Commit 6bb663f

Browse files
committed
Send PaymentForwardedFailed for forward failures
1 parent 1994fdd commit 6bb663f

11 files changed

+212
-101
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
853853
events::Event::PendingHTLCsForwardable { .. } => {
854854
nodes[$node].process_pending_htlc_forwards();
855855
},
856+
events::Event::PaymentForwardedFailed { .. } => {},
856857
_ => if out.may_fail.load(atomic::Ordering::Acquire) {
857858
return;
858859
} else {

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
828828

829829
// Fail the payment backwards, failing the monitor update on nodes[1]'s receipt of the RAA
830830
assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1));
831-
expect_pending_htlcs_forwardable!(nodes[2]);
831+
expect_pending_htlcs_forwardable!(nodes[2], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
832832
check_added_monitors!(nodes[2], 1);
833833

834834
let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -909,7 +909,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
909909
let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_2.2).unwrap().clone();
910910
nodes[1].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update);
911911
check_added_monitors!(nodes[1], 0);
912-
expect_pending_htlcs_forwardable!(nodes[1]);
912+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
913913
check_added_monitors!(nodes[1], 1);
914914

915915
let mut events_3 = nodes[1].node.get_and_clear_pending_msg_events();
@@ -1689,7 +1689,7 @@ fn test_monitor_update_on_pending_forwards() {
16891689

16901690
let (_, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000);
16911691
assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1));
1692-
expect_pending_htlcs_forwardable!(nodes[2]);
1692+
expect_pending_htlcs_forwardable!(nodes[2], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
16931693
check_added_monitors!(nodes[2], 1);
16941694

16951695
let cs_fail_update = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -1710,7 +1710,7 @@ fn test_monitor_update_on_pending_forwards() {
17101710
commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false);
17111711

17121712
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
1713-
expect_pending_htlcs_forwardable!(nodes[1]);
1713+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
17141714
check_added_monitors!(nodes[1], 1);
17151715
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
17161716
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
@@ -2094,7 +2094,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
20942094
check_closed_broadcast!(nodes[1], true);
20952095
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
20962096
check_added_monitors!(nodes[1], 1);
2097-
expect_pending_htlcs_forwardable!(nodes[1]);
2097+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
20982098

20992099
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]);
21002100
expect_payment_sent_without_paths!(nodes[0], payment_preimage);
@@ -2456,7 +2456,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
24562456
};
24572457
if second_fails {
24582458
assert!(nodes[2].node.fail_htlc_backwards(&payment_hash));
2459-
expect_pending_htlcs_forwardable!(nodes[2]);
2459+
expect_pending_htlcs_forwardable!(nodes[2], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
24602460
check_added_monitors!(nodes[2], 1);
24612461
get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
24622462
} else {
@@ -2490,7 +2490,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
24902490

24912491
if second_fails {
24922492
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (0, 0), (1, 0), (0, 0), (0, 0), (false, false));
2493-
expect_pending_htlcs_forwardable!(nodes[1]);
2493+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
24942494
} else {
24952495
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (1, 0), (0, 0), (0, 0), (0, 0), (false, false));
24962496
}

lightning/src/ln/channel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5608,7 +5608,7 @@ impl<Signer: Sign> Channel<Signer> {
56085608
/// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
56095609
/// Also returns the list of payment_hashes for channels which we can safely fail backwards
56105610
/// immediately (others we will have to allow to time out).
5611-
pub fn force_shutdown(&mut self, should_broadcast: bool) -> (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash)>) {
5611+
pub fn force_shutdown(&mut self, should_broadcast: bool) -> (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash, HTLCDestination)>) {
56125612
// Note that we MUST only generate a monitor update that indicates force-closure - we're
56135613
// called during initialization prior to the chain_monitor in the encompassing ChannelManager
56145614
// being fully configured in some cases. Thus, its likely any monitor events we generate will
@@ -5618,10 +5618,11 @@ impl<Signer: Sign> Channel<Signer> {
56185618
// We go ahead and "free" any holding cell HTLCs or HTLCs we haven't yet committed to and
56195619
// return them to fail the payment.
56205620
let mut dropped_outbound_htlcs = Vec::with_capacity(self.holding_cell_htlc_updates.len());
5621+
let counterparty_node_id = self.get_counterparty_node_id();
56215622
for htlc_update in self.holding_cell_htlc_updates.drain(..) {
56225623
match htlc_update {
56235624
HTLCUpdateAwaitingACK::AddHTLC { source, payment_hash, .. } => {
5624-
dropped_outbound_htlcs.push((source, payment_hash));
5625+
dropped_outbound_htlcs.push((source, payment_hash, HTLCDestination::OpenChannel { node_id: counterparty_node_id, channel_id: self.channel_id }));
56255626
},
56265627
_ => {}
56275628
}

0 commit comments

Comments
 (0)