Skip to content

Commit 66d2e28

Browse files
committed
Clean up tests which rely on block count constants indirectly
Over the years we've built up a few tests which rely on block count constants but without making direct references to those constants. Here we fix three such tests to ensure changing block count constants in the next commit do not break tests.
1 parent 777e5c3 commit 66d2e28

8 files changed

+56
-10
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,13 @@ fn async_receive_mpp() {
537537
create_announced_chan_between_nodes(&nodes, 0, 2);
538538
create_unannounced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0);
539539
create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0);
540+
541+
// Ensure all nodes start at the same height.
542+
connect_blocks(&nodes[0], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
543+
connect_blocks(&nodes[1], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
544+
connect_blocks(&nodes[2], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
545+
connect_blocks(&nodes[3], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
546+
540547
let (offer, static_invoice) = create_static_invoice(&nodes[1], &nodes[3], None, &secp_ctx);
541548

542549
// In other tests we hardcode the sender's random bytes so we can predict the keysend preimage to
@@ -618,6 +625,12 @@ fn amount_doesnt_match_invreq() {
618625
create_unannounced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0);
619626
create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0);
620627

628+
// Ensure all nodes start at the same height.
629+
connect_blocks(&nodes[0], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
630+
connect_blocks(&nodes[1], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
631+
connect_blocks(&nodes[2], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
632+
connect_blocks(&nodes[3], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
633+
621634
let (offer, static_invoice) = create_static_invoice(&nodes[1], &nodes[3], None, &secp_ctx);
622635

623636
// Set the random bytes so we can predict the payment preimage and hash.
@@ -810,9 +823,15 @@ fn invalid_async_receive_with_retry<F1, F2>(
810823
let node_chanmgrs =
811824
create_node_chanmgrs(3, &node_cfgs, &[None, Some(allow_priv_chan_fwds_cfg), None]);
812825
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
826+
813827
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
814828
create_unannounced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0);
815829

830+
// Ensure all nodes start at the same height.
831+
connect_blocks(&nodes[0], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
832+
connect_blocks(&nodes[1], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
833+
connect_blocks(&nodes[2], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
834+
816835
let blinded_paths_to_always_online_node = nodes[1]
817836
.message_router
818837
.create_blinded_paths(

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ fn mpp_to_one_hop_blinded_path() {
204204
let chan_upd_1_3 = create_announced_chan_between_nodes(&nodes, 1, 3).0.contents;
205205
create_announced_chan_between_nodes(&nodes, 2, 3).0.contents;
206206

207+
// Ensure all nodes start at the same height.
208+
connect_blocks(&nodes[0], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
209+
connect_blocks(&nodes[1], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
210+
connect_blocks(&nodes[2], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
211+
connect_blocks(&nodes[3], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
212+
207213
let amt_msat = 15_000_000;
208214
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
209215
let payee_tlvs = UnauthenticatedReceiveTlvs {
@@ -267,6 +273,14 @@ fn mpp_to_three_hop_blinded_paths() {
267273
let chan_upd_3_5 = create_announced_chan_between_nodes(&nodes, 3, 5).0.contents;
268274
let chan_upd_4_5 = create_announced_chan_between_nodes(&nodes, 4, 5).0.contents;
269275

276+
// Start every node on the same block height to make reasoning about timeouts easier
277+
connect_blocks(&nodes[0], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
278+
connect_blocks(&nodes[1], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
279+
connect_blocks(&nodes[2], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
280+
connect_blocks(&nodes[3], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
281+
connect_blocks(&nodes[4], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[4].best_block_info().1);
282+
connect_blocks(&nodes[5], 6*CHAN_CONFIRM_DEPTH + 1 - nodes[5].best_block_info().1);
283+
270284
let amt_msat = 15_000_000;
271285
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[5], Some(amt_msat), None);
272286
let route_params = {
@@ -1070,6 +1084,12 @@ fn blinded_path_retries() {
10701084
let chan_1_3 = create_announced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0);
10711085
let chan_2_3 = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0);
10721086

1087+
// Ensure all nodes start at the same height.
1088+
connect_blocks(&nodes[0], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
1089+
connect_blocks(&nodes[1], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
1090+
connect_blocks(&nodes[2], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
1091+
connect_blocks(&nodes[3], 4*CHAN_CONFIRM_DEPTH + 1 - nodes[3].best_block_info().1);
1092+
10731093
let amt_msat = 5000;
10741094
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
10751095
let route_params = {

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15817,15 +15817,15 @@ mod tests {
1581715817
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
1581815818
let result = create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive(msgs::InboundOnionReceivePayload {
1581915819
sender_intended_htlc_amt_msat: 100,
15820-
cltv_expiry_height: 22,
15820+
cltv_expiry_height: TEST_FINAL_CLTV,
1582115821
payment_metadata: None,
1582215822
keysend_preimage: None,
1582315823
payment_data: Some(msgs::FinalOnionHopData {
1582415824
payment_secret: PaymentSecret([0; 32]),
1582515825
total_msat: 100,
1582615826
}),
1582715827
custom_tlvs: Vec::new(),
15828-
}), [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None, current_height);
15828+
}), [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, current_height);
1582915829

1583015830
// Should not return an error as this condition:
1583115831
// https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7822,7 +7822,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
78227822
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
78237823

78247824
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
7825-
let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 30)
7825+
let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), TEST_FINAL_CLTV)
78267826
.with_bolt11_features(nodes[0].node.bolt11_invoice_features()).unwrap();
78277827
let (route,_, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_params, 3000000);
78287828
send_along_route(&nodes[1], route, &vec!(&nodes[0])[..], 3000000);

lightning/src/ln/invoice_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ mod test {
711711
use bitcoin::hashes::sha256::Hash as Sha256;
712712
use bitcoin::network::Network;
713713
use crate::sign::PhantomKeysManager;
714+
use crate::chain::channelmonitor::HTLC_FAIL_BACK_BUFFER;
714715
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
715716
use crate::types::payment::{PaymentHash, PaymentPreimage};
716717
use crate::ln::channelmanager::{Bolt11InvoiceParameters, PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
@@ -843,7 +844,7 @@ mod test {
843844
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
844845
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
845846

846-
let custom_min_final_cltv_expiry_delta = Some(21);
847+
let custom_min_final_cltv_expiry_delta = Some(HTLC_FAIL_BACK_BUFFER as u16);
847848
let description = Bolt11InvoiceDescription::Direct(Description::empty());
848849
let invoice_params = Bolt11InvoiceParameters {
849850
amount_msats: Some(10_000),

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ fn one_hop_blinded_path_with_custom_tlv() {
156156
create_announced_chan_between_nodes(&nodes, 0, 1);
157157
let chan_upd_1_2 = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0).0.contents;
158158

159+
// Start with all nodes at the same height
160+
connect_blocks(&nodes[0], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
161+
connect_blocks(&nodes[1], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
162+
connect_blocks(&nodes[2], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
163+
159164
// Construct the route parameters for sending to nodes[2]'s 1-hop blinded path.
160165
let amt_msat = 100_000;
161166
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);

lightning/src/ln/onion_payment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ mod tests {
506506
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
507507
use crate::ln::types::ChannelId;
508508
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
509-
use crate::ln::channelmanager::RecipientOnionFields;
509+
use crate::ln::channelmanager::{RecipientOnionFields, MIN_CLTV_EXPIRY_DELTA};
510+
use crate::ln::functional_test_utils::TEST_FINAL_CLTV;
510511
use crate::types::features::{ChannelFeatures, NodeFeatures};
511512
use crate::ln::msgs;
512513
use crate::ln::onion_utils::create_payment_onion;
@@ -637,7 +638,7 @@ mod tests {
637638
RouteHop {
638639
pubkey: hop_pk,
639640
fee_msat: hop_fee,
640-
cltv_expiry_delta: 42,
641+
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA as u32,
641642
short_channel_id: 1,
642643
node_features: NodeFeatures::empty(),
643644
channel_features: ChannelFeatures::empty(),
@@ -646,7 +647,7 @@ mod tests {
646647
RouteHop {
647648
pubkey: recipient_pk,
648649
fee_msat: recipient_amount,
649-
cltv_expiry_delta: 42,
650+
cltv_expiry_delta: TEST_FINAL_CLTV,
650651
short_channel_id: 2,
651652
node_features: NodeFeatures::empty(),
652653
channel_features: ChannelFeatures::empty(),

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn test_routed_scid_alias() {
246246
htlc_maximum_msat: None,
247247
htlc_minimum_msat: None,
248248
}])];
249-
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
249+
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
250250
.with_bolt11_features(nodes[2].node.bolt11_invoice_features()).unwrap()
251251
.with_route_hints(hop_hints).unwrap();
252252
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
@@ -412,7 +412,7 @@ fn test_inbound_scid_privacy() {
412412
htlc_maximum_msat: None,
413413
htlc_minimum_msat: None,
414414
}])];
415-
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
415+
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
416416
.with_bolt11_features(nodes[2].node.bolt11_invoice_features()).unwrap()
417417
.with_route_hints(hop_hints.clone()).unwrap();
418418
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
@@ -428,7 +428,7 @@ fn test_inbound_scid_privacy() {
428428
// what channel we're talking about.
429429
hop_hints[0].0[0].short_channel_id = last_hop[0].short_channel_id.unwrap();
430430

431-
let payment_params_2 = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
431+
let payment_params_2 = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
432432
.with_bolt11_features(nodes[2].node.bolt11_invoice_features()).unwrap()
433433
.with_route_hints(hop_hints).unwrap();
434434
let (route_2, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params_2, 100_000);

0 commit comments

Comments
 (0)