Skip to content

Commit d6364c6

Browse files
committed
approval-distribution: Fix handling of conclude
After moonbeam-foundation@53373a9, approval-distribution did not terminate anymore if Conclude signal was received. This should have been caught by the subsystem tests, but it wasn't because the subsystem is also exiting on error when the channels are dropped so the test overseer was dropped which made the susbystem exit and masked the problem. This pr fixes both the test and the subsystem. Signed-off-by: Alexandru Gheorghe <[email protected]>
1 parent 069f8a6 commit d6364c6

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

polkadot/node/network/approval-distribution/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,14 +2508,18 @@ impl ApprovalDistribution {
25082508
};
25092509

25102510

2511-
self.handle_from_orchestra(message, &mut approval_voting_sender, &mut network_sender, state, rng).await;
2511+
if self.handle_from_orchestra(message, &mut approval_voting_sender, &mut network_sender, state, rng).await {
2512+
return;
2513+
}
25122514

25132515
},
25142516
}
25152517
}
25162518
}
25172519

25182520
/// Handles a from orchestra message received by approval distribution subystem.
2521+
///
2522+
/// Returns `true` if the subsystem should be stopped.
25192523
pub async fn handle_from_orchestra<
25202524
N: overseer::SubsystemSender<NetworkBridgeTxMessage>,
25212525
A: overseer::SubsystemSender<ApprovalVotingMessage>,
@@ -2526,7 +2530,7 @@ impl ApprovalDistribution {
25262530
network_sender: &mut N,
25272531
state: &mut State,
25282532
rng: &mut (impl CryptoRng + Rng),
2529-
) {
2533+
) -> bool {
25302534
match message {
25312535
FromOrchestra::Communication { msg } =>
25322536
Self::handle_incoming(
@@ -2555,8 +2559,9 @@ impl ApprovalDistribution {
25552559
gum::trace!(target: LOG_TARGET, number = %number, "finalized signal");
25562560
state.handle_block_finalized(network_sender, &self.metrics, number).await;
25572561
},
2558-
FromOrchestra::Signal(OverseerSignal::Conclude) => return,
2562+
FromOrchestra::Signal(OverseerSignal::Conclude) => return true,
25592563
}
2564+
false
25602565
}
25612566

25622567
async fn handle_incoming<

polkadot/node/network/approval-distribution/src/tests.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
5959
let subsystem = ApprovalDistribution::new(Default::default());
6060
{
6161
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(12345);
62-
63-
let subsystem =
64-
subsystem.run_inner(context, &mut state, REPUTATION_CHANGE_TEST_INTERVAL, &mut rng);
62+
let (tx, rx) = oneshot::channel();
63+
let subsystem = async {
64+
subsystem
65+
.run_inner(context, &mut state, REPUTATION_CHANGE_TEST_INTERVAL, &mut rng)
66+
.await;
67+
tx.send(()).expect("Fail to notify subystem is done");
68+
};
6569

6670
let test_fut = test_fn(virtual_overseer);
6771

@@ -76,6 +80,8 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
7680
.timeout(TIMEOUT)
7781
.await
7882
.expect("Conclude send timeout");
83+
let _ =
84+
rx.timeout(Duration::from_secs(2)).await.expect("Subsystem did not conclude");
7985
},
8086
subsystem,
8187
));

0 commit comments

Comments
 (0)