Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split async/sync work in stages #4636

Merged
merged 13 commits into from
Nov 17, 2023
Merged

Conversation

onbjerg
Copy link
Member

@onbjerg onbjerg commented Sep 18, 2023

This is essentially just #4215 but renamed to better reflect what the PR will now be about.

Previously, most of the work in #4215 was to try and remove the Send + Sync bounds for DbTx where possible to make it work with redb, however the transactions have since been made Send + Sync upstream so that is no longer needed.

Instead, this will continue work on splitting async and sync work in the stages into two parts, inspired by tower's Service trait: async work will be done in poll_ready, which will tell the caller when the stage is ready to be executed, and sync work (incl. writing to the database) will be performed in execute as normal.

This will make it a lot clearer when things block and when they do not; most stages block in execute and do not really leverage async at all, some notable exceptions being the header and bodies stage.

Assumptions

  • It is assumed that unwinds will never need any async work done, so poll_ready is only required to be called before execute

(Rebasing newer work and pushing in a bit)

@onbjerg onbjerg added A-staged-sync Related to staged sync (pipelines and stages) C-debt Refactor of code section that is hard to understand or maintain labels Sep 18, 2023
@onbjerg onbjerg force-pushed the onbjerg/stage-poll-ready branch from e47ed97 to 2f582ed Compare September 18, 2023 18:26
@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label Oct 11, 2023
@github-actions github-actions bot closed this Oct 18, 2023
@rkrasiuk rkrasiuk reopened this Nov 13, 2023
@rkrasiuk rkrasiuk added M-prevent-stale Prevents old inactive issues/PRs from being closed due to inactivity and removed S-stale This issue/PR is stale and will close with no further activity labels Nov 13, 2023
@rkrasiuk rkrasiuk force-pushed the onbjerg/stage-poll-ready branch from 2f582ed to 661876f Compare November 15, 2023 08:49
@rkrasiuk rkrasiuk marked this pull request as ready for review November 15, 2023 11:09
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this looks great!

I like this a lot.
some style nits

bin/reth/src/stage/dump/hashing_account.rs Outdated Show resolved Hide resolved
bin/reth/src/stage/dump/hashing_storage.rs Outdated Show resolved Hide resolved
bin/reth/src/stage/dump/merkle.rs Outdated Show resolved Hide resolved
crates/stages/src/pipeline/mod.rs Outdated Show resolved Hide resolved
crates/stages/src/stage.rs Outdated Show resolved Hide resolved
crates/stages/src/stage.rs Outdated Show resolved Hide resolved
@rkrasiuk rkrasiuk force-pushed the onbjerg/stage-poll-ready branch from 4ffb880 to 0a456c8 Compare November 17, 2023 19:34
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm, some suggestions that could be done as followups

I'd also suggest renaming ExecInput to ExecContext?

{
input.checkpoint = Some(stage_progress);
loop {
poll_fn(|cx| exec_stage.poll_execute_ready(cx, input)).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

we add an extension trait with a helper function that does this:

https://docs.rs/tower/latest/tower/trait.ServiceExt.html#method.ready

but perhaps not worth it, maybe in a followup

pub consensus: Arc<dyn Consensus>,
downloader: D,
/// Block response buffer.
buffer: Vec<BlockResponse>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

these could probably be an Option, right?
with the assumption that calling execute before ready can panic

but this is fine

Comment on lines +38 to +39
/// Database handle.
provider: Provider,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this a lot, no more fiddling with the db types directly,
we could also box this I think

@rkrasiuk rkrasiuk force-pushed the onbjerg/stage-poll-ready branch from 1cc5a4c to 9bb2e44 Compare November 17, 2023 21:02
@rkrasiuk rkrasiuk enabled auto-merge November 17, 2023 21:08
@rkrasiuk rkrasiuk added this pull request to the merge queue Nov 17, 2023
Merged via the queue into main with commit db5d01e Nov 17, 2023
25 checks passed
@rkrasiuk rkrasiuk deleted the onbjerg/stage-poll-ready branch November 17, 2023 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-staged-sync Related to staged sync (pipelines and stages) C-debt Refactor of code section that is hard to understand or maintain M-prevent-stale Prevents old inactive issues/PRs from being closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants