Skip to content

Commit ea4b279

Browse files
committed
Drop now-useless PaymentSecret parameters when claiming/failing-back
1 parent 4a6f42e commit ea4b279

File tree

8 files changed

+72
-77
lines changed

8 files changed

+72
-77
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
686686
let had_events = !events.is_empty();
687687
for event in events.drain(..) {
688688
match event {
689-
events::Event::PaymentReceived { payment_hash, payment_secret, amt, user_payment_id: _ } => {
689+
events::Event::PaymentReceived { payment_hash, payment_secret: _, amt, user_payment_id: _ } => {
690690
if claim_set.insert(payment_hash.0) {
691691
if $fail {
692-
assert!(nodes[$node].fail_htlc_backwards(&payment_hash, &payment_secret));
692+
assert!(nodes[$node].fail_htlc_backwards(&payment_hash));
693693
} else {
694-
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), &payment_secret, amt));
694+
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0), amt));
695695
}
696696
}
697697
},

fuzz/src/full_stack.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
370370
}, our_network_key, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0], Arc::clone(&logger)));
371371

372372
let mut should_forward = false;
373-
let mut payments_received: Vec<(PaymentHash, Option<PaymentSecret>, u64)> = Vec::new();
373+
let mut payments_received: Vec<(PaymentHash, u64)> = Vec::new();
374374
let mut payments_sent = 0;
375375
let mut pending_funding_generation: Vec<([u8; 32], u64, Script)> = Vec::new();
376376
let mut pending_funding_signatures = HashMap::new();
@@ -475,23 +475,23 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
475475
}
476476
},
477477
8 => {
478-
for (payment, payment_secret, amt) in payments_received.drain(..) {
478+
for (payment, amt) in payments_received.drain(..) {
479479
// SHA256 is defined as XOR of all input bytes placed in the first byte, and 0s
480480
// for the remaining bytes. Thus, if not all remaining bytes are 0s we cannot
481481
// fulfill this HTLC, but if they are, we can just take the first byte and
482482
// place that anywhere in our preimage.
483483
if &payment.0[1..] != &[0; 31] {
484-
channelmanager.fail_htlc_backwards(&payment, &payment_secret);
484+
channelmanager.fail_htlc_backwards(&payment);
485485
} else {
486486
let mut payment_preimage = PaymentPreimage([0; 32]);
487487
payment_preimage.0[0] = payment.0[0];
488-
channelmanager.claim_funds(payment_preimage, &payment_secret, amt);
488+
channelmanager.claim_funds(payment_preimage, amt);
489489
}
490490
}
491491
},
492492
9 => {
493-
for (payment, payment_secret, _) in payments_received.drain(..) {
494-
channelmanager.fail_htlc_backwards(&payment, &payment_secret);
493+
for (payment, _) in payments_received.drain(..) {
494+
channelmanager.fail_htlc_backwards(&payment);
495495
}
496496
},
497497
10 => {
@@ -570,9 +570,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
570570
Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, output_script, .. } => {
571571
pending_funding_generation.push((temporary_channel_id, channel_value_satoshis, output_script));
572572
},
573-
Event::PaymentReceived { payment_hash, payment_secret, amt, user_payment_id: _ } => {
573+
Event::PaymentReceived { payment_hash, payment_secret: _, amt, user_payment_id: _ } => {
574574
//TODO: enhance by fetching random amounts from fuzz input?
575-
payments_received.push((payment_hash, payment_secret, amt));
575+
payments_received.push((payment_hash, amt));
576576
},
577577
Event::PaymentSent {..} => {},
578578
Event::PaymentFailed {..} => {},

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)