Skip to content

Commit b045453

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 6b94af9 commit b045453

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ pub enum ConnectStyle {
171171
/// Provides the full block via the `chain::Listen` interface. In the current code this is
172172
/// equivalent to `TransactionsFirst` with some additional assertions.
173173
FullBlockViaListen,
174+
/// Provides the full block via the `chain::Listen` interface, condensing multiple block
175+
/// disconnections into a single `blocks_disconnected` call.
176+
FullBlockDisconnectionsSkippingViaListen,
174177
}
175178

176179
impl ConnectStyle {
@@ -185,6 +188,7 @@ impl ConnectStyle {
185188
ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks => true,
186189
ConnectStyle::TransactionsFirstReorgsOnlyTip => true,
187190
ConnectStyle::FullBlockViaListen => false,
191+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen => false,
188192
}
189193
}
190194

@@ -199,14 +203,15 @@ impl ConnectStyle {
199203
ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks => false,
200204
ConnectStyle::TransactionsFirstReorgsOnlyTip => false,
201205
ConnectStyle::FullBlockViaListen => false,
206+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen => false,
202207
}
203208
}
204209

205210
fn random_style() -> ConnectStyle {
206211
use core::hash::{BuildHasher, Hasher};
207212
// Get a random value using the only std API to do so - the DefaultHasher
208213
let rand_val = std::collections::hash_map::RandomState::new().build_hasher().finish();
209-
let res = match rand_val % 9 {
214+
let res = match rand_val % 10 {
210215
0 => ConnectStyle::BestBlockFirst,
211216
1 => ConnectStyle::BestBlockFirstSkippingBlocks,
212217
2 => ConnectStyle::BestBlockFirstReorgsOnlyTip,
@@ -216,6 +221,7 @@ impl ConnectStyle {
216221
6 => ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks,
217222
7 => ConnectStyle::TransactionsFirstReorgsOnlyTip,
218223
8 => ConnectStyle::FullBlockViaListen,
224+
9 => ConnectStyle::FullBlockDisconnectionsSkippingViaListen,
219225
_ => unreachable!(),
220226
};
221227
eprintln!("Using Block Connection Style: {:?}", res);
@@ -319,7 +325,7 @@ fn do_connect_block_without_consistency_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b
319325
node.node.transactions_confirmed(&block.header, &txdata, height);
320326
node.node.best_block_updated(&block.header, height);
321327
},
322-
ConnectStyle::FullBlockViaListen => {
328+
ConnectStyle::FullBlockViaListen|ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
323329
node.chain_monitor.chain_monitor.block_connected(&block, height);
324330
node.node.block_connected(&block, height);
325331
}
@@ -353,6 +359,12 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32)
353359
node.chain_monitor.chain_monitor.blocks_disconnected(orig.0.header.prev_blockhash, orig.1 - 1);
354360
Listen::blocks_disconnected(node.node, orig.0.header.prev_blockhash, orig.1 - 1);
355361
},
362+
ConnectStyle::FullBlockDisconnectionsSkippingViaListen => {
363+
if i == count - 1 {
364+
node.chain_monitor.chain_monitor.blocks_disconnected(orig.0.header.prev_blockhash, orig.1 - 1);
365+
Listen::blocks_disconnected(node.node, orig.0.header.prev_blockhash, orig.1 - 1);
366+
}
367+
},
356368
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks|
357369
ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks|ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks => {
358370
if i == count - 1 {

0 commit comments

Comments
 (0)