Skip to content

Commit 22a83d2

Browse files
committed
Drop the amount parameter to claim_funds
Like the payment_secret parameter, this paramter has been the source of much confusion, so we just drop it. Users should prefer to do this check when registering the payment secret instead of at claim-time.
1 parent 64639f3 commit 22a83d2

File tree

8 files changed

+180
-170
lines changed

8 files changed

+180
-170
lines changed

lightning-persister/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ mod tests {
251251
check_persisted_data!(0);
252252

253253
// Send a few payments and make sure the monitors are updated to the latest.
254-
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000);
254+
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
255255
check_persisted_data!(5);
256-
send_payment(&nodes[1], &vec!(&nodes[0])[..], 4000000, 4_000_000);
256+
send_payment(&nodes[1], &vec!(&nodes[0])[..], 4000000);
257257
check_persisted_data!(10);
258258

259259
// Force close because cooperative close doesn't result in any persisted

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ mod tests {
379379
let (commitment_tx, htlc_tx) = {
380380
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 5_000_000).0;
381381
let mut txn = get_local_commitment_txn!(nodes[0], channel.2);
382-
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage, 5_000_000);
382+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
383383

384384
assert_eq!(txn.len(), 2);
385385
(txn.remove(0), txn.remove(0))

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn test_monitor_and_persister_update_fail() {
8989
let outpoint = OutPoint { txid: chan.3.txid(), index: 0 };
9090

9191
// Rebalance the network to generate htlc in the two directions
92-
send_payment(&nodes[0], &vec!(&nodes[1])[..], 10_000_000, 10_000_000);
92+
send_payment(&nodes[0], &vec!(&nodes[1])[..], 10_000_000);
9393

9494
// Route an HTLC from node 0 to node 1 (but don't settle)
9595
let preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 9_000_000).0;
@@ -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));
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);
@@ -213,7 +213,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail
213213
_ => panic!("Unexpected event"),
214214
}
215215

216-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1, 1_000_000);
216+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
217217

218218
// Now set it to failed again...
219219
let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(&nodes[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));
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);
@@ -581,7 +581,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
581581
_ => panic!("Unexpected event"),
582582
}
583583

584-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2, 1_000_000);
584+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
585585
}
586586

587587
#[test]
@@ -695,7 +695,7 @@ fn test_monitor_update_fail_cs() {
695695
_ => panic!("Unexpected event"),
696696
};
697697

698-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage, 1_000_000);
698+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
699699
}
700700

701701
#[test]
@@ -746,7 +746,7 @@ fn test_monitor_update_fail_no_rebroadcast() {
746746
_ => panic!("Unexpected event"),
747747
}
748748

749-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1, 1_000_000);
749+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
750750
}
751751

752752
#[test]
@@ -760,7 +760,7 @@ fn test_monitor_update_raa_while_paused() {
760760
let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
761761
let logger = test_utils::TestLogger::new();
762762

763-
send_payment(&nodes[0], &[&nodes[1]], 5000000, 5_000_000);
763+
send_payment(&nodes[0], &[&nodes[1]], 5000000);
764764
let (payment_preimage_1, our_payment_hash_1, our_payment_secret_1) = get_payment_preimage_hash!(nodes[1]);
765765
{
766766
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
@@ -824,8 +824,8 @@ fn test_monitor_update_raa_while_paused() {
824824
expect_pending_htlcs_forwardable!(nodes[1]);
825825
expect_payment_received!(nodes[1], our_payment_hash_1, our_payment_secret_1, 1000000);
826826

827-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1, 1_000_000);
828-
claim_payment(&nodes[1], &[&nodes[0]], payment_preimage_2, 1_000_000);
827+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
828+
claim_payment(&nodes[1], &[&nodes[0]], payment_preimage_2);
829829
}
830830

831831
fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
@@ -839,13 +839,13 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
839839
let logger = test_utils::TestLogger::new();
840840

841841
// Rebalance a bit so that we can send backwards from 2 to 1.
842-
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
842+
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000);
843843

844844
// Route a first payment that we'll fail backwards
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

@@ -1078,10 +1078,10 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
10781078
Event::PaymentReceived { payment_hash, .. } => assert_eq!(payment_hash, payment_hash_4.unwrap()),
10791079
_ => panic!("Unexpected event"),
10801080
};
1081-
claim_payment(&nodes[2], &[&nodes[1], &nodes[0]], payment_preimage_4.unwrap(), 1_000_000);
1081+
claim_payment(&nodes[2], &[&nodes[1], &nodes[0]], payment_preimage_4.unwrap());
10821082
}
10831083

1084-
claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage_2, 1_000_000);
1084+
claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage_2);
10851085
}
10861086

10871087
#[test]
@@ -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));
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());
@@ -1288,9 +1288,9 @@ fn raa_no_response_awaiting_raa_state() {
12881288
expect_pending_htlcs_forwardable!(nodes[1]);
12891289
expect_payment_received!(nodes[1], payment_hash_3, payment_secret_3, 1000000);
12901290

1291-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1, 1_000_000);
1292-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2, 1_000_000);
1293-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_3, 1_000_000);
1291+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
1292+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
1293+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_3);
12941294
}
12951295

12961296
#[test]
@@ -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));
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() });
@@ -1416,7 +1416,7 @@ fn claim_while_disconnected_monitor_update_fail() {
14161416
_ => panic!("Unexpected event"),
14171417
}
14181418

1419-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2, 1_000_000);
1419+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
14201420
}
14211421

14221422
#[test]
@@ -1484,7 +1484,7 @@ fn monitor_failed_no_reestablish_response() {
14841484
expect_pending_htlcs_forwardable!(nodes[1]);
14851485
expect_payment_received!(nodes[1], payment_hash_1, payment_secret_1, 1000000);
14861486

1487-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1, 1_000_000);
1487+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
14881488
}
14891489

14901490
#[test]
@@ -1585,8 +1585,8 @@ fn first_message_on_recv_ordering() {
15851585
expect_pending_htlcs_forwardable!(nodes[1]);
15861586
expect_payment_received!(nodes[1], payment_hash_2, payment_secret_2, 1000000);
15871587

1588-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1, 1_000_000);
1589-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2, 1_000_000);
1588+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
1589+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
15901590
}
15911591

15921592
#[test]
@@ -1605,12 +1605,12 @@ fn test_monitor_update_fail_claim() {
16051605
let logger = test_utils::TestLogger::new();
16061606

16071607
// Rebalance a bit so that we can send backwards from 3 to 2.
1608-
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
1608+
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000);
16091609

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));
16141614
check_added_monitors!(nodes[1], 1);
16151615

16161616
let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[0]);
@@ -1686,10 +1686,10 @@ fn test_monitor_update_on_pending_forwards() {
16861686
let logger = test_utils::TestLogger::new();
16871687

16881688
// Rebalance a bit so that we can send backwards from 3 to 1.
1689-
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
1689+
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000);
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

@@ -1741,7 +1741,7 @@ fn test_monitor_update_on_pending_forwards() {
17411741
nodes[0].node.process_pending_htlc_forwards();
17421742
expect_payment_received!(nodes[0], payment_hash_2, payment_secret_2, 1000000);
17431743

1744-
claim_payment(&nodes[2], &[&nodes[1], &nodes[0]], payment_preimage_2, 1_000_000);
1744+
claim_payment(&nodes[2], &[&nodes[1], &nodes[0]], payment_preimage_2);
17451745
}
17461746

17471747
#[test]
@@ -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));
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);
@@ -1806,7 +1806,7 @@ fn monitor_update_claim_fail_no_response() {
18061806
_ => panic!("Unexpected event"),
18071807
}
18081808

1809-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2, 1_000_000);
1809+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
18101810
}
18111811

18121812
// confirm_a_first and restore_b_before_conf are wholly unrelated to earlier bools and
@@ -1896,7 +1896,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
18961896
node.net_graph_msg_handler.handle_channel_update(&bs_update).unwrap();
18971897
}
18981898

1899-
send_payment(&nodes[0], &[&nodes[1]], 8000000, 8_000_000);
1899+
send_payment(&nodes[0], &[&nodes[1]], 8000000);
19001900
close_channel(&nodes[0], &nodes[1], &channel_id, funding_tx, true);
19011901
}
19021902

@@ -1964,5 +1964,5 @@ fn test_path_paused_mpp() {
19641964
assert_eq!(events.len(), 1);
19651965
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), payment_secret, events.pop().unwrap(), true);
19661966

1967-
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage, 200_000);
1967+
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
19681968
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22512251
/// the sender "proof-of-payment" when they did not fulfill the full expected payment.
22522252
///
22532253
/// May panic if called except in response to a PaymentReceived event.
2254-
pub fn claim_funds(&self, payment_preimage: PaymentPreimage, expected_amount: u64) -> bool {
2254+
pub fn claim_funds(&self, payment_preimage: PaymentPreimage) -> bool {
22552255
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
22562256

22572257
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
@@ -2272,7 +2272,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22722272
// we got all the HTLCs and then a channel closed while we were waiting for the user to
22732273
// provide the preimage, so worrying too much about the optimal handling isn't worth
22742274
// it.
2275-
let mut valid_mpp = sources[0].payment_data.total_msat >= expected_amount;
2275+
let mut valid_mpp = true;
22762276
for htlc in sources.iter() {
22772277
if !valid_mpp { break; }
22782278
if let None = channel_state.as_ref().unwrap().short_to_id.get(&htlc.prev_hop.short_channel_id) {

lightning/src/ln/functional_test_utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,11 +1048,11 @@ pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route
10481048
(our_payment_preimage, our_payment_hash, our_payment_secret)
10491049
}
10501050

1051-
pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_preimage: PaymentPreimage, expected_amount: u64) {
1051+
pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_preimage: PaymentPreimage) {
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));
10561056
check_added_monitors!(expected_paths[0].last().unwrap(), expected_paths.len());
10571057

10581058
macro_rules! msgs_from_ev {
@@ -1136,8 +1136,8 @@ pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, exp
11361136
}
11371137
}
11381138

1139-
pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage, expected_amount: u64) {
1140-
claim_payment_along_route(origin_node, &[expected_route], false, our_payment_preimage, expected_amount);
1139+
pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage) {
1140+
claim_payment_along_route(origin_node, &[expected_route], false, our_payment_preimage);
11411141
}
11421142

11431143
pub const TEST_FINAL_CLTV: u32 = 50;
@@ -1170,9 +1170,9 @@ pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_rou
11701170
assert!(err.contains("Cannot send value that would put us over the max HTLC value in flight our peer will accept")));
11711171
}
11721172

1173-
pub fn send_payment<'a, 'b, 'c>(origin: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64, expected_value: u64) {
1173+
pub fn send_payment<'a, 'b, 'c>(origin: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
11741174
let our_payment_preimage = route_payment(&origin, expected_route, recv_value).0;
1175-
claim_payment(&origin, expected_route, our_payment_preimage, expected_value);
1175+
claim_payment(&origin, expected_route, our_payment_preimage);
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) {

0 commit comments

Comments
 (0)