Skip to content

Commit 5b21115

Browse files
committed
Make test block connect style configurable for deterministic runs
Tests previously selected a random block connect style to improve coverage. However, this randomness made test output non-deterministic and significantly cluttered diffs when comparing logs before and after changes. To address this, an LDK_TEST_CONNECT_STYLE environment variable is added to override the random selection and enable deterministic test runs. Note that broader coverage may be better achieved via targeted tests per connect style or a test matrix cycling through all styles, but this change focuses on improving reproducibility and debuggability.
1 parent 62c5849 commit 5b21115

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ Fuzzing is heavily encouraged: you will find all related material under `fuzz/`
176176
Mutation testing is work-in-progress; any contribution there would be warmly
177177
welcomed.
178178

179+
### Environment Variables
180+
181+
* `LDK_TEST_CONNECT_STYLE` - Override the random block connect style used in tests for deterministic runs. Valid values:
182+
* `BEST_BLOCK_FIRST`
183+
* `BEST_BLOCK_FIRST_SKIPPING_BLOCKS`
184+
* `BEST_BLOCK_FIRST_REORGS_ONLY_TIP`
185+
* `TRANSACTIONS_FIRST`
186+
* `TRANSACTIONS_FIRST_SKIPPING_BLOCKS`
187+
* `TRANSACTIONS_DUPLICATIVELY_FIRST_SKIPPING_BLOCKS`
188+
* `HIGHLY_REDUNDANT_TRANSACTIONS_FIRST_SKIPPING_BLOCKS`
189+
* `TRANSACTIONS_FIRST_REORGS_ONLY_TIP`
190+
* `FULL_BLOCK_VIA_LISTEN`
191+
* `FULL_BLOCK_DISCONNECTIONS_SKIPPING_VIA_LISTEN`
192+
179193
C/C++ Bindings
180194
--------------
181195

lightning/src/ln/functional_test_utils.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4563,7 +4563,29 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(
45634563
let mut nodes = Vec::new();
45644564
let chan_count = Rc::new(RefCell::new(0));
45654565
let payment_count = Rc::new(RefCell::new(0));
4566-
let connect_style = Rc::new(RefCell::new(ConnectStyle::random_style()));
4566+
4567+
let connect_style = Rc::new(RefCell::new(match std::env::var("LDK_TEST_CONNECT_STYLE") {
4568+
Ok(val) => match val.as_str() {
4569+
"BEST_BLOCK_FIRST" => ConnectStyle::BestBlockFirst,
4570+
"BEST_BLOCK_FIRST_SKIPPING_BLOCKS" => ConnectStyle::BestBlockFirstSkippingBlocks,
4571+
"BEST_BLOCK_FIRST_REORGS_ONLY_TIP" => ConnectStyle::BestBlockFirstReorgsOnlyTip,
4572+
"TRANSACTIONS_FIRST" => ConnectStyle::TransactionsFirst,
4573+
"TRANSACTIONS_FIRST_SKIPPING_BLOCKS" => ConnectStyle::TransactionsFirstSkippingBlocks,
4574+
"TRANSACTIONS_DUPLICATIVELY_FIRST_SKIPPING_BLOCKS" => {
4575+
ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks
4576+
},
4577+
"HIGHLY_REDUNDANT_TRANSACTIONS_FIRST_SKIPPING_BLOCKS" => {
4578+
ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks
4579+
},
4580+
"TRANSACTIONS_FIRST_REORGS_ONLY_TIP" => ConnectStyle::TransactionsFirstReorgsOnlyTip,
4581+
"FULL_BLOCK_VIA_LISTEN" => ConnectStyle::FullBlockViaListen,
4582+
"FULL_BLOCK_DISCONNECTIONS_SKIPPING_VIA_LISTEN" => {
4583+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen
4584+
},
4585+
_ => panic!("Unknown ConnectStyle '{}'", val),
4586+
},
4587+
Err(_) => ConnectStyle::random_style(),
4588+
}));
45674589

45684590
for i in 0..node_count {
45694591
let dedicated_entropy = DedicatedEntropy(RandomBytes::new([i as u8; 32]));

0 commit comments

Comments
 (0)