mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 22:41:06 +00:00
refactor overseer into proc-macro based pattern (#2962)
This commit is contained in:
committed by
GitHub
parent
2510bfc5d7
commit
3c9104daff
@@ -29,6 +29,7 @@
|
||||
//! We maintain a rolling window of session indices. This starts as empty
|
||||
|
||||
use polkadot_node_subsystem::{
|
||||
overseer,
|
||||
messages::{
|
||||
RuntimeApiMessage, RuntimeApiRequest, ChainApiMessage, ApprovalDistributionMessage,
|
||||
ChainSelectionMessage,
|
||||
@@ -84,7 +85,7 @@ struct ImportedBlockInfoEnv<'a> {
|
||||
// Computes information about the imported block. Returns `None` if the info couldn't be extracted -
|
||||
// failure to communicate with overseer,
|
||||
async fn imported_block_info(
|
||||
ctx: &mut impl SubsystemContext,
|
||||
ctx: &mut (impl SubsystemContext + overseer::SubsystemContext),
|
||||
env: ImportedBlockInfoEnv<'_>,
|
||||
block_hash: Hash,
|
||||
block_header: &Header,
|
||||
@@ -98,7 +99,7 @@ async fn imported_block_info(
|
||||
ctx.send_message(RuntimeApiMessage::Request(
|
||||
block_hash,
|
||||
RuntimeApiRequest::CandidateEvents(c_tx),
|
||||
).into()).await;
|
||||
)).await;
|
||||
|
||||
let events: Vec<CandidateEvent> = match c_rx.await {
|
||||
Ok(Ok(events)) => events,
|
||||
@@ -120,7 +121,7 @@ async fn imported_block_info(
|
||||
ctx.send_message(RuntimeApiMessage::Request(
|
||||
block_header.parent_hash,
|
||||
RuntimeApiRequest::SessionIndexForChild(s_tx),
|
||||
).into()).await;
|
||||
)).await;
|
||||
|
||||
let session_index = match s_rx.await {
|
||||
Ok(Ok(s)) => s,
|
||||
@@ -161,7 +162,7 @@ async fn imported_block_info(
|
||||
ctx.send_message(RuntimeApiMessage::Request(
|
||||
block_hash,
|
||||
RuntimeApiRequest::CurrentBabeEpoch(s_tx),
|
||||
).into()).await;
|
||||
)).await;
|
||||
|
||||
match s_rx.await {
|
||||
Ok(Ok(s)) => s,
|
||||
@@ -284,20 +285,21 @@ pub struct BlockImportedCandidates {
|
||||
/// * and return information about all candidates imported under each block.
|
||||
///
|
||||
/// It is the responsibility of the caller to schedule wakeups for each block.
|
||||
pub(crate) async fn handle_new_head<'a>(
|
||||
ctx: &mut impl SubsystemContext,
|
||||
pub(crate) async fn handle_new_head(
|
||||
ctx: &mut (impl SubsystemContext + overseer::SubsystemContext),
|
||||
state: &mut State,
|
||||
db: &mut OverlayedBackend<'a, impl Backend>,
|
||||
db: &mut OverlayedBackend<'_, impl Backend>,
|
||||
head: Hash,
|
||||
finalized_number: &Option<BlockNumber>,
|
||||
) -> SubsystemResult<Vec<BlockImportedCandidates>> {
|
||||
) -> SubsystemResult<Vec<BlockImportedCandidates>>
|
||||
{
|
||||
// Update session info based on most recent head.
|
||||
|
||||
let mut span = jaeger::Span::new(head, "approval-checking-import");
|
||||
|
||||
let header = {
|
||||
let (h_tx, h_rx) = oneshot::channel();
|
||||
ctx.send_message(ChainApiMessage::BlockHeader(head, h_tx).into()).await;
|
||||
ctx.send_message(ChainApiMessage::BlockHeader(head, h_tx)).await;
|
||||
|
||||
match h_rx.await? {
|
||||
Err(e) => {
|
||||
@@ -375,7 +377,7 @@ pub(crate) async fn handle_new_head<'a>(
|
||||
// It's possible that we've lost a race with finality.
|
||||
let (tx, rx) = oneshot::channel();
|
||||
ctx.send_message(
|
||||
ChainApiMessage::FinalizedBlockHash(block_header.number.clone(), tx).into()
|
||||
ChainApiMessage::FinalizedBlockHash(block_header.number.clone(), tx)
|
||||
).await;
|
||||
|
||||
let lost_to_finality = match rx.await {
|
||||
@@ -469,7 +471,7 @@ pub(crate) async fn handle_new_head<'a>(
|
||||
|
||||
// If all bits are already set, then send an approve message.
|
||||
if approved_bitfield.count_ones() == approved_bitfield.len() {
|
||||
ctx.send_message(ChainSelectionMessage::Approved(block_hash).into()).await;
|
||||
ctx.send_message(ChainSelectionMessage::Approved(block_hash)).await;
|
||||
}
|
||||
|
||||
let block_entry = v1::BlockEntry {
|
||||
@@ -498,7 +500,7 @@ pub(crate) async fn handle_new_head<'a>(
|
||||
|
||||
// Notify chain-selection of all approved hashes.
|
||||
for hash in approved_hashes {
|
||||
ctx.send_message(ChainSelectionMessage::Approved(hash).into()).await;
|
||||
ctx.send_message(ChainSelectionMessage::Approved(hash)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +553,7 @@ pub(crate) async fn handle_new_head<'a>(
|
||||
"Informing distribution of newly imported chain",
|
||||
);
|
||||
|
||||
ctx.send_unbounded_message(ApprovalDistributionMessage::NewBlocks(approval_meta).into());
|
||||
ctx.send_unbounded_message(ApprovalDistributionMessage::NewBlocks(approval_meta));
|
||||
|
||||
Ok(imported_candidates)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ use polkadot_node_subsystem::{
|
||||
AvailabilityRecoveryMessage, ChainSelectionMessage,
|
||||
},
|
||||
errors::RecoveryError,
|
||||
Subsystem, SubsystemContext, SubsystemError, SubsystemResult, SpawnedSubsystem,
|
||||
overseer::{self, SubsystemSender as _}, SubsystemContext, SubsystemError, SubsystemResult, SpawnedSubsystem,
|
||||
FromOverseer, OverseerSignal, SubsystemSender,
|
||||
};
|
||||
use polkadot_node_subsystem_util::{
|
||||
@@ -333,12 +333,15 @@ impl ApprovalVotingSubsystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> Subsystem<C> for ApprovalVotingSubsystem
|
||||
where C: SubsystemContext<Message = ApprovalVotingMessage>
|
||||
impl<Context> overseer::Subsystem<Context, SubsystemError> for ApprovalVotingSubsystem
|
||||
where
|
||||
Context: SubsystemContext<Message = ApprovalVotingMessage>,
|
||||
Context: overseer::SubsystemContext<Message = ApprovalVotingMessage>,
|
||||
{
|
||||
fn start(self, ctx: C) -> SpawnedSubsystem {
|
||||
|
||||
fn start(self, ctx: Context) -> SpawnedSubsystem {
|
||||
let backend = DbBackend::new(self.db.clone(), self.db_config);
|
||||
let future = run::<DbBackend, C>(
|
||||
let future = run::<DbBackend, Context>(
|
||||
ctx,
|
||||
self,
|
||||
Box::new(SystemClock),
|
||||
@@ -663,15 +666,16 @@ enum Action {
|
||||
Conclude,
|
||||
}
|
||||
|
||||
async fn run<B, C>(
|
||||
mut ctx: C,
|
||||
async fn run<B, Context>(
|
||||
mut ctx: Context,
|
||||
mut subsystem: ApprovalVotingSubsystem,
|
||||
clock: Box<dyn Clock + Send + Sync>,
|
||||
assignment_criteria: Box<dyn AssignmentCriteria + Send + Sync>,
|
||||
mut backend: B,
|
||||
) -> SubsystemResult<()>
|
||||
where
|
||||
C: SubsystemContext<Message = ApprovalVotingMessage>,
|
||||
Context: SubsystemContext<Message = ApprovalVotingMessage>,
|
||||
Context: overseer::SubsystemContext<Message = ApprovalVotingMessage>,
|
||||
B: Backend,
|
||||
{
|
||||
let mut state = State {
|
||||
@@ -797,7 +801,7 @@ async fn run<B, C>(
|
||||
//
|
||||
// returns `true` if any of the actions was a `Conclude` command.
|
||||
async fn handle_actions(
|
||||
ctx: &mut impl SubsystemContext,
|
||||
ctx: &mut (impl SubsystemContext<Message = ApprovalVotingMessage> + overseer::SubsystemContext<Message = ApprovalVotingMessage>),
|
||||
state: &mut State,
|
||||
overlayed_db: &mut OverlayedBackend<'_, impl Backend>,
|
||||
metrics: &Metrics,
|
||||
@@ -861,7 +865,7 @@ async fn handle_actions(
|
||||
ctx.send_unbounded_message(ApprovalDistributionMessage::DistributeAssignment(
|
||||
indirect_cert,
|
||||
candidate_index,
|
||||
).into());
|
||||
));
|
||||
|
||||
match approvals_cache.get(&candidate_hash) {
|
||||
Some(ApprovalOutcome::Approved) => {
|
||||
@@ -902,14 +906,14 @@ async fn handle_actions(
|
||||
}
|
||||
}
|
||||
Action::NoteApprovedInChainSelection(block_hash) => {
|
||||
ctx.send_message(ChainSelectionMessage::Approved(block_hash).into()).await;
|
||||
ctx.send_message(ChainSelectionMessage::Approved(block_hash)).await;
|
||||
}
|
||||
Action::BecomeActive => {
|
||||
*mode = Mode::Active;
|
||||
|
||||
let messages = distribution_messages_for_activation(overlayed_db)?;
|
||||
|
||||
ctx.send_messages(messages.into_iter().map(Into::into)).await;
|
||||
ctx.send_messages(messages.into_iter()).await;
|
||||
}
|
||||
Action::Conclude => { conclude = true; }
|
||||
}
|
||||
@@ -1017,7 +1021,7 @@ fn distribution_messages_for_activation(
|
||||
|
||||
// Handle an incoming signal from the overseer. Returns true if execution should conclude.
|
||||
async fn handle_from_overseer(
|
||||
ctx: &mut impl SubsystemContext,
|
||||
ctx: &mut (impl SubsystemContext<Message = ApprovalVotingMessage> + overseer::SubsystemContext<Message = ApprovalVotingMessage>),
|
||||
state: &mut State,
|
||||
db: &mut OverlayedBackend<'_, impl Backend>,
|
||||
metrics: &Metrics,
|
||||
@@ -1130,7 +1134,7 @@ async fn handle_from_overseer(
|
||||
}
|
||||
|
||||
async fn handle_approved_ancestor(
|
||||
ctx: &mut impl SubsystemContext,
|
||||
ctx: &mut (impl SubsystemContext + overseer::SubsystemContext),
|
||||
db: &OverlayedBackend<'_, impl Backend>,
|
||||
target: Hash,
|
||||
lower_bound: BlockNumber,
|
||||
@@ -1149,7 +1153,7 @@ async fn handle_approved_ancestor(
|
||||
let target_number = {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
ctx.send_message(ChainApiMessage::BlockNumber(target, tx).into()).await;
|
||||
ctx.send_message(ChainApiMessage::BlockNumber(target, tx)).await;
|
||||
|
||||
match rx.await {
|
||||
Ok(Ok(Some(n))) => n,
|
||||
@@ -1173,7 +1177,7 @@ async fn handle_approved_ancestor(
|
||||
hash: target,
|
||||
k: (target_number - (lower_bound + 1)) as usize,
|
||||
response_channel: tx,
|
||||
}.into()).await;
|
||||
}).await;
|
||||
|
||||
match rx.await {
|
||||
Ok(Ok(a)) => a,
|
||||
@@ -1994,7 +1998,7 @@ fn process_wakeup(
|
||||
// spawned. When the background work is no longer needed, the `AbortHandle` should be dropped
|
||||
// to cancel the background work and any requests it has spawned.
|
||||
async fn launch_approval(
|
||||
ctx: &mut impl SubsystemContext,
|
||||
ctx: &mut (impl SubsystemContext<Message = ApprovalVotingMessage> + overseer::SubsystemContext<Message = ApprovalVotingMessage>),
|
||||
metrics: Metrics,
|
||||
session_index: SessionIndex,
|
||||
candidate: CandidateReceipt,
|
||||
@@ -2043,7 +2047,7 @@ async fn launch_approval(
|
||||
session_index,
|
||||
Some(backing_group),
|
||||
a_tx,
|
||||
).into()).await;
|
||||
)).await;
|
||||
|
||||
ctx.send_message(
|
||||
RuntimeApiMessage::Request(
|
||||
@@ -2052,7 +2056,7 @@ async fn launch_approval(
|
||||
candidate.descriptor.validation_code_hash,
|
||||
code_tx,
|
||||
),
|
||||
).into()
|
||||
)
|
||||
).await;
|
||||
|
||||
let candidate = candidate.clone();
|
||||
|
||||
Reference in New Issue
Block a user