Skip to content

Commit fb91bb3

Browse files
committed
Drop now-useless PaymentSecret parameters when claiming/failing-back
1 parent 892fa2b commit fb91bb3

File tree

6 files changed

+61
-66
lines changed

6 files changed

+61
-66
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn test_monitor_and_persister_update_fail() {
120120
persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
121121

122122
// Try to update ChannelMonitor
123-
assert!(nodes[1].node.claim_funds(preimage, &None, 9_000_000));
123+
assert!(nodes[1].node.claim_funds(preimage, 9_000_000));
124124
check_added_monitors!(nodes[1], 1);
125125
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
126126
assert_eq!(updates.update_fulfill_htlcs.len(), 1);
@@ -304,7 +304,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
304304

305305
// Claim the previous payment, which will result in a update_fulfill_htlc/CS from nodes[1]
306306
// but nodes[0] won't respond since it is frozen.
307-
assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000));
307+
assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000));
308308
check_added_monitors!(nodes[1], 1);
309309
let events_2 = nodes[1].node.get_and_clear_pending_msg_events();
310310
assert_eq!(events_2.len(), 1);
@@ -845,7 +845,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
845845
let (_, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000);
846846

847847
// Fail the payment backwards, failing the monitor update on nodes[1]'s receipt of the RAA
848-
assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1, &None));
848+
assert!(nodes[2].node.fail_htlc_backwards(&payment_hash_1));
849849
expect_pending_htlcs_forwardable!(nodes[2]);
850850
check_added_monitors!(nodes[2], 1);
851851

@@ -1107,7 +1107,7 @@ fn test_monitor_update_fail_reestablish() {
11071107
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
11081108
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
11091109

1110-
assert!(nodes[2].node.claim_funds(our_payment_preimage, &None, 1_000_000));
1110+
assert!(nodes[2].node.claim_funds(our_payment_preimage, 1_000_000));
11111111
check_added_monitors!(nodes[2], 1);
11121112
let mut updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
11131113
assert!(updates.update_add_htlcs.is_empty());
@@ -1314,7 +1314,7 @@ fn claim_while_disconnected_monitor_update_fail() {
13141314
nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
13151315
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
13161316

1317-
assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000));
1317+
assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000));
13181318
check_added_monitors!(nodes[1], 1);
13191319

13201320
nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { features: InitFeatures::empty() });
@@ -1610,7 +1610,7 @@ fn test_monitor_update_fail_claim() {
16101610
let (payment_preimage_1, _, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
16111611

16121612
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure));
1613-
assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000));
1613+
assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000));
16141614
check_added_monitors!(nodes[1], 1);
16151615

16161616
let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[0]);
@@ -1689,7 +1689,7 @@ fn test_monitor_update_on_pending_forwards() {
16891689
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
16901690

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

@@ -1776,7 +1776,7 @@ fn monitor_update_claim_fail_no_response() {
17761776
let as_raa = commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false, true, false, true);
17771777

17781778
*nodes[1].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure));
1779-
assert!(nodes[1].node.claim_funds(payment_preimage_1, &None, 1_000_000));
1779+
assert!(nodes[1].node.claim_funds(payment_preimage_1, 1_000_000));
17801780
check_added_monitors!(nodes[1], 1);
17811781
let events = nodes[1].node.get_and_clear_pending_msg_events();
17821782
assert_eq!(events.len(), 0);

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
20862086
/// along the path (including in our own channel on which we received it).
20872087
/// Returns false if no payment was found to fail backwards, true if the process of failing the
20882088
/// HTLC backwards has been started.
2089-
pub fn fail_htlc_backwards(&self, payment_hash: &PaymentHash, _payment_secret: &Option<PaymentSecret>) -> bool {
2089+
pub fn fail_htlc_backwards(&self, payment_hash: &PaymentHash) -> bool {
20902090
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
20912091

20922092
let mut channel_state = Some(self.channel_state.lock().unwrap());
@@ -2255,18 +2255,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22552255
/// generating message events for the net layer to claim the payment, if possible. Thus, you
22562256
/// should probably kick the net layer to go send messages if this returns true!
22572257
///
2258-
/// You must specify the expected amounts for this HTLC, and we will only claim HTLCs
2259-
/// available within a few percent of the expected amount. This is critical for several
2260-
/// reasons : a) it avoids providing senders with `proof-of-payment` (in the form of the
2261-
/// payment_preimage without having provided the full value and b) it avoids certain
2262-
/// privacy-breaking recipient-probing attacks which may reveal payment activity to
2263-
/// motivated attackers.
2264-
///
2265-
/// Note that the privacy concerns in (b) are not relevant in payments with a payment_secret
2266-
/// set. Thus, for such payments we will claim any payments which do not under-pay.
2258+
/// Note that if you did not set an `amount_msat` when calling [`get_payment_secret`] or
2259+
/// [`get_payment_secret_preimage`] you must check that the amount in the `PaymentReceived`
2260+
/// event matches your expectation. If you fail to do so and call this method, you may provide
2261+
/// the sender "proof-of-payment" when they did not fulfill the full expected payment.
22672262
///
22682263
/// May panic if called except in response to a PaymentReceived event.
2269-
pub fn claim_funds(&self, payment_preimage: PaymentPreimage, _payment_secret: &Option<PaymentSecret>, expected_amount: u64) -> bool {
2264+
pub fn claim_funds(&self, payment_preimage: PaymentPreimage, expected_amount: u64) -> bool {
22702265
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
22712266

22722267
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, exp
10521052
for path in expected_paths.iter() {
10531053
assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
10541054
}
1055-
assert!(expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage, &None, expected_amount));
1055+
assert!(expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage, expected_amount));
10561056
check_added_monitors!(expected_paths[0].last().unwrap(), expected_paths.len());
10571057

10581058
macro_rules! msgs_from_ev {
@@ -1176,7 +1176,7 @@ pub fn send_payment<'a, 'b, 'c>(origin: &Node<'a, 'b, 'c>, expected_route: &[&No
11761176
}
11771177

11781178
pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_hash: PaymentHash) {
1179-
assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash, &None));
1179+
assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash));
11801180
expect_pending_htlcs_forwardable!(expected_route.last().unwrap());
11811181
check_added_monitors!(expected_route.last().unwrap(), 1);
11821182

0 commit comments

Comments
 (0)