Skip to content

Commit abe26d6

Browse files
committed
Drop now-useless PaymentSecret parameters when claiming/failing-back
1 parent 640f030 commit abe26d6

File tree

8 files changed

+76
-78
lines changed

8 files changed

+76
-78
lines changed

fuzz/src/chanmon_consistency.rs

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

fuzz/src/full_stack.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
371371
}, 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)));
372372

373373
let mut should_forward = false;
374-
let mut payments_received: Vec<(PaymentHash, Option<PaymentSecret>, u64)> = Vec::new();
374+
let mut payments_received: Vec<(PaymentHash, u64)> = Vec::new();
375375
let mut payments_sent = 0;
376376
let mut pending_funding_generation: Vec<([u8; 32], u64, Script)> = Vec::new();
377377
let mut pending_funding_signatures = HashMap::new();
@@ -476,23 +476,23 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
476476
}
477477
},
478478
8 => {
479-
for (payment, payment_secret, amt) in payments_received.drain(..) {
479+
for (payment, amt) in payments_received.drain(..) {
480480
// SHA256 is defined as XOR of all input bytes placed in the first byte, and 0s
481481
// for the remaining bytes. Thus, if not all remaining bytes are 0s we cannot
482482
// fulfill this HTLC, but if they are, we can just take the first byte and
483483
// place that anywhere in our preimage.
484484
if &payment.0[1..] != &[0; 31] {
485-
channelmanager.fail_htlc_backwards(&payment, &payment_secret);
485+
channelmanager.fail_htlc_backwards(&payment);
486486
} else {
487487
let mut payment_preimage = PaymentPreimage([0; 32]);
488488
payment_preimage.0[0] = payment.0[0];
489-
channelmanager.claim_funds(payment_preimage, &payment_secret, amt);
489+
channelmanager.claim_funds(payment_preimage, amt);
490490
}
491491
}
492492
},
493493
9 => {
494-
for (payment, payment_secret, _) in payments_received.drain(..) {
495-
channelmanager.fail_htlc_backwards(&payment, &payment_secret);
494+
for (payment, _) in payments_received.drain(..) {
495+
channelmanager.fail_htlc_backwards(&payment);
496496
}
497497
},
498498
10 => {
@@ -571,9 +571,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
571571
Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, output_script, .. } => {
572572
pending_funding_generation.push((temporary_channel_id, channel_value_satoshis, output_script));
573573
},
574-
Event::PaymentReceived { payment_hash, payment_secret, amt, user_payment_id: _ } => {
574+
Event::PaymentReceived { payment_hash, payment_secret: _, amt, user_payment_id: _ } => {
575575
//TODO: enhance by fetching random amounts from fuzz input?
576-
payments_received.push((payment_hash, payment_secret, amt));
576+
payments_received.push((payment_hash, amt));
577577
},
578578
Event::PaymentSent {..} => {},
579579
Event::PaymentFailed {..} => {},

lightning/src/ln/chanmon_update_fail_tests.rs

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

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

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

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

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

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

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

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

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

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

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

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

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

lightning/src/ln/channelmanager.rs

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

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

22972295
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
@@ -4832,7 +4830,7 @@ pub mod bench {
48324830

48334831
expect_pending_htlcs_forwardable!(NodeHolder { node: &$node_b });
48344832
expect_payment_received!(NodeHolder { node: &$node_b }, payment_hash, payment_secret, 10_000);
4835-
assert!($node_b.claim_funds(payment_preimage, &Some(payment_secret), 10_000));
4833+
assert!($node_b.claim_funds(payment_preimage, 10_000));
48364834

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

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)