Skip to content

Commit 952e0cb

Browse files
committed
fuzz: factor chanmon_consistency node loops
Replace repeated per-node setup and event-processing calls with loops. Keep the existing assertions and early-continue behavior intact.
1 parent 12c541c commit 952e0cb

1 file changed

Lines changed: 25 additions & 35 deletions

File tree

fuzz/src/chanmon_consistency.rs

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,10 +2237,11 @@ fn assert_test_invariants(nodes: &[HarnessNode<'_>; 3]) {
22372237
assert_eq!(nodes[1].list_channels().len(), 6);
22382238
assert_eq!(nodes[2].list_channels().len(), 3);
22392239

2240-
// All broadcasters should be empty. Broadcast transactions are handled explicitly.
2241-
assert!(nodes[0].broadcaster.txn_broadcasted.borrow().is_empty());
2242-
assert!(nodes[1].broadcaster.txn_broadcasted.borrow().is_empty());
2243-
assert!(nodes[2].broadcaster.txn_broadcasted.borrow().is_empty());
2240+
// All broadcasters should be empty because broadcast transactions only enter
2241+
// the modeled mempool through explicit relay commands or finish cleanup.
2242+
for node in nodes {
2243+
assert!(node.broadcaster.txn_broadcasted.borrow().is_empty());
2244+
}
22442245
}
22452246

22462247
fn connect_peers(source: &ChanMan<'_>, dest: &ChanMan<'_>) {
@@ -2557,16 +2558,17 @@ impl<'a, Out: Output + MaybeSend + MaybeSync> Harness<'a, Out> {
25572558
make_channel(&mut nodes, 1, 2, 5, set_0reserve, false, &mut chain_state);
25582559
make_channel(&mut nodes, 1, 2, 6, false, false, &mut chain_state);
25592560

2560-
// Wipe the transactions-broadcasted set to make sure we don't broadcast
2561-
// any transactions during normal operation after setup.
2562-
nodes[0].broadcaster.txn_broadcasted.borrow_mut().clear();
2563-
nodes[1].broadcaster.txn_broadcasted.borrow_mut().clear();
2564-
nodes[2].broadcaster.txn_broadcasted.borrow_mut().clear();
2561+
// Wipe setup-time broadcasts so normal operation starts with an empty
2562+
// relay queue. Later broadcasts only enter the mempool through relay
2563+
// commands or finish cleanup.
2564+
for node in &nodes {
2565+
node.broadcaster.txn_broadcasted.borrow_mut().clear();
2566+
}
25652567

25662568
// Sync all nodes to tip to lock the funding.
2567-
nodes[0].sync_with_chain_state(&chain_state, None);
2568-
nodes[1].sync_with_chain_state(&chain_state, None);
2569-
nodes[2].sync_with_chain_state(&chain_state, None);
2569+
for node in &mut nodes {
2570+
node.sync_with_chain_state(&chain_state, None);
2571+
}
25702572

25712573
lock_fundings(&nodes);
25722574

@@ -3145,7 +3147,7 @@ impl<'a, Out: Output + MaybeSend + MaybeSync> Harness<'a, Out> {
31453147

31463148
fn process_all_events(&mut self) {
31473149
let mut last_pass_no_updates = false;
3148-
for i in 0..std::usize::MAX {
3150+
'settle: for i in 0..std::usize::MAX {
31493151
if i == MAX_SETTLE_ITERATIONS {
31503152
panic!(
31513153
"It may take many iterations to settle the state, but it should not take forever"
@@ -3156,30 +3158,18 @@ impl<'a, Out: Output + MaybeSend + MaybeSync> Harness<'a, Out> {
31563158
made_progress |= self.ab_link.complete_all_monitor_updates(&self.nodes);
31573159
made_progress |= self.bc_link.complete_all_monitor_updates(&self.nodes);
31583160
// Then, make sure any current forwards make their way to their destination.
3159-
if self.process_msg_events(0, false, ProcessMessages::AllMessages) {
3160-
last_pass_no_updates = false;
3161-
continue;
3162-
}
3163-
if self.process_msg_events(1, false, ProcessMessages::AllMessages) {
3164-
last_pass_no_updates = false;
3165-
continue;
3166-
}
3167-
if self.process_msg_events(2, false, ProcessMessages::AllMessages) {
3168-
last_pass_no_updates = false;
3169-
continue;
3161+
for node_idx in 0..3 {
3162+
if self.process_msg_events(node_idx, false, ProcessMessages::AllMessages) {
3163+
last_pass_no_updates = false;
3164+
continue 'settle;
3165+
}
31703166
}
31713167
// ...making sure any payments are claimed.
3172-
if self.process_events(0, false) {
3173-
last_pass_no_updates = false;
3174-
continue;
3175-
}
3176-
if self.process_events(1, false) {
3177-
last_pass_no_updates = false;
3178-
continue;
3179-
}
3180-
if self.process_events(2, false) {
3181-
last_pass_no_updates = false;
3182-
continue;
3168+
for node_idx in 0..3 {
3169+
if self.process_events(node_idx, false) {
3170+
last_pass_no_updates = false;
3171+
continue 'settle;
3172+
}
31833173
}
31843174
if made_progress {
31853175
last_pass_no_updates = false;

0 commit comments

Comments
 (0)