Skip to content

Commit b04feed

Browse files
alexgghgithub-actions[bot]pepoviola
authored andcommitted
extend overseer to send priority messages (#8834)
Extend overseer to send priority messages, the new functionality is used for sending messages on the grandpa call path when we call dispute-coordinator and approval-voting in finality_target_with_longest_chain to make sure we don't block unnecessarily. Depends on: paritytech/orchestra#87. --------- Signed-off-by: Alexandru Gheorghe <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Javier Viola <[email protected]> Co-authored-by: Javier Viola <[email protected]>
1 parent 47eef75 commit b04feed

File tree

6 files changed

+100
-17
lines changed

6 files changed

+100
-17
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/node/core/approval-voting-parallel/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ async fn run_main_loop<Context>(
347347
// The message the approval voting subsystem would've handled.
348348
ApprovalVotingParallelMessage::ApprovedAncestor(_, _,_) |
349349
ApprovalVotingParallelMessage::GetApprovalSignaturesForCandidate(_, _) => {
350-
to_approval_voting_worker.send_message(
350+
to_approval_voting_worker.send_message_with_priority::<overseer::HighPriority>(
351351
msg.try_into().expect(
352352
"Message is one of ApprovedAncestor, GetApprovalSignaturesForCandidate
353353
and that can be safely converted to ApprovalVotingMessage; qed"

polkadot/node/overseer/src/lib.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,20 @@ impl Handle {
190190
self.send_and_log_error(Event::BlockImported(block)).await
191191
}
192192

193-
/// Send some message to one of the `Subsystem`s.
193+
/// Send some message with normal priority to one of the `Subsystem`s.
194194
pub async fn send_msg(&mut self, msg: impl Into<AllMessages>, origin: &'static str) {
195-
self.send_and_log_error(Event::MsgToSubsystem { msg: msg.into(), origin }).await
195+
self.send_msg_with_priority(msg, origin, PriorityLevel::Normal).await
196+
}
197+
198+
/// Send some message with the specified priority to one of the `Subsystem`s.
199+
pub async fn send_msg_with_priority(
200+
&mut self,
201+
msg: impl Into<AllMessages>,
202+
origin: &'static str,
203+
priority: PriorityLevel,
204+
) {
205+
self.send_and_log_error(Event::MsgToSubsystem { msg: msg.into(), origin, priority })
206+
.await
196207
}
197208

198209
/// Send a message not providing an origin.
@@ -296,6 +307,8 @@ pub enum Event {
296307
msg: AllMessages,
297308
/// The originating subsystem name.
298309
origin: &'static str,
310+
/// The priority of the message.
311+
priority: PriorityLevel,
299312
},
300313
/// A request from the outer world.
301314
ExternalRequest(ExternalRequest),
@@ -764,8 +777,15 @@ where
764777
select! {
765778
msg = self.events_rx.select_next_some() => {
766779
match msg {
767-
Event::MsgToSubsystem { msg, origin } => {
768-
self.route_message(msg.into(), origin).await?;
780+
Event::MsgToSubsystem { msg, origin, priority } => {
781+
match priority {
782+
PriorityLevel::Normal => {
783+
self.route_message(msg.into(), origin).await?;
784+
},
785+
PriorityLevel::High => {
786+
self.route_message_with_priority::<HighPriority>(msg.into(), origin).await?;
787+
},
788+
}
769789
self.metrics.on_message_relayed();
770790
}
771791
Event::Stop => {

polkadot/node/service/src/relay_chain_selection.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use polkadot_node_subsystem::messages::{
4343
ChainSelectionMessage, DisputeCoordinatorMessage, HighestApprovedAncestorBlock,
4444
};
4545
use polkadot_node_subsystem_util::metrics::{self, prometheus};
46-
use polkadot_overseer::{AllMessages, Handle};
46+
use polkadot_overseer::{AllMessages, Handle, PriorityLevel};
4747
use polkadot_primitives::{Block as PolkadotBlock, BlockNumber, Hash, Header as PolkadotHeader};
4848
use sp_consensus::{Error as ConsensusError, SelectChain};
4949
use std::sync::Arc;
@@ -238,7 +238,7 @@ pub struct SelectRelayChainInner<B, OH> {
238238
impl<B, OH> SelectRelayChainInner<B, OH>
239239
where
240240
B: HeaderProviderProvider<PolkadotBlock>,
241-
OH: OverseerHandleT,
241+
OH: OverseerHandleT + OverseerHandleWithPriorityT,
242242
{
243243
/// Create a new [`SelectRelayChainInner`] wrapping the given chain backend
244244
/// and a handle to the overseer.
@@ -286,7 +286,7 @@ where
286286
impl<B, OH> Clone for SelectRelayChainInner<B, OH>
287287
where
288288
B: HeaderProviderProvider<PolkadotBlock> + Send + Sync,
289-
OH: OverseerHandleT,
289+
OH: OverseerHandleT + OverseerHandleWithPriorityT,
290290
{
291291
fn clone(&self) -> Self {
292292
SelectRelayChainInner {
@@ -325,17 +325,40 @@ pub trait OverseerHandleT: Clone + Send + Sync {
325325
async fn send_msg<M: Send + Into<AllMessages>>(&mut self, msg: M, origin: &'static str);
326326
}
327327

328+
/// Trait for the overseer handle that allows sending messages with the specified priority level.
329+
#[async_trait::async_trait]
330+
pub trait OverseerHandleWithPriorityT: Clone + Send + Sync {
331+
async fn send_msg_with_priority<M: Send + Into<AllMessages>>(
332+
&mut self,
333+
msg: M,
334+
origin: &'static str,
335+
priority: PriorityLevel,
336+
);
337+
}
338+
328339
#[async_trait::async_trait]
329340
impl OverseerHandleT for Handle {
330341
async fn send_msg<M: Send + Into<AllMessages>>(&mut self, msg: M, origin: &'static str) {
331342
Handle::send_msg(self, msg, origin).await
332343
}
333344
}
334345

346+
#[async_trait::async_trait]
347+
impl OverseerHandleWithPriorityT for Handle {
348+
async fn send_msg_with_priority<M: Send + Into<AllMessages>>(
349+
&mut self,
350+
msg: M,
351+
origin: &'static str,
352+
priority: PriorityLevel,
353+
) {
354+
Handle::send_msg_with_priority(self, msg, origin, priority).await
355+
}
356+
}
357+
335358
impl<B, OH> SelectRelayChainInner<B, OH>
336359
where
337360
B: HeaderProviderProvider<PolkadotBlock>,
338-
OH: OverseerHandleT + 'static,
361+
OH: OverseerHandleT + OverseerHandleWithPriorityT + 'static,
339362
{
340363
/// Get all leaves of the chain, i.e. block hashes that are suitable to
341364
/// build upon and have no suitable children.
@@ -472,9 +495,10 @@ where
472495
.await;
473496
} else {
474497
overseer
475-
.send_msg(
498+
.send_msg_with_priority(
476499
ApprovalVotingMessage::ApprovedAncestor(subchain_head, target_number, tx),
477500
std::any::type_name::<Self>(),
501+
PriorityLevel::High,
478502
)
479503
.await;
480504
}
@@ -503,16 +527,18 @@ where
503527
let lag_update_task = async move {
504528
if approval_voting_parallel_enabled {
505529
overseer_handle
506-
.send_msg(
530+
.send_msg_with_priority(
507531
ApprovalVotingParallelMessage::ApprovalCheckingLagUpdate(lag),
508532
std::any::type_name::<Self>(),
533+
PriorityLevel::High,
509534
)
510535
.await;
511536
} else {
512537
overseer_handle
513-
.send_msg(
538+
.send_msg_with_priority(
514539
ApprovalDistributionMessage::ApprovalCheckingLagUpdate(lag),
515540
std::any::type_name::<Self>(),
541+
PriorityLevel::High,
516542
)
517543
.await;
518544
}
@@ -542,13 +568,14 @@ where
542568
// 3. Constrain according to disputes:
543569
let (tx, rx) = oneshot::channel();
544570
overseer
545-
.send_msg(
571+
.send_msg_with_priority(
546572
DisputeCoordinatorMessage::DetermineUndisputedChain {
547573
base: (target_number, target_hash),
548574
block_descriptions: subchain_block_descriptions,
549575
tx,
550576
},
551577
std::any::type_name::<Self>(),
578+
PriorityLevel::High,
552579
)
553580
.await;
554581

polkadot/node/service/src/tests.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use futures::channel::oneshot::Receiver;
2020
use polkadot_node_primitives::approval::v2::VrfSignature;
2121
use polkadot_node_subsystem::messages::{AllMessages, BlockDescription};
2222
use polkadot_node_subsystem_util::TimeoutExt;
23+
use polkadot_overseer::{HighPriority, PriorityLevel};
2324
use polkadot_test_client::Sr25519Keyring;
2425
use sp_consensus_babe::{
2526
digests::{CompatibleDigestItem, PreDigest, SecondaryVRFPreDigest},
@@ -55,6 +56,26 @@ impl OverseerHandleT for TestSubsystemSender {
5556
}
5657
}
5758

59+
#[async_trait::async_trait]
60+
impl OverseerHandleWithPriorityT for TestSubsystemSender {
61+
async fn send_msg_with_priority<M: Send + Into<AllMessages>>(
62+
&mut self,
63+
msg: M,
64+
_origin: &'static str,
65+
priority: PriorityLevel,
66+
) {
67+
match priority {
68+
PriorityLevel::High => {
69+
TestSubsystemSender::send_message_with_priority::<HighPriority>(self, msg.into())
70+
.await;
71+
},
72+
PriorityLevel::Normal => {
73+
TestSubsystemSender::send_message(self, msg.into()).await;
74+
},
75+
}
76+
}
77+
}
78+
5879
struct TestHarness {
5980
virtual_overseer: VirtualOverseer,
6081
case_vars: CaseVars,

prdoc/pr_8834.prdoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
title: extend overseer to send priority messages
2+
doc:
3+
- audience: Node Dev
4+
description: |-
5+
Extend overseer to send priority messages, the new functionality is used for sending messages
6+
on the grandpa call path when we call dispute-coordinator and approval-voting in
7+
finality_target_with_longest_chain to make sure we don't block unnecessarily.
8+
9+
crates:
10+
- name: polkadot-node-core-approval-voting-parallel
11+
bump: patch
12+
- name: polkadot-overseer
13+
bump: patch
14+
- name: polkadot-service
15+
bump: patch

0 commit comments

Comments
 (0)