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

backing: refactor off of jobs system #5377

Merged
merged 5 commits into from
Apr 27, 2022

Conversation

rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Apr 22, 2022

Part of #4259

This refactors the candidate-backing subsystem not to use the util::jobs framework.

candidate-backing was one of the first subsystems, and it was written in an object-oriented style (as opposed to the functional style which is better for asynchronous code). This meant that some functions had to be changed from &self to &mut self even though it doesn't seem like they need to be - otherwise it would require Context: Sync.

This also changed the behavior of the subsystem overall: previously, each relay-parent's work was spawned in a background task by util::Jobs but now we do all the work in a single task with the exception of actual PoV recovery and candidate validation - that still happens in the background. There's not much heavy work happening in the 'main thread' of candidate backing except for signing messages occasionally (a few for every block), so this shouldn't have a meaningful impact on performance.

The goal of this refactoring is to make it easier to control when candidate-backing 'jobs' actually get cleaned up when we implement #3779 (In particular, #5057, which has more details)

TODO:

  • Refactor the error type using the fatality crate as is done in other subsystems.
  • Refactor run into run and run_until_error, as is done in other subsystems.
  • Test on Versi

@rphmeier rphmeier added 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. labels Apr 22, 2022
Comment on lines +287 to +289
for deactivated in update.deactivated {
jobs.remove(&deactivated);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is almost all we need for async backing - just not deactivating stuff quite as quickly.

Some(a) => a,
};

macro_rules! try_runtime_api {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everything from here onwards has been copied more or less verbatim from the util::JobTrait implementation that I've removed.

While there are improvements to be made, I will not be addressing them in this PR.

loop {
futures::select! {
validated_command = self.background_validation.next() => {
let _span = span.child("process-validation-result");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this span wasn't useful so you won't find it in the refactored code

Some(msg) => {
// we intentionally want spans created in `process_msg` to descend from the
// `span ` which is longer-lived than this ephemeral timing span.
let _timing_span = span.child("process-message");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this span wasn't useful so you won't find it in the refactored code

let mut jobs = HashMap::new();

// TODO [now]: refactor to JFYIError and add a `run_until_error` function
// which actually does this loop
Copy link
Member

Choose a reason for hiding this comment

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

are you planning to address it here or in a follow-up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here (I have a TODO in the description)

@ordian
Copy link
Member

ordian commented Apr 25, 2022

I didn't really look deeply since it the code was mostly copied. Looks good overall. One thing we might improve in a follow-up is taking senders instead of Context in a couple of places.

Good to go once it's fully tested on Versi.

Copy link
Contributor

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

Generally looks good, I'd prefer not passing Context to inner functions unless strictly necessary.

node/core/backing/src/lib.rs Outdated Show resolved Hide resolved
node/core/backing/src/lib.rs Show resolved Hide resolved
@drahnr drahnr self-requested a review April 26, 2022 13:14
@rphmeier
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 3adf622 into master Apr 27, 2022
@paritytech-processbot paritytech-processbot bot deleted the rh-remove-backing-job branch April 27, 2022 22:19
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants