Skip to content

Commit 0a2a40c

Browse files
committed
Add a PaymentClaimed event to indicate a payment was claimed
This replaces the return value of `claim_funds` with an event. It does not yet change behavior in any material way.
1 parent 28c70ac commit 0a2a40c

11 files changed

+248
-86
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,11 +842,12 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
842842
if $fail {
843843
assert!(nodes[$node].fail_htlc_backwards(&payment_hash));
844844
} else {
845-
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0)));
845+
nodes[$node].claim_funds(PaymentPreimage(payment_hash.0));
846846
}
847847
}
848848
},
849849
events::Event::PaymentSent { .. } => {},
850+
events::Event::PaymentClaimed { .. } => {},
850851
events::Event::PaymentPathSuccessful { .. } => {},
851852
events::Event::PaymentPathFailed { .. } => {},
852853
events::Event::PaymentForwarded { .. } if $node == 1 => {},

lightning/src/chain/chainmonitor.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> even
731731
mod tests {
732732
use bitcoin::BlockHeader;
733733
use ::{check_added_monitors, check_closed_broadcast, check_closed_event};
734-
use ::{expect_payment_sent, expect_payment_sent_without_paths, expect_payment_path_successful, get_event_msg};
734+
use ::{expect_payment_sent, expect_payment_claimed, expect_payment_sent_without_paths, expect_payment_path_successful, get_event_msg};
735735
use ::{get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err};
736736
use chain::{ChannelMonitorUpdateErr, Confirm, Watch};
737737
use chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS;
@@ -798,16 +798,18 @@ mod tests {
798798
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
799799

800800
// Route two payments to be claimed at the same time.
801-
let payment_preimage_1 = route_payment(&nodes[0], &[&nodes[1]], 1_000_000).0;
802-
let payment_preimage_2 = route_payment(&nodes[0], &[&nodes[1]], 1_000_000).0;
801+
let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
802+
let (payment_preimage_2, payment_hash_2, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
803803

804804
chanmon_cfgs[1].persister.offchain_monitor_updates.lock().unwrap().clear();
805805
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
806806

807807
nodes[1].node.claim_funds(payment_preimage_1);
808808
check_added_monitors!(nodes[1], 1);
809+
expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
809810
nodes[1].node.claim_funds(payment_preimage_2);
810811
check_added_monitors!(nodes[1], 1);
812+
expect_payment_claimed!(nodes[1], payment_hash_2, 1_000_000);
811813

812814
chanmon_cfgs[1].persister.set_update_ret(Ok(()));
813815

@@ -877,8 +879,9 @@ mod tests {
877879
let (route, second_payment_hash, _, second_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
878880

879881
// First route a payment that we will claim on chain and give the recipient the preimage.
880-
let payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 1_000_000).0;
882+
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
881883
nodes[1].node.claim_funds(payment_preimage);
884+
expect_payment_claimed!(nodes[1], payment_hash, 1_000_000);
882885
nodes[1].node.get_and_clear_pending_msg_events();
883886
check_added_monitors!(nodes[1], 1);
884887
let remote_txn = get_local_commitment_txn!(nodes[1], channel.2);

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn test_monitor_and_persister_update_fail() {
8989
send_payment(&nodes[0], &vec!(&nodes[1])[..], 10_000_000);
9090

9191
// Route an HTLC from node 0 to node 1 (but don't settle)
92-
let preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 9_000_000).0;
92+
let (preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 9_000_000);
9393

9494
// Make a copy of the ChainMonitor so we can capture the error it returns on a
9595
// bogus update. Note that if instead we updated the nodes[0]'s ChainMonitor
@@ -123,8 +123,10 @@ fn test_monitor_and_persister_update_fail() {
123123
persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
124124

125125
// Try to update ChannelMonitor
126-
assert!(nodes[1].node.claim_funds(preimage));
126+
nodes[1].node.claim_funds(preimage);
127+
expect_payment_claimed!(nodes[1], payment_hash, 9_000_000);
127128
check_added_monitors!(nodes[1], 1);
129+
128130
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
129131
assert_eq!(updates.update_fulfill_htlcs.len(), 1);
130132
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
@@ -267,7 +269,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
267269
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
268270
let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
269271

270-
let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
272+
let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
271273

272274
// Now try to send a second payment which will fail to send
273275
let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
@@ -283,8 +285,10 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
283285

284286
// Claim the previous payment, which will result in a update_fulfill_htlc/CS from nodes[1]
285287
// but nodes[0] won't respond since it is frozen.
286-
assert!(nodes[1].node.claim_funds(payment_preimage_1));
288+
nodes[1].node.claim_funds(payment_preimage_1);
287289
check_added_monitors!(nodes[1], 1);
290+
expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
291+
288292
let events_2 = nodes[1].node.get_and_clear_pending_msg_events();
289293
assert_eq!(events_2.len(), 1);
290294
let (bs_initial_fulfill, bs_initial_commitment_signed) = match events_2[0] {
@@ -1088,13 +1092,15 @@ fn test_monitor_update_fail_reestablish() {
10881092
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
10891093
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
10901094

1091-
let (payment_preimage, _, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000);
1095+
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000);
10921096

10931097
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
10941098
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
10951099

1096-
assert!(nodes[2].node.claim_funds(payment_preimage));
1100+
nodes[2].node.claim_funds(payment_preimage);
10971101
check_added_monitors!(nodes[2], 1);
1102+
expect_payment_claimed!(nodes[2], payment_hash, 1_000_000);
1103+
10981104
let mut updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
10991105
assert!(updates.update_add_htlcs.is_empty());
11001106
assert!(updates.update_fail_htlcs.is_empty());
@@ -1292,13 +1298,14 @@ fn claim_while_disconnected_monitor_update_fail() {
12921298
let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
12931299

12941300
// Forward a payment for B to claim
1295-
let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
1301+
let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
12961302

12971303
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
12981304
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
12991305

1300-
assert!(nodes[1].node.claim_funds(payment_preimage_1));
1306+
nodes[1].node.claim_funds(payment_preimage_1);
13011307
check_added_monitors!(nodes[1], 1);
1308+
expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
13021309

13031310
nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { features: InitFeatures::empty(), remote_network_address: None });
13041311
nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { features: InitFeatures::empty(), remote_network_address: None });
@@ -1578,10 +1585,11 @@ fn test_monitor_update_fail_claim() {
15781585
// Rebalance a bit so that we can send backwards from 3 to 2.
15791586
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000);
15801587

1581-
let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
1588+
let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
15821589

15831590
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
1584-
assert!(nodes[1].node.claim_funds(payment_preimage_1));
1591+
nodes[1].node.claim_funds(payment_preimage_1);
1592+
expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
15851593
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Temporary failure claiming HTLC, treating as success: Failed to update ChannelMonitor".to_string(), 1);
15861594
check_added_monitors!(nodes[1], 1);
15871595

@@ -1754,7 +1762,7 @@ fn monitor_update_claim_fail_no_response() {
17541762
let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
17551763

17561764
// Forward a payment for B to claim
1757-
let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
1765+
let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
17581766

17591767
// Now start forwarding a second payment, skipping the last RAA so B is in AwaitingRAA
17601768
let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
@@ -1770,8 +1778,10 @@ fn monitor_update_claim_fail_no_response() {
17701778
let as_raa = commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false, true, false, true);
17711779

17721780
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
1773-
assert!(nodes[1].node.claim_funds(payment_preimage_1));
1781+
nodes[1].node.claim_funds(payment_preimage_1);
1782+
expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
17741783
check_added_monitors!(nodes[1], 1);
1784+
17751785
let events = nodes[1].node.get_and_clear_pending_msg_events();
17761786
assert_eq!(events.len(), 0);
17771787
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Temporary failure claiming HTLC, treating as success: Failed to update ChannelMonitor".to_string(), 1);
@@ -2076,13 +2086,15 @@ fn test_fail_htlc_on_broadcast_after_claim() {
20762086
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
20772087
let chan_id_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()).2;
20782088

2079-
let payment_preimage = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 2000).0;
2089+
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 2000);
20802090

20812091
let bs_txn = get_local_commitment_txn!(nodes[2], chan_id_2);
20822092
assert_eq!(bs_txn.len(), 1);
20832093

20842094
nodes[2].node.claim_funds(payment_preimage);
20852095
check_added_monitors!(nodes[2], 1);
2096+
expect_payment_claimed!(nodes[2], payment_hash, 2000);
2097+
20862098
let cs_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
20872099
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]);
20882100
let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
@@ -2235,7 +2247,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
22352247
//
22362248
// Note that because, at the end, MonitorUpdateFailed is still set, the HTLC generated in (c)
22372249
// will not be freed from the holding cell.
2238-
let (payment_preimage_0, _, _) = route_payment(&nodes[1], &[&nodes[0]], 100000);
2250+
let (payment_preimage_0, payment_hash_0, _) = route_payment(&nodes[1], &[&nodes[0]], 100_000);
22392251

22402252
nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)).unwrap();
22412253
check_added_monitors!(nodes[0], 1);
@@ -2246,8 +2258,9 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
22462258
check_added_monitors!(nodes[0], 0);
22472259

22482260
chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
2249-
assert!(nodes[0].node.claim_funds(payment_preimage_0));
2261+
nodes[0].node.claim_funds(payment_preimage_0);
22502262
check_added_monitors!(nodes[0], 1);
2263+
expect_payment_claimed!(nodes[0], payment_hash_0, 100_000);
22512264

22522265
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send.msgs[0]);
22532266
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send.commitment_msg);
@@ -2460,8 +2473,10 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
24602473
check_added_monitors!(nodes[2], 1);
24612474
get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
24622475
} else {
2463-
assert!(nodes[2].node.claim_funds(payment_preimage));
2476+
nodes[2].node.claim_funds(payment_preimage);
24642477
check_added_monitors!(nodes[2], 1);
2478+
expect_payment_claimed!(nodes[2], payment_hash, 100_000);
2479+
24652480
let cs_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
24662481
assert_eq!(cs_updates.update_fulfill_htlcs.len(), 1);
24672482
// Check that the message we're about to deliver matches the one generated:
@@ -2630,20 +2645,22 @@ fn double_temp_error() {
26302645

26312646
let (_, _, channel_id, _) = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
26322647

2633-
let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
2634-
let (payment_preimage_2, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
2648+
let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
2649+
let (payment_preimage_2, payment_hash_2, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
26352650

26362651
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
26372652
// `claim_funds` results in a ChannelMonitorUpdate.
2638-
assert!(nodes[1].node.claim_funds(payment_preimage_1));
2653+
nodes[1].node.claim_funds(payment_preimage_1);
26392654
check_added_monitors!(nodes[1], 1);
2655+
expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
26402656
let (funding_tx, latest_update_1, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();
26412657

26422658
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
26432659
// Previously, this would've panicked due to a double-call to `Channel::monitor_update_failed`,
26442660
// which had some asserts that prevented it from being called twice.
2645-
assert!(nodes[1].node.claim_funds(payment_preimage_2));
2661+
nodes[1].node.claim_funds(payment_preimage_2);
26462662
check_added_monitors!(nodes[1], 1);
2663+
expect_payment_claimed!(nodes[1], payment_hash_2, 1_000_000);
26472664
chanmon_cfgs[1].persister.set_update_ret(Ok(()));
26482665

26492666
let (_, latest_update_2, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();

lightning/src/ln/channelmanager.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,26 +3788,29 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
37883788
/// Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
37893789
/// [`MessageSendEvent`]s needed to claim the payment.
37903790
///
3791+
/// Note that calling this method does *not* guarantee that the payment has been claimed. You
3792+
/// *must* wait for an [`Event::PaymentClaimed`] event which upon a successful claim will be
3793+
/// provided to your [`EventHandler`] when [`process_pending_events`] is next called.
3794+
///
37913795
/// Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
37923796
/// [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
37933797
/// event matches your expectation. If you fail to do so and call this method, you may provide
37943798
/// the sender "proof-of-payment" when they did not fulfill the full expected payment.
37953799
///
3796-
/// Returns whether any HTLCs were claimed, and thus if any new [`MessageSendEvent`]s are now
3797-
/// pending for processing via [`get_and_clear_pending_msg_events`].
3798-
///
37993800
/// [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
3801+
/// [`Event::PaymentClaimed`]: crate::util::events::Event::PaymentClaimed
3802+
/// [`process_pending_events`]: EventsProvider::process_pending_events
38003803
/// [`create_inbound_payment`]: Self::create_inbound_payment
38013804
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
38023805
/// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
3803-
pub fn claim_funds(&self, payment_preimage: PaymentPreimage) -> bool {
3806+
pub fn claim_funds(&self, payment_preimage: PaymentPreimage) {
38043807
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
38053808

38063809
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
38073810

38083811
let mut channel_state = Some(self.channel_state.lock().unwrap());
38093812
let removed_source = channel_state.as_mut().unwrap().claimable_htlcs.remove(&payment_hash);
3810-
if let Some((_, mut sources)) = removed_source {
3813+
if let Some((payment_purpose, mut sources)) = removed_source {
38113814
assert!(!sources.is_empty());
38123815

38133816
// If we are claiming an MPP payment, we have to take special care to ensure that each
@@ -3821,12 +3824,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
38213824
// we got all the HTLCs and then a channel closed while we were waiting for the user to
38223825
// provide the preimage, so worrying too much about the optimal handling isn't worth
38233826
// it.
3827+
let mut claimable_amt_msat = 0;
38243828
let mut valid_mpp = true;
38253829
for htlc in sources.iter() {
38263830
if let None = channel_state.as_ref().unwrap().short_to_id.get(&htlc.prev_hop.short_channel_id) {
38273831
valid_mpp = false;
38283832
break;
38293833
}
3834+
claimable_amt_msat += htlc.value;
38303835
}
38313836

38323837
let mut errs = Vec::new();
@@ -3862,6 +3867,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
38623867
}
38633868
}
38643869

3870+
if claimed_any_htlcs {
3871+
self.pending_events.lock().unwrap().push(events::Event::PaymentClaimed {
3872+
payment_hash,
3873+
purpose: payment_purpose,
3874+
amt: claimable_amt_msat,
3875+
});
3876+
}
3877+
38653878
// Now that we've done the entire above loop in one lock, we can handle any errors
38663879
// which were generated.
38673880
channel_state.take();
@@ -3870,9 +3883,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
38703883
let res: Result<(), _> = Err(err);
38713884
let _ = handle_error!(self, res, counterparty_node_id);
38723885
}
3873-
3874-
claimed_any_htlcs
3875-
} else { false }
3886+
}
38763887
}
38773888

38783889
fn claim_funds_from_hop(&self, channel_state_lock: &mut MutexGuard<ChannelHolder<Signer>>, prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage) -> ClaimFundsFromHop {
@@ -6827,7 +6838,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
68276838
for (_, monitor) in args.channel_monitors.iter() {
68286839
for (payment_hash, payment_preimage) in monitor.get_stored_preimages() {
68296840
if let Some(claimable_htlcs) = claimable_htlcs.remove(&payment_hash) {
6830-
log_info!(args.logger, "Re-claimaing HTLCs with payment hash {} due to partial-claim.", log_bytes!(payment_hash.0));
6841+
log_info!(args.logger, "Re-claiming HTLCs with payment hash {} as we've released the preimage to a ChannelMonitor!", log_bytes!(payment_hash.0));
68316842
for claimable_htlc in claimable_htlcs.1 {
68326843
// Add a holding-cell claim of the payment to the Channel, which should be
68336844
// applied ~immediately on peer reconnection. Because it won't generate a
@@ -7109,8 +7120,10 @@ mod tests {
71097120
// claim_funds_along_route because the ordering of the messages causes the second half of the
71107121
// payment to be put in the holding cell, which confuses the test utilities. So we exchange the
71117122
// lightning messages manually.
7112-
assert!(nodes[1].node.claim_funds(payment_preimage));
7123+
nodes[1].node.claim_funds(payment_preimage);
7124+
expect_payment_claimed!(nodes[1], our_payment_hash, 200_000);
71137125
check_added_monitors!(nodes[1], 2);
7126+
71147127
let bs_first_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
71157128
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_first_updates.update_fulfill_htlcs[0]);
71167129
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_updates.commitment_signed);
@@ -7556,7 +7569,8 @@ pub mod bench {
75567569

75577570
expect_pending_htlcs_forwardable!(NodeHolder { node: &$node_b });
75587571
expect_payment_received!(NodeHolder { node: &$node_b }, payment_hash, payment_secret, 10_000);
7559-
assert!($node_b.claim_funds(payment_preimage));
7572+
$node_b.claim_funds(payment_preimage);
7573+
expect_payment_claimed!(NodeHolder { node: &$node_b }, payment_hash, 10_000);
75607574

75617575
match $node_b.get_and_clear_pending_msg_events().pop().unwrap() {
75627576
MessageSendEvent::UpdateHTLCs { node_id, updates } => {

0 commit comments

Comments
 (0)