-
Notifications
You must be signed in to change notification settings - Fork 202
feat(katana): pipeline execution loop with checkpointing #2741
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b598216
stage checkpoint provider
kariy 8d9ad7e
make blockchain provider cloneable
kariy a2e8714
pipeline syncing loop
kariy 976f762
fmt
kariy 78c1206
remove unused trait
kariy dff6b6d
add pipeline diagram
kariy b1c569c
fix tests
kariy 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 hidden or 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 hidden or 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 hidden or 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,35 @@ | ||
# Syncing pipeline | ||
|
||
```mermaid | ||
flowchart TD | ||
A[Start Pipeline Run] --> B[Initialize chunk_tip] | ||
|
||
B --> D{Process Blocks in Chunks} | ||
D --> E[run_once_until] | ||
|
||
%% run_once_until subflow | ||
E --> S1[For each Stage] | ||
S1 --> S2[Get Stage Checkpoint] | ||
S2 --> S3{Checkpoint >= Target?} | ||
S3 -->|Yes| S4[Skip Stage] | ||
S3 -->|No| S5[Execute Stage<br>from checkpoint+1 to target] | ||
S5 --> S6[Update Stage Checkpoint] | ||
S6 --> S1 | ||
S4 --> S1 | ||
|
||
S1 -->|All Stages Complete| F{Reached Target Tip?} | ||
F -->|No| G[Increment chunk_tip by<br>chunk_size] | ||
G --> D | ||
|
||
F -->|Yes| H[Wait for New Tip] | ||
H -->|New Tip Received| D | ||
H -->|Channel Closed| I[Pipeline Complete] | ||
|
||
style A fill:#f9f,stroke:#333 | ||
style I fill:#f96,stroke:#333 | ||
|
||
%% Example annotations | ||
classDef note fill:#fff,stroke:#333,stroke-dasharray: 5 5 | ||
N1[For example: Tip=1000<br>chunk_size=100<br>Processes: 0-100, 100-200, etc]:::note | ||
N1 -.-> D | ||
``` |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,34 +1,38 @@ | ||
use katana_primitives::block::BlockNumber; | ||
use katana_provider::error::ProviderError; | ||
|
||
mod sequencing; | ||
|
||
pub use sequencing::Sequencing; | ||
|
||
/// The result type of a stage execution. See [Stage::execute]. | ||
pub type StageResult = Result<(), Error>; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub enum StageId { | ||
Sequencing, | ||
#[derive(Debug, Default, Clone)] | ||
pub struct StageExecutionInput { | ||
pub from: BlockNumber, | ||
pub to: BlockNumber, | ||
} | ||
|
||
impl core::fmt::Display for StageId { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
StageId::Sequencing => write!(f, "Sequencing"), | ||
} | ||
} | ||
#[derive(Debug, Default)] | ||
pub struct StageExecutionOutput { | ||
pub last_block_processed: BlockNumber, | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Provider(#[from] ProviderError), | ||
|
||
#[error(transparent)] | ||
Other(#[from] anyhow::Error), | ||
} | ||
|
||
#[async_trait::async_trait] | ||
pub trait Stage: Send + Sync { | ||
/// Returns the id which uniquely identifies the stage. | ||
fn id(&self) -> StageId; | ||
fn id(&self) -> &'static str; | ||
|
||
/// Executes the stage. | ||
async fn execute(&mut self) -> StageResult; | ||
async fn execute(&mut self, input: &StageExecutionInput) -> StageResult; | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.