Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

refactor overseer into proc-macro based pattern #2962

Merged
merged 166 commits into from
Jul 8, 2021
Merged

Conversation

drahnr
Copy link
Contributor

@drahnr drahnr commented Apr 29, 2021

The branch name is historical, this expanded into a refactoring of the Overseer into a pattern to actually allow simpler spawning of modified nodes with subsystems that exhibit modified (malicious and/or broken) behavior besides future compile time checks based on subsystem.

This is stage one and lies the groundwork for further checks:

  • generate the overseer as it is currently
  • provide a builder pattern for overseer construction
  • Avoid AllMessages and .into() in any subsystem, always send the subsystem specific types directly
  • make the overseer macro idempotent and eliminate all leaked types from the current impl

Next steps are covered in #3427


Notes to reviewers:

  • You will find two traits called SubsystemContext, where one binds 3 associated types, the other is a wrapper around it. This was meant to simplifify the trait bounds across all subsystem's generic type Context. In retrospective I am not sure which is better: Subsystem<Message=X> + overseer::Subsystem<Message=X> vs overseer::Subsystem<Message=X, AllMessages=AllMessages, Signal=OverseerSignal, Error=SubsystemError>.

  • Most usages of conversions into AllMessages around fn send_message(..) were removed, instead almost all instances now do the conversion implicitly which removes quite a bit of clutter and will be necessary for [node] Add additional sanitization checks to overseer #3427 anyways.

  • I moved the #[cfg(test)] mod tests; back at the end of the file. It caused a whole lot of duplicate definitions and it's just clearer to have one spot to look for the test module, and that's at the bottom of a file. External or not is imho secondary to that.

  • Most changes are boring trait bounds, so I'd recommend on focusing on the node/overseer/src/lib.rs and more generally on node/{overseer,subsystem}/* where the most relevant changes are.

@drahnr drahnr added A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes labels Apr 29, 2021
@drahnr drahnr self-assigned this Apr 29, 2021
doc/testing.md Outdated Show resolved Hide resolved
doc/testing.md Outdated Show resolved Hide resolved
Cargo.lock Outdated Show resolved Hide resolved
behavior-tests/Cargo.toml Outdated Show resolved Hide resolved
@drahnr drahnr changed the title doc: testing outline testing outline + overseer refactor May 12, 2021
@paritytech paritytech deleted a comment Jul 8, 2021
Copy link
Contributor

@Lldenaurois Lldenaurois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a few small suggestions. Overall, I think this is fine to merge as-is though

node/core/approval-voting/src/import.rs Show resolved Hide resolved
head: Hash,
finalized_number: &Option<BlockNumber>,
) -> SubsystemResult<Vec<BlockImportedCandidates>> {
) -> SubsystemResult<Vec<BlockImportedCandidates>>
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I believe it's standard to have the braces on the same line as the return unless the return is deconstructed (multi-line).


loop {
futures::select! {
m = receiver.next() => match m.unwrap() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: single character variables are a bit mysterious. I would suggest msg = instead of m and res = instead of r

{
fn start(self, ctx: C) -> SpawnedSubsystem {
fn start(self, ctx: Context) -> SpawnedSubsystem {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

number_leaves: 0,
finalized_state: None,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Spaces between functions?

@@ -148,13 +179,14 @@ macro_rules! specialize_requests {
#[doc = "Request `"]
#[doc = $doc_name]
#[doc = "` from the runtime"]
pub async fn $func_name(
pub async fn $func_name (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space

@drahnr
Copy link
Contributor Author

drahnr commented Jul 8, 2021

I'll take care of the nits in a follow up

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. I8-refactor Code needs refactoring. J0-enhancement An additional feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants