Skip to content

Commit 4a3f21a

Browse files
committed
Send PaymentForwardedFailed for forward failures
1 parent 0675964 commit 4a3f21a

11 files changed

+209
-113
lines changed

fuzz/src/chanmon_consistency.rs

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

lightning/src/ln/chanmon_update_fail_tests.rs

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

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

838838
let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -913,7 +913,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
913913
let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_2.2).unwrap().clone();
914914
nodes[1].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update);
915915
check_added_monitors!(nodes[1], 0);
916-
expect_pending_htlcs_forwardable!(nodes[1]);
916+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
917917
check_added_monitors!(nodes[1], 1);
918918

919919
let mut events_3 = nodes[1].node.get_and_clear_pending_msg_events();
@@ -1697,7 +1697,7 @@ fn test_monitor_update_on_pending_forwards() {
16971697

16981698
let (_, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000);
16991699
nodes[2].node.fail_htlc_backwards(&payment_hash_1);
1700-
expect_pending_htlcs_forwardable!(nodes[2]);
1700+
expect_pending_htlcs_forwardable!(nodes[2], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
17011701
check_added_monitors!(nodes[2], 1);
17021702

17031703
let cs_fail_update = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
@@ -1718,7 +1718,7 @@ fn test_monitor_update_on_pending_forwards() {
17181718
commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false);
17191719

17201720
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
1721-
expect_pending_htlcs_forwardable!(nodes[1]);
1721+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
17221722
check_added_monitors!(nodes[1], 1);
17231723
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
17241724
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
@@ -2106,7 +2106,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
21062106
check_closed_broadcast!(nodes[1], true);
21072107
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
21082108
check_added_monitors!(nodes[1], 1);
2109-
expect_pending_htlcs_forwardable!(nodes[1]);
2109+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
21102110

21112111
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]);
21122112
expect_payment_sent_without_paths!(nodes[0], payment_preimage);
@@ -2469,7 +2469,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
24692469
};
24702470
if second_fails {
24712471
nodes[2].node.fail_htlc_backwards(&payment_hash);
2472-
expect_pending_htlcs_forwardable!(nodes[2]);
2472+
expect_pending_htlcs_forwardable!(nodes[2], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
24732473
check_added_monitors!(nodes[2], 1);
24742474
get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
24752475
} else {
@@ -2505,7 +2505,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
25052505

25062506
if second_fails {
25072507
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (0, 0), (1, 0), (0, 0), (0, 0), (false, false));
2508-
expect_pending_htlcs_forwardable!(nodes[1]);
2508+
expect_pending_htlcs_forwardable!(nodes[1], PaymentForwardedFailedConditions::new().payment_forwarding_failed());
25092509
} else {
25102510
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (1, 0), (0, 0), (0, 0), (0, 0), (false, false));
25112511
}

lightning/src/ln/channel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5660,7 +5660,7 @@ impl<Signer: Sign> Channel<Signer> {
56605660
/// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
56615661
/// Also returns the list of payment_hashes for channels which we can safely fail backwards
56625662
/// immediately (others we will have to allow to time out).
5663-
pub fn force_shutdown(&mut self, should_broadcast: bool) -> (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash)>) {
5663+
pub fn force_shutdown(&mut self, should_broadcast: bool) -> (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash, HTLCDestination)>) {
56645664
// Note that we MUST only generate a monitor update that indicates force-closure - we're
56655665
// called during initialization prior to the chain_monitor in the encompassing ChannelManager
56665666
// being fully configured in some cases. Thus, its likely any monitor events we generate will
@@ -5670,10 +5670,11 @@ impl<Signer: Sign> Channel<Signer> {
56705670
// We go ahead and "free" any holding cell HTLCs or HTLCs we haven't yet committed to and
56715671
// return them to fail the payment.
56725672
let mut dropped_outbound_htlcs = Vec::with_capacity(self.holding_cell_htlc_updates.len());
5673+
let counterparty_node_id = self.get_counterparty_node_id();
56735674
for htlc_update in self.holding_cell_htlc_updates.drain(..) {
56745675
match htlc_update {
56755676
HTLCUpdateAwaitingACK::AddHTLC { source, payment_hash, .. } => {
5676-
dropped_outbound_htlcs.push((source, payment_hash));
5677+
dropped_outbound_htlcs.push((source, payment_hash, HTLCDestination::OpenChannel { node_id: counterparty_node_id, channel_id: self.channel_id }));
56775678
},
56785679
_ => {}
56795680
}

0 commit comments

Comments
 (0)