Skip to content

Commit 8b098ab

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 e01d30a commit 8b098ab

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 16 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,8 @@ 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
382+
| ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
376383
node.chain_monitor.chain_monitor.block_connected(&block, height);
377384
node.node.block_connected(&block, height);
378385
},
@@ -433,6 +440,13 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32)
433440
node.chain_monitor.chain_monitor.blocks_disconnected(best_block);
434441
Listen::blocks_disconnected(node.node, best_block);
435442
},
443+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
444+
if i == count - 1 {
445+
let best_block = BestBlock::new(orig.0.header.prev_blockhash, orig.1 - 1);
446+
node.chain_monitor.chain_monitor.blocks_disconnected(best_block);
447+
Listen::blocks_disconnected(node.node, best_block);
448+
}
449+
},
436450
ConnectStyle::BestBlockFirstSkippingBlocks
437451
| ConnectStyle::TransactionsFirstSkippingBlocks
438452
| ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks

lightning/src/ln/functional_tests.rs

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

2724-
if *nodes[1].connect_style.borrow() == ConnectStyle::FullBlockViaListen {
2725-
// We rely on the ability to connect a block redundantly, which isn't allowed via
2726-
// `chain::Listen`, so we never run the test if we randomly get assigned that
2727-
// connect_style.
2728-
return;
2724+
match *nodes[1].connect_style.borrow() {
2725+
ConnectStyle::FullBlockViaListen
2726+
| ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
2727+
// We rely on the ability to connect a block redundantly, which isn't allowed via
2728+
// `chain::Listen`, so we never run the test if we randomly get assigned that
2729+
// connect_style.
2730+
return;
2731+
},
2732+
_ => {},
27292733
}
27302734
let funding_tx = create_announced_chan_between_nodes(&nodes, 0, 1).3;
27312735
let message = "Channel force-closed".to_owned();

0 commit comments

Comments
 (0)