Skip to content

Commit a297bba

Browse files
committed
Add new payment type and metadata bytes
1 parent 5db1677 commit a297bba

File tree

8 files changed

+122
-34
lines changed

8 files changed

+122
-34
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ fn get_payment_secret_hash(dest: &ChanMan, payment_id: &mut u8) -> Option<(Payme
300300
let mut payment_hash;
301301
for _ in 0..256 {
302302
payment_hash = PaymentHash(Sha256::hash(&[*payment_id; 1]).into_inner());
303-
if let Ok(payment_secret) = dest.create_inbound_payment_for_hash(payment_hash, None, 3600) {
303+
if let Ok(payment_secret) = dest.create_inbound_payment_for_hash(payment_hash, None, 3600, None) {
304304
return Some((payment_secret, payment_hash));
305305
}
306306
*payment_id = payment_id.wrapping_add(1);

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
557557
let payment_hash = PaymentHash(Sha256::from_engine(sha).into_inner());
558558
// Note that this may fail - our hashes may collide and we'll end up trying to
559559
// double-register the same payment_hash.
560-
let _ = channelmanager.create_inbound_payment_for_hash(payment_hash, None, 1);
560+
let _ = channelmanager.create_inbound_payment_for_hash(payment_hash, None, 1, None);
561561
},
562562
9 => {
563563
for payment in payments_received.drain(..) {

lightning-invoice/src/utils.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ where
155155
.duration_since(UNIX_EPOCH)
156156
.expect("Time must be > 1970")
157157
.as_secs(),
158+
None,
158159
)
159160
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
160161
(payment_hash, payment_secret)
@@ -168,6 +169,7 @@ where
168169
.duration_since(UNIX_EPOCH)
169170
.expect("Time must be > 1970")
170171
.as_secs(),
172+
None,
171173
)
172174
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
173175
};
@@ -357,7 +359,7 @@ where
357359
// `create_inbound_payment` only returns an error if the amount is greater than the total bitcoin
358360
// supply.
359361
let (payment_hash, payment_secret) = channelmanager
360-
.create_inbound_payment(amt_msat, invoice_expiry_delta_secs)
362+
.create_inbound_payment(amt_msat, invoice_expiry_delta_secs, min_final_cltv_expiry_delta)
361363
.map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
362364
let our_node_pubkey = channelmanager.get_our_node_id();
363365
let channels = channelmanager.list_channels();
@@ -1128,7 +1130,7 @@ mod test {
11281130
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 2, 100000, 10001, channelmanager::provided_init_features(), channelmanager::provided_init_features());
11291131

11301132
let payment_amt = 20_000;
1131-
let (payment_hash, _payment_secret) = nodes[1].node.create_inbound_payment(Some(payment_amt), 3600).unwrap();
1133+
let (payment_hash, _payment_secret) = nodes[1].node.create_inbound_payment(Some(payment_amt), 3600, None).unwrap();
11321134
let route_hints = vec![
11331135
nodes[1].node.get_phantom_route_hints(),
11341136
nodes[2].node.get_phantom_route_hints(),

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5563,8 +5563,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
55635563
/// [`PaymentReceived`]: events::Event::PaymentReceived
55645564
/// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
55655565
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
5566-
pub fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<(PaymentHash, PaymentSecret), ()> {
5567-
inbound_payment::create(&self.inbound_payment_key, min_value_msat, invoice_expiry_delta_secs, &self.keys_manager, self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
5566+
pub fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32,
5567+
min_final_cltv_expiry_delta: Option<u32>) -> Result<(PaymentHash, PaymentSecret), ()> {
5568+
inbound_payment::create(&self.inbound_payment_key, min_value_msat, invoice_expiry_delta_secs,
5569+
&self.keys_manager, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, min_final_cltv_expiry_delta)
55685570
}
55695571

55705572
/// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
@@ -5627,8 +5629,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
56275629
///
56285630
/// [`create_inbound_payment`]: Self::create_inbound_payment
56295631
/// [`PaymentReceived`]: events::Event::PaymentReceived
5630-
pub fn create_inbound_payment_for_hash(&self, payment_hash: PaymentHash, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<PaymentSecret, ()> {
5631-
inbound_payment::create_from_hash(&self.inbound_payment_key, min_value_msat, payment_hash, invoice_expiry_delta_secs, self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
5632+
pub fn create_inbound_payment_for_hash(&self, payment_hash: PaymentHash,
5633+
min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32, min_final_cltv_expiry: Option<u32>) -> Result<PaymentSecret, ()> {
5634+
inbound_payment::create_from_hash(&self.inbound_payment_key, min_value_msat, payment_hash,
5635+
invoice_expiry_delta_secs, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, min_final_cltv_expiry)
56325636
}
56335637

56345638
/// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
@@ -8287,7 +8291,7 @@ pub mod bench {
82878291
payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes());
82888292
payment_count += 1;
82898293
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
8290-
let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200).unwrap();
8294+
let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
82918295

82928296
$node_a.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
82938297
let payment_event = SendEvent::from_event($node_a.get_and_clear_pending_msg_events().pop().unwrap());

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ macro_rules! get_payment_preimage_hash {
13431343
*payment_count += 1;
13441344
let payment_hash = $crate::ln::PaymentHash(
13451345
bitcoin::hashes::sha256::Hash::hash(&payment_preimage.0[..]).into_inner());
1346-
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200).unwrap();
1346+
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200, None).unwrap();
13471347
(payment_preimage, payment_hash, payment_secret)
13481348
}
13491349
}

lightning/src/ln/functional_tests.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
12401240
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000);
12411241

12421242
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], 800_000);
1243-
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200).unwrap();
1243+
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
12441244
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], 800_000, payment_hash, node_a_payment_secret);
12451245

12461246
// Provide preimage to node 0 by claiming payment
@@ -4723,7 +4723,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
47234723

47244724
let (our_payment_preimage, duplicate_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 900_000);
47254725

4726-
let payment_secret = nodes[3].node.create_inbound_payment_for_hash(duplicate_payment_hash, None, 7200).unwrap();
4726+
let payment_secret = nodes[3].node.create_inbound_payment_for_hash(duplicate_payment_hash, None, 7200, None).unwrap();
47274727
// We reduce the final CLTV here by a somewhat arbitrary constant to keep it under the one-byte
47284728
// script push size limit so that the below script length checks match
47294729
// ACCEPTED_HTLC_SCRIPT_WEIGHT.
@@ -4941,30 +4941,30 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
49414941
let (_, payment_hash_2, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], ds_dust_limit*1000); // not added < dust limit + HTLC tx fee
49424942
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], ds_dust_limit*1000);
49434943
// 2nd HTLC:
4944-
send_along_route_with_secret(&nodes[1], route.clone(), &[&[&nodes[2], &nodes[3], &nodes[5]]], ds_dust_limit*1000, payment_hash_1, nodes[5].node.create_inbound_payment_for_hash(payment_hash_1, None, 7200).unwrap()); // not added < dust limit + HTLC tx fee
4944+
send_along_route_with_secret(&nodes[1], route.clone(), &[&[&nodes[2], &nodes[3], &nodes[5]]], ds_dust_limit*1000, payment_hash_1, nodes[5].node.create_inbound_payment_for_hash(payment_hash_1, None, 7200, None).unwrap()); // not added < dust limit + HTLC tx fee
49454945
// 3rd HTLC:
4946-
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], ds_dust_limit*1000, payment_hash_2, nodes[5].node.create_inbound_payment_for_hash(payment_hash_2, None, 7200).unwrap()); // not added < dust limit + HTLC tx fee
4946+
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], ds_dust_limit*1000, payment_hash_2, nodes[5].node.create_inbound_payment_for_hash(payment_hash_2, None, 7200, None).unwrap()); // not added < dust limit + HTLC tx fee
49474947
// 4th HTLC:
49484948
let (_, payment_hash_3, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 1000000);
49494949
// 5th HTLC:
49504950
let (_, payment_hash_4, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 1000000);
49514951
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], 1000000);
49524952
// 6th HTLC:
4953-
send_along_route_with_secret(&nodes[1], route.clone(), &[&[&nodes[2], &nodes[3], &nodes[5]]], 1000000, payment_hash_3, nodes[5].node.create_inbound_payment_for_hash(payment_hash_3, None, 7200).unwrap());
4953+
send_along_route_with_secret(&nodes[1], route.clone(), &[&[&nodes[2], &nodes[3], &nodes[5]]], 1000000, payment_hash_3, nodes[5].node.create_inbound_payment_for_hash(payment_hash_3, None, 7200, None).unwrap());
49544954
// 7th HTLC:
4955-
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], 1000000, payment_hash_4, nodes[5].node.create_inbound_payment_for_hash(payment_hash_4, None, 7200).unwrap());
4955+
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], 1000000, payment_hash_4, nodes[5].node.create_inbound_payment_for_hash(payment_hash_4, None, 7200, None).unwrap());
49564956

49574957
// 8th HTLC:
49584958
let (_, payment_hash_5, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 1000000);
49594959
// 9th HTLC:
49604960
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], ds_dust_limit*1000);
4961-
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], ds_dust_limit*1000, payment_hash_5, nodes[5].node.create_inbound_payment_for_hash(payment_hash_5, None, 7200).unwrap()); // not added < dust limit + HTLC tx fee
4961+
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], ds_dust_limit*1000, payment_hash_5, nodes[5].node.create_inbound_payment_for_hash(payment_hash_5, None, 7200, None).unwrap()); // not added < dust limit + HTLC tx fee
49624962

49634963
// 10th HTLC:
49644964
let (_, payment_hash_6, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], ds_dust_limit*1000); // not added < dust limit + HTLC tx fee
49654965
// 11th HTLC:
49664966
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], 1000000);
4967-
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], 1000000, payment_hash_6, nodes[5].node.create_inbound_payment_for_hash(payment_hash_6, None, 7200).unwrap());
4967+
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[2], &nodes[3], &nodes[5]]], 1000000, payment_hash_6, nodes[5].node.create_inbound_payment_for_hash(payment_hash_6, None, 7200, None).unwrap());
49684968

49694969
// Double-check that six of the new HTLC were added
49704970
// We now have six HTLCs pending over the dust limit and six HTLCs under the dust limit (ie,
@@ -6932,7 +6932,7 @@ fn test_check_htlc_underpaying() {
69326932
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id()).with_features(channelmanager::provided_invoice_features());
69336933
let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), None, 10_000, TEST_FINAL_CLTV, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
69346934
let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
6935-
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200).unwrap();
6935+
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200, None).unwrap();
69366936
nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap();
69376937
check_added_monitors!(nodes[0], 1);
69386938

@@ -7935,7 +7935,7 @@ fn test_preimage_storage() {
79357935
create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
79367936

79377937
{
7938-
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 7200).unwrap();
7938+
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 7200, None).unwrap();
79397939
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
79407940
nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
79417941
check_added_monitors!(nodes[0], 1);
@@ -8041,7 +8041,7 @@ fn test_bad_secret_hash() {
80418041

80428042
let random_payment_hash = PaymentHash([42; 32]);
80438043
let random_payment_secret = PaymentSecret([43; 32]);
8044-
let (our_payment_hash, our_payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 2).unwrap();
8044+
let (our_payment_hash, our_payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 2, None).unwrap();
80458045
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
80468046

80478047
// All the below cases should end up being handled exactly identically, so we macro the

0 commit comments

Comments
 (0)