-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: pipeline builder #1017
Merged
Merged
feat: pipeline builder #1017
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
703a70b
fix: honor `serde` feature in `reth-network`
onbjerg 3ed30b9
feat: `PipelineBuilder`
onbjerg 2d6944b
refactor: smol nit
onbjerg 8973d57
test: fix port of events in pipeline tests
onbjerg da5c750
refactor: return `PipelineEvent` event stream
onbjerg b5306b9
docs: rephrasing
onbjerg 9f5e4aa
test: fix doctest
onbjerg 5f2a7cd
chore: add `TransactionLookupStage`
onbjerg 9135943
chore: add history indexing stages
onbjerg 50a9d1c
docs: explain `MerkleStage` split
onbjerg 0429786
chore: add `reth-stages` prelude module
onbjerg 6a80568
chore: naming
onbjerg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::{pipeline::QueuedStage, Pipeline, Stage, StageSet}; | ||
use reth_db::database::Database; | ||
use reth_interfaces::sync::{NoopSyncStateUpdate, SyncStateUpdater}; | ||
use reth_primitives::BlockNumber; | ||
|
||
/// Builds a [`Pipeline`]. | ||
#[derive(Debug)] | ||
#[must_use = "call `build` to construct the pipeline"] | ||
pub struct PipelineBuilder<DB, U = NoopSyncStateUpdate> | ||
where | ||
DB: Database, | ||
U: SyncStateUpdater, | ||
{ | ||
pipeline: Pipeline<DB, U>, | ||
} | ||
|
||
impl<DB: Database, U: SyncStateUpdater> Default for PipelineBuilder<DB, U> { | ||
fn default() -> Self { | ||
Self { pipeline: Pipeline::default() } | ||
} | ||
} | ||
|
||
impl<DB, U> PipelineBuilder<DB, U> | ||
where | ||
DB: Database, | ||
U: SyncStateUpdater, | ||
{ | ||
/// Add a stage to the pipeline. | ||
pub fn add_stage<S>(mut self, stage: S) -> Self | ||
where | ||
S: Stage<DB> + 'static, | ||
{ | ||
self.pipeline.stages.push(QueuedStage { stage: Box::new(stage) }); | ||
self | ||
} | ||
|
||
/// Add a set of stages to the pipeline. | ||
/// | ||
/// Stages can be grouped into a set by using a [`StageSet`]. | ||
/// | ||
/// To customize the stages in the set (reorder, disable, insert a stage) call | ||
/// [`build`][StageSet::build] on the set which will convert it to a | ||
/// [`StageSetBuilder`][crate::StageSetBuilder]. | ||
pub fn add_stages<Set: StageSet<DB>>(mut self, set: Set) -> Self { | ||
for stage in set.build().finish() { | ||
self.pipeline.stages.push(QueuedStage { stage }); | ||
} | ||
self | ||
} | ||
|
||
/// Set the target block. | ||
/// | ||
/// Once this block is reached, the pipeline will stop. | ||
pub fn with_max_block(mut self, block: BlockNumber) -> Self { | ||
self.pipeline.max_block = Some(block); | ||
self | ||
} | ||
|
||
/// Set a [SyncStateUpdater]. | ||
pub fn with_sync_state_updater(mut self, updater: U) -> Self { | ||
self.pipeline.sync_state_updater = Some(updater); | ||
self | ||
} | ||
|
||
/// Builds the final [`Pipeline`]. | ||
pub fn build(self) -> Pipeline<DB, U> { | ||
self.pipeline | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uses the new stage sets: as mentioned, I want to make either the stage sets or the stages optionally ser/de to replace
StagesConfig
. This would make this a lot easier. Primary hurdles are:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this abstraction.