-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(katana): pipeline execution loop with checkpointing (#2741)
- Loading branch information
Showing
18 changed files
with
334 additions
and
41 deletions.
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
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 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 |
---|---|---|
@@ -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.