Skip to content

Commit d0dec67

Browse files
committed
Add more robust functional test of Listen::blocks_disconnected
Now that the `Listen` interface allows blocks to be disconnected in batches rather than one at a time, we should test this. Here we add a new `ConnectStyle` for the functional test framework which tests doing so.
1 parent b1b4b4e commit d0dec67

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ pub enum ConnectStyle {
197197
/// Provides the full block via the `chain::Listen` interface. In the current code this is
198198
/// equivalent to `TransactionsFirst` with some additional assertions.
199199
FullBlockViaListen,
200+
/// Provides the full block via the `chain::Listen` interface, condensing multiple block
201+
/// disconnections into a single `blocks_disconnected` call.
202+
FullBlockDisconnectionsSkippingViaListen,
200203
}
201204

202205
impl ConnectStyle {
@@ -211,6 +214,7 @@ impl ConnectStyle {
211214
ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks => true,
212215
ConnectStyle::TransactionsFirstReorgsOnlyTip => true,
213216
ConnectStyle::FullBlockViaListen => false,
217+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen => false,
214218
}
215219
}
216220

@@ -225,14 +229,15 @@ impl ConnectStyle {
225229
ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks => false,
226230
ConnectStyle::TransactionsFirstReorgsOnlyTip => false,
227231
ConnectStyle::FullBlockViaListen => false,
232+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen => false,
228233
}
229234
}
230235

231236
fn random_style() -> ConnectStyle {
232237
use core::hash::{BuildHasher, Hasher};
233238
// Get a random value using the only std API to do so - the DefaultHasher
234239
let rand_val = std::collections::hash_map::RandomState::new().build_hasher().finish();
235-
let res = match rand_val % 9 {
240+
let res = match rand_val % 10 {
236241
0 => ConnectStyle::BestBlockFirst,
237242
1 => ConnectStyle::BestBlockFirstSkippingBlocks,
238243
2 => ConnectStyle::BestBlockFirstReorgsOnlyTip,
@@ -242,6 +247,7 @@ impl ConnectStyle {
242247
6 => ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks,
243248
7 => ConnectStyle::TransactionsFirstReorgsOnlyTip,
244249
8 => ConnectStyle::FullBlockViaListen,
250+
9 => ConnectStyle::FullBlockDisconnectionsSkippingViaListen,
245251
_ => unreachable!(),
246252
};
247253
eprintln!("Using Block Connection Style: {:?}", res);
@@ -372,7 +378,7 @@ fn do_connect_block_without_consistency_checks<'a, 'b, 'c, 'd>(
372378
node.node.transactions_confirmed(&block.header, &txdata, height);
373379
node.node.best_block_updated(&block.header, height);
374380
},
375-
ConnectStyle::FullBlockViaListen => {
381+
ConnectStyle::FullBlockViaListen|ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
376382
node.chain_monitor.chain_monitor.block_connected(&block, height);
377383
node.node.block_connected(&block, height);
378384
},
@@ -433,6 +439,13 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32)
433439
node.chain_monitor.chain_monitor.blocks_disconnected(best_block);
434440
Listen::blocks_disconnected(node.node, best_block);
435441
},
442+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
443+
if i == count - 1 {
444+
let best_block = BestBlock::new(orig.0.header.prev_blockhash, orig.1 - 1);
445+
node.chain_monitor.chain_monitor.blocks_disconnected(best_block);
446+
Listen::blocks_disconnected(node.node, best_block);
447+
}
448+
},
436449
ConnectStyle::BestBlockFirstSkippingBlocks
437450
| ConnectStyle::TransactionsFirstSkippingBlocks
438451
| ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks

lightning/src/ln/functional_tests.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,11 +2727,15 @@ pub fn test_htlc_ignore_latest_remote_commitment() {
27272727
let node_a_id = nodes[0].node.get_our_node_id();
27282728
let node_b_id = nodes[1].node.get_our_node_id();
27292729

2730-
if *nodes[1].connect_style.borrow() == ConnectStyle::FullBlockViaListen {
2731-
// We rely on the ability to connect a block redundantly, which isn't allowed via
2732-
// `chain::Listen`, so we never run the test if we randomly get assigned that
2733-
// connect_style.
2734-
return;
2730+
match *nodes[1].connect_style.borrow() {
2731+
ConnectStyle::FullBlockViaListen
2732+
| ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
2733+
// We rely on the ability to connect a block redundantly, which isn't allowed via
2734+
// `chain::Listen`, so we never run the test if we randomly get assigned that
2735+
// connect_style.
2736+
return;
2737+
},
2738+
_ => {},
27352739
}
27362740
let funding_tx = create_announced_chan_between_nodes(&nodes, 0, 1).3;
27372741
let message = "Channel force-closed".to_owned();

0 commit comments

Comments
 (0)