Skip to content

Commit c2fe4d0

Browse files
committed
Add new payment type and metadata bytes
Adds two new payment `Method`s for identifying payments with custom `min_final_cltv_expiry_delta` as payments with LDK or user payment hashes. The `min_final_cltv_expiry_delta` value is packed into the first 2 bytes of the expiry timestamp in the payment secret metadata.
1 parent ff1a3da commit c2fe4d0

File tree

9 files changed

+229
-41
lines changed

9 files changed

+229
-41
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ fn get_payment_secret_hash(dest: &ChanMan, payment_id: &mut u8) -> Option<(Payme
340340
let mut payment_hash;
341341
for _ in 0..256 {
342342
payment_hash = PaymentHash(Sha256::hash(&[*payment_id; 1]).into_inner());
343-
if let Ok(payment_secret) = dest.create_inbound_payment_for_hash(payment_hash, None, 3600) {
343+
if let Ok(payment_secret) = dest.create_inbound_payment_for_hash(payment_hash, None, 3600, None) {
344344
return Some((payment_secret, payment_hash));
345345
}
346346
*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
@@ -605,7 +605,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
605605
let payment_hash = PaymentHash(Sha256::from_engine(sha).into_inner());
606606
// Note that this may fail - our hashes may collide and we'll end up trying to
607607
// double-register the same payment_hash.
608-
let _ = channelmanager.create_inbound_payment_for_hash(payment_hash, None, 1);
608+
let _ = channelmanager.create_inbound_payment_for_hash(payment_hash, None, 1, None);
609609
},
610610
9 => {
611611
for payment in payments_received.drain(..) {

lightning-invoice/src/utils.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ where
166166
.duration_since(UNIX_EPOCH)
167167
.expect("Time must be > 1970")
168168
.as_secs(),
169+
min_final_cltv_expiry_delta,
169170
)
170171
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
171172
(payment_hash, payment_secret)
@@ -179,6 +180,7 @@ where
179180
.duration_since(UNIX_EPOCH)
180181
.expect("Time must be > 1970")
181182
.as_secs(),
183+
min_final_cltv_expiry_delta,
182184
)
183185
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
184186
};
@@ -397,7 +399,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T: Der
397399
// `create_inbound_payment` only returns an error if the amount is greater than the total bitcoin
398400
// supply.
399401
let (payment_hash, payment_secret) = channelmanager
400-
.create_inbound_payment(amt_msat, invoice_expiry_delta_secs)
402+
.create_inbound_payment(amt_msat, invoice_expiry_delta_secs, min_final_cltv_expiry_delta)
401403
.map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
402404
_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
403405
channelmanager, node_signer, logger, network, amt_msat, description, duration_since_epoch,
@@ -424,7 +426,8 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_
424426
L::Target: Logger,
425427
{
426428
let payment_secret = channelmanager
427-
.create_inbound_payment_for_hash(payment_hash,amt_msat, invoice_expiry_delta_secs)
429+
.create_inbound_payment_for_hash(payment_hash, amt_msat, invoice_expiry_delta_secs,
430+
min_final_cltv_expiry_delta)
428431
.map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
429432
_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
430433
channelmanager, node_signer, logger, network, amt_msat,
@@ -1170,7 +1173,7 @@ mod test {
11701173
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 2, 100000, 10001);
11711174

11721175
let payment_amt = 20_000;
1173-
let (payment_hash, _payment_secret) = nodes[1].node.create_inbound_payment(Some(payment_amt), 3600).unwrap();
1176+
let (payment_hash, _payment_secret) = nodes[1].node.create_inbound_payment(Some(payment_amt), 3600, None).unwrap();
11741177
let route_hints = vec![
11751178
nodes[1].node.get_phantom_route_hints(),
11761179
nodes[2].node.get_phantom_route_hints(),

lightning/src/ln/channelmanager.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,7 @@ where
19141914
// final_expiry_too_soon
19151915
// We have to have some headroom to broadcast on chain if we have the preimage, so make sure
19161916
// we have at least HTLC_FAIL_BACK_BUFFER blocks to go.
1917+
//
19171918
// Also, ensure that, in the case of an unknown preimage for the received payment hash, our
19181919
// payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
19191920
// channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
@@ -3184,10 +3185,21 @@ where
31843185
let payment_preimage = match inbound_payment::verify(payment_hash, &payment_data, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, &self.logger) {
31853186
Ok(payment_preimage) => payment_preimage,
31863187
Err(()) => {
3188+
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", log_bytes!(payment_hash.0));
31873189
fail_htlc!(claimable_htlc, payment_hash);
31883190
continue
31893191
}
31903192
};
3193+
if let Some(min_final_cltv_expiry_delta) = inbound_payment::get_custom_min_final_cltv_expiry_delta(
3194+
payment_data.payment_secret, &self.inbound_payment_key) {
3195+
let expected_min_expiry_height = (self.current_best_block().height() + min_final_cltv_expiry_delta as u32) as u64;
3196+
if (cltv_expiry as u64) < expected_min_expiry_height {
3197+
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as its CLTV expiry was too soon (had {}, earliest expected {})",
3198+
log_bytes!(payment_hash.0), cltv_expiry, expected_min_expiry_height);
3199+
fail_htlc!(claimable_htlc, payment_hash);
3200+
continue;
3201+
}
3202+
}
31913203
check_total_value!(payment_data, payment_preimage);
31923204
},
31933205
OnionPayload::Spontaneous(preimage) => {
@@ -5273,12 +5285,18 @@ where
52735285
///
52745286
/// Errors if `min_value_msat` is greater than total bitcoin supply.
52755287
///
5288+
/// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
5289+
/// on versions of LDK prior to 0.0.114.
5290+
///
52765291
/// [`claim_funds`]: Self::claim_funds
52775292
/// [`PaymentClaimable`]: events::Event::PaymentClaimable
52785293
/// [`PaymentClaimable::payment_preimage`]: events::Event::PaymentClaimable::payment_preimage
52795294
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
5280-
pub fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<(PaymentHash, PaymentSecret), ()> {
5281-
inbound_payment::create(&self.inbound_payment_key, min_value_msat, invoice_expiry_delta_secs, &self.entropy_source, self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
5295+
pub fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32,
5296+
min_final_cltv_expiry_delta: Option<u16>) -> Result<(PaymentHash, PaymentSecret), ()> {
5297+
inbound_payment::create(&self.inbound_payment_key, min_value_msat, invoice_expiry_delta_secs,
5298+
&self.entropy_source, self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
5299+
min_final_cltv_expiry_delta)
52825300
}
52835301

52845302
/// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
@@ -5339,10 +5357,16 @@ where
53395357
///
53405358
/// Errors if `min_value_msat` is greater than total bitcoin supply.
53415359
///
5360+
/// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
5361+
/// on versions of LDK prior to 0.0.114.
5362+
///
53425363
/// [`create_inbound_payment`]: Self::create_inbound_payment
53435364
/// [`PaymentClaimable`]: events::Event::PaymentClaimable
5344-
pub fn create_inbound_payment_for_hash(&self, payment_hash: PaymentHash, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<PaymentSecret, ()> {
5345-
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)
5365+
pub fn create_inbound_payment_for_hash(&self, payment_hash: PaymentHash, min_value_msat: Option<u64>,
5366+
invoice_expiry_delta_secs: u32, min_final_cltv_expiry: Option<u16>) -> Result<PaymentSecret, ()> {
5367+
inbound_payment::create_from_hash(&self.inbound_payment_key, min_value_msat, payment_hash,
5368+
invoice_expiry_delta_secs, self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
5369+
min_final_cltv_expiry)
53465370
}
53475371

53485372
/// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
@@ -8505,7 +8529,7 @@ pub mod bench {
85058529
payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes());
85068530
payment_count += 1;
85078531
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
8508-
let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200).unwrap();
8532+
let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
85098533

85108534
$node_a.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
85118535
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,17 +1447,22 @@ macro_rules! get_payment_preimage_hash {
14471447
}
14481448
};
14491449
($dest_node: expr, $min_value_msat: expr) => {
1450+
{
1451+
crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
1452+
}
1453+
};
1454+
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
14501455
{
14511456
use bitcoin::hashes::Hash as _;
14521457
let mut payment_count = $dest_node.network_payment_count.borrow_mut();
14531458
let payment_preimage = $crate::ln::PaymentPreimage([*payment_count; 32]);
14541459
*payment_count += 1;
14551460
let payment_hash = $crate::ln::PaymentHash(
14561461
bitcoin::hashes::sha256::Hash::hash(&payment_preimage.0[..]).into_inner());
1457-
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200).unwrap();
1462+
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200, $min_final_cltv_expiry_delta).unwrap();
14581463
(payment_preimage, payment_hash, payment_secret)
14591464
}
1460-
}
1465+
};
14611466
}
14621467

14631468
#[macro_export]

lightning/src/ln/functional_tests.rs

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

12481248
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], 800_000);
1249-
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200).unwrap();
1249+
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
12501250
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], 800_000, payment_hash, node_a_payment_secret);
12511251

12521252
// Provide preimage to node 0 by claiming payment
@@ -4712,7 +4712,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
47124712

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

4715-
let payment_secret = nodes[3].node.create_inbound_payment_for_hash(duplicate_payment_hash, None, 7200).unwrap();
4715+
let payment_secret = nodes[3].node.create_inbound_payment_for_hash(duplicate_payment_hash, None, 7200, None).unwrap();
47164716
// We reduce the final CLTV here by a somewhat arbitrary constant to keep it under the one-byte
47174717
// script push size limit so that the below script length checks match
47184718
// ACCEPTED_HTLC_SCRIPT_WEIGHT.
@@ -4925,30 +4925,30 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
49254925
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
49264926
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], ds_dust_limit*1000);
49274927
// 2nd HTLC:
4928-
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
4928+
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
49294929
// 3rd HTLC:
4930-
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
4930+
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
49314931
// 4th HTLC:
49324932
let (_, payment_hash_3, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 1000000);
49334933
// 5th HTLC:
49344934
let (_, payment_hash_4, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 1000000);
49354935
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], 1000000);
49364936
// 6th HTLC:
4937-
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());
4937+
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());
49384938
// 7th HTLC:
4939-
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());
4939+
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());
49404940

49414941
// 8th HTLC:
49424942
let (_, payment_hash_5, _) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 1000000);
49434943
// 9th HTLC:
49444944
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], ds_dust_limit*1000);
4945-
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
4945+
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
49464946

49474947
// 10th HTLC:
49484948
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
49494949
// 11th HTLC:
49504950
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], 1000000);
4951-
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());
4951+
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());
49524952

49534953
// Double-check that six of the new HTLC were added
49544954
// We now have six HTLCs pending over the dust limit and six HTLCs under the dust limit (ie,
@@ -6922,7 +6922,7 @@ fn test_check_htlc_underpaying() {
69226922
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id()).with_features(nodes[1].node.invoice_features());
69236923
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();
69246924
let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
6925-
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200).unwrap();
6925+
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200, None).unwrap();
69266926
nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap();
69276927
check_added_monitors!(nodes[0], 1);
69286928

@@ -7917,7 +7917,7 @@ fn test_preimage_storage() {
79177917
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
79187918

79197919
{
7920-
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 7200).unwrap();
7920+
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 7200, None).unwrap();
79217921
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
79227922
nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
79237923
check_added_monitors!(nodes[0], 1);
@@ -8023,7 +8023,7 @@ fn test_bad_secret_hash() {
80238023

80248024
let random_payment_hash = PaymentHash([42; 32]);
80258025
let random_payment_secret = PaymentSecret([43; 32]);
8026-
let (our_payment_hash, our_payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 2).unwrap();
8026+
let (our_payment_hash, our_payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 2, None).unwrap();
80278027
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
80288028

80298029
// All the below cases should end up being handled exactly identically, so we macro the
@@ -9582,3 +9582,60 @@ fn accept_busted_but_better_fee() {
95829582
_ => panic!("Unexpected event"),
95839583
};
95849584
}
9585+
9586+
fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash: bool) {
9587+
let mut chanmon_cfgs = create_chanmon_cfgs(2);
9588+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
9589+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
9590+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
9591+
let min_final_cltv_expiry_delta = 120;
9592+
let final_cltv_expiry_delta = if valid_delta { min_final_cltv_expiry_delta + 2 } else {
9593+
min_final_cltv_expiry_delta - 2 };
9594+
let recv_value = 100_000;
9595+
9596+
create_chan_between_nodes(&nodes[0], &nodes[1]);
9597+
9598+
let payment_parameters = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id());
9599+
let (payment_hash, payment_preimage, payment_secret) = if use_user_hash {
9600+
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[1],
9601+
Some(recv_value), Some(min_final_cltv_expiry_delta));
9602+
(payment_hash, payment_preimage, payment_secret)
9603+
} else {
9604+
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(recv_value), 7200, Some(min_final_cltv_expiry_delta)).unwrap();
9605+
(payment_hash, nodes[1].node.get_payment_preimage(payment_hash, payment_secret).unwrap(), payment_secret)
9606+
};
9607+
let route = get_route!(nodes[0], payment_parameters, recv_value, final_cltv_expiry_delta as u32).unwrap();
9608+
nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
9609+
check_added_monitors!(nodes[0], 1);
9610+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
9611+
assert_eq!(events.len(), 1);
9612+
let mut payment_event = SendEvent::from_event(events.pop().unwrap());
9613+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
9614+
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
9615+
expect_pending_htlcs_forwardable!(nodes[1]);
9616+
9617+
if valid_delta {
9618+
expect_payment_claimable!(nodes[1], payment_hash, payment_secret, recv_value, if use_user_hash {
9619+
None } else { Some(payment_preimage) }, nodes[1].node.get_our_node_id());
9620+
9621+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
9622+
} else {
9623+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::FailedPayment { payment_hash }]);
9624+
9625+
check_added_monitors!(nodes[1], 1);
9626+
9627+
let fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
9628+
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_updates.update_fail_htlcs[0]);
9629+
commitment_signed_dance!(nodes[0], nodes[1], fail_updates.commitment_signed, false, true);
9630+
9631+
expect_payment_failed!(nodes[0], payment_hash, true);
9632+
}
9633+
}
9634+
9635+
#[test]
9636+
fn test_payment_with_custom_min_cltv_expiry_delta() {
9637+
do_payment_with_custom_min_final_cltv_expiry(false, false);
9638+
do_payment_with_custom_min_final_cltv_expiry(false, true);
9639+
do_payment_with_custom_min_final_cltv_expiry(true, false);
9640+
do_payment_with_custom_min_final_cltv_expiry(true, true);
9641+
}

0 commit comments

Comments
 (0)