Skip to content

Commit

Permalink
feat(derive): holocene activation
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Sep 25, 2024
1 parent 830a828 commit d1416bb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
10 changes: 10 additions & 0 deletions crates/derive/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ pub enum ResetError {
/// Attributes builder error variant, with [BuilderError].
#[error("Attributes builder error: {0}")]
AttributesBuilder(#[from] BuilderError),
/// A Holocene activation temporary error.
#[error("Holocene activation error")]
HoloceneActivation,
}

impl ResetError {
/// Wrap [self] as a [PipelineErrorKind::Reset].
pub fn reset(self) -> PipelineErrorKind {
PipelineErrorKind::Reset(self)
}
}

/// A decoding error.
Expand Down
11 changes: 11 additions & 0 deletions crates/derive/src/stages/l1_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,19 @@ impl<F: ChainProvider + Send> OriginAdvancer for L1Traversal<F> {
}

crate::set!(ORIGIN_GAUGE, next_l1_origin.number as i64);

self.block = Some(next_l1_origin);
self.done = false;

// If the prev block is not holocene, but the next is, we need to flag this
// so the pipeline driver will reset the pipeline for holocene activation.
let prev_block_holocene =
self.rollup_config.is_holocene_active(self.block.unwrap().timestamp);
let next_block_holocene = self.rollup_config.is_holocene_active(next_l1_origin.timestamp);
if !prev_block_holocene && next_block_holocene {
return Err(ResetError::HoloceneActivation.reset());
}

Ok(())
}
}
Expand Down
56 changes: 32 additions & 24 deletions examples/trusted-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,32 +214,40 @@ async fn sync(cli: cli::Cli) -> Result<()> {
metrics::PIPELINE_STEPS.with_label_values(&["origin_advance"]).inc();
trace!(target: "loop", "Advanced origin");
}
StepResult::OriginAdvanceErr(e) => {
metrics::PIPELINE_STEPS.with_label_values(&["origin_advance_failure"]).inc();
warn!(target: "loop", "Could not advance origin: {:?}", e);
}
StepResult::StepFailed(e) => match e {
PipelineErrorKind::Temporary(e) => {
if matches!(e, PipelineError::NotEnoughData) {
metrics::PIPELINE_STEPS.with_label_values(&["not_enough_data"]).inc();
debug!(target: "loop", "Not enough data to step derivation pipeline");
}
}
PipelineErrorKind::Reset(_) => {
metrics::PIPELINE_STEPS.with_label_values(&["reset"]).inc();
warn!(target: "loop", "Resetting pipeline: {:?}", e);
pipeline
.reset(
cursor.block_info,
pipeline.origin().ok_or(anyhow::anyhow!("Missing origin"))?,
)
.await?;
sr => {
if let StepResult::OriginAdvanceErr(ref e) = sr {
metrics::PIPELINE_STEPS.with_label_values(&["origin_advance_failure"]).inc();
warn!(target: "loop", "Could not advance origin: {:?}", e);
}
_ => {
metrics::PIPELINE_STEPS.with_label_values(&["failure"]).inc();
error!(target: "loop", "Error stepping derivation pipeline: {:?}", e);

match sr {
StepResult::PreparedAttributes | StepResult::AdvancedOrigin => {}
StepResult::OriginAdvanceErr(e) | StepResult::StepFailed(e) => match e {
PipelineErrorKind::Temporary(e) => {
if matches!(e, PipelineError::NotEnoughData) {
metrics::PIPELINE_STEPS
.with_label_values(&["not_enough_data"])
.inc();
debug!(target: "loop", "Not enough data to step derivation pipeline");
}
}
PipelineErrorKind::Reset(_) => {
metrics::PIPELINE_STEPS.with_label_values(&["reset"]).inc();
warn!(target: "loop", "Resetting pipeline: {:?}", e);
pipeline
.reset(
cursor.block_info,
pipeline.origin().ok_or(anyhow::anyhow!("Missing origin"))?,
)
.await?;
}
PipelineErrorKind::Critical(_) => {
metrics::PIPELINE_STEPS.with_label_values(&["failure"]).inc();
error!(target: "loop", "Error stepping derivation pipeline: {:?}", e);
}
},
}
},
}
}

// Peek at the next prepared attributes and validate them.
Expand Down

0 comments on commit d1416bb

Please sign in to comment.