Make test block connect style configurable for deterministic runs
What changed, and why it matters
This change only affects internal test code. It adds an environment variable so developers can choose a fixed block-connect style during testing instead of having one picked at random. There is no production code change and no security impact.
No security action needed. This is a benign test-quality improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies lightning/src/ln/functional_test_utils.rs so that create_network() reads LDK_TEST_CONNECT_STYLE to select a deterministic ConnectStyle for tests, falling back to the existing random selection when the variable is absent. It also documents the variable in CONTRIBUTING.md. The change is purely test-infrastructure tooling.
Changed components
lightning/src/ln/functional_test_utils.rsCONTRIBUTING.mdInspect captured patch +37 / −1
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 1bc431a..e7825ac 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -176,6 +176,20 @@ Fuzzing is heavily encouraged: you will find all related material under `fuzz/`
Mutation testing is work-in-progress; any contribution there would be warmly
welcomed.
+### Environment Variables
+
+* `LDK_TEST_CONNECT_STYLE` - Override the random block connect style used in tests for deterministic runs. Valid values:
+ * `BEST_BLOCK_FIRST`
+ * `BEST_BLOCK_FIRST_SKIPPING_BLOCKS`
+ * `BEST_BLOCK_FIRST_REORGS_ONLY_TIP`
+ * `TRANSACTIONS_FIRST`
+ * `TRANSACTIONS_FIRST_SKIPPING_BLOCKS`
+ * `TRANSACTIONS_DUPLICATIVELY_FIRST_SKIPPING_BLOCKS`
+ * `HIGHLY_REDUNDANT_TRANSACTIONS_FIRST_SKIPPING_BLOCKS`
+ * `TRANSACTIONS_FIRST_REORGS_ONLY_TIP`
+ * `FULL_BLOCK_VIA_LISTEN`
+ * `FULL_BLOCK_DISCONNECTIONS_SKIPPING_VIA_LISTEN`
+
C/C++ Bindings
--------------
diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs
index e072deb..e9cb13d 100644
--- a/lightning/src/ln/functional_test_utils.rs
+++ b/lightning/src/ln/functional_test_utils.rs
@@ -4563,7 +4563,29 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(
let mut nodes = Vec::new();
let chan_count = Rc::new(RefCell::new(0));
let payment_count = Rc::new(RefCell::new(0));
- let connect_style = Rc::new(RefCell::new(ConnectStyle::random_style()));
+
+ let connect_style = Rc::new(RefCell::new(match std::env::var("LDK_TEST_CONNECT_STYLE") {
+ Ok(val) => match val.as_str() {
+ "BEST_BLOCK_FIRST" => ConnectStyle::BestBlockFirst,
+ "BEST_BLOCK_FIRST_SKIPPING_BLOCKS" => ConnectStyle::BestBlockFirstSkippingBlocks,
+ "BEST_BLOCK_FIRST_REORGS_ONLY_TIP" => ConnectStyle::BestBlockFirstReorgsOnlyTip,
+ "TRANSACTIONS_FIRST" => ConnectStyle::TransactionsFirst,
+ "TRANSACTIONS_FIRST_SKIPPING_BLOCKS" => ConnectStyle::TransactionsFirstSkippingBlocks,
+ "TRANSACTIONS_DUPLICATIVELY_FIRST_SKIPPING_BLOCKS" => {
+ ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks
+ },
+ "HIGHLY_REDUNDANT_TRANSACTIONS_FIRST_SKIPPING_BLOCKS" => {
+ ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks
+ },
+ "TRANSACTIONS_FIRST_REORGS_ONLY_TIP" => ConnectStyle::TransactionsFirstReorgsOnlyTip,
+ "FULL_BLOCK_VIA_LISTEN" => ConnectStyle::FullBlockViaListen,
+ "FULL_BLOCK_DISCONNECTIONS_SKIPPING_VIA_LISTEN" => {
+ ConnectStyle::FullBlockDisconnectionsSkippingViaListen
+ },
+ _ => panic!("Unknown ConnectStyle '{}'", val),
+ },
+ Err(_) => ConnectStyle::random_style(),
+ }));
for i in 0..node_count {
let dedicated_entropy = DedicatedEntropy(RandomBytes::new([i as u8; 32]));
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.