mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
feat(bin): improve status logs (#5518)
This commit is contained in:
@@ -5,10 +5,7 @@ use crate::{
|
||||
use bytes::{Buf, BufMut};
|
||||
use reth_codecs::{derive_arbitrary, main_codec, Compact};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fmt::{Display, Formatter},
|
||||
ops::RangeInclusive,
|
||||
};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
/// Saves the progress of Merkle stage.
|
||||
#[derive(Default, Debug, Clone, PartialEq)]
|
||||
@@ -169,9 +166,16 @@ pub struct EntitiesCheckpoint {
|
||||
pub total: u64,
|
||||
}
|
||||
|
||||
impl Display for EntitiesCheckpoint {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:.2}%", 100.0 * self.processed as f64 / self.total as f64)
|
||||
impl EntitiesCheckpoint {
|
||||
/// Formats entities checkpoint as percentage, i.e. `processed / total`.
|
||||
///
|
||||
/// Return [None] if `total == 0`.
|
||||
pub fn fmt_percentage(&self) -> Option<String> {
|
||||
if self.total == 0 {
|
||||
return None
|
||||
}
|
||||
|
||||
Some(format!("{:.2}%", 100.0 * self.processed as f64 / self.total as f64))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use crate::stage::{ExecOutput, UnwindInput, UnwindOutput};
|
||||
use reth_primitives::stage::{StageCheckpoint, StageId};
|
||||
use reth_primitives::{
|
||||
stage::{StageCheckpoint, StageId},
|
||||
BlockNumber,
|
||||
};
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
/// An event emitted by a [Pipeline][crate::Pipeline].
|
||||
@@ -12,13 +15,15 @@ use std::fmt::{Display, Formatter};
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum PipelineEvent {
|
||||
/// Emitted when a stage is about to be run.
|
||||
Running {
|
||||
Run {
|
||||
/// Pipeline stages progress.
|
||||
pipeline_stages_progress: PipelineStagesProgress,
|
||||
/// The stage that is about to be run.
|
||||
stage_id: StageId,
|
||||
/// The previous checkpoint of the stage.
|
||||
checkpoint: Option<StageCheckpoint>,
|
||||
/// The block number up to which the stage is running, if known.
|
||||
target: Option<BlockNumber>,
|
||||
},
|
||||
/// Emitted when a stage has run a single time.
|
||||
Ran {
|
||||
@@ -30,7 +35,7 @@ pub enum PipelineEvent {
|
||||
result: ExecOutput,
|
||||
},
|
||||
/// Emitted when a stage is about to be unwound.
|
||||
Unwinding {
|
||||
Unwind {
|
||||
/// The stage that is about to be unwound.
|
||||
stage_id: StageId,
|
||||
/// The unwind parameters.
|
||||
|
||||
@@ -290,7 +290,7 @@ where
|
||||
);
|
||||
while checkpoint.block_number > to {
|
||||
let input = UnwindInput { checkpoint, unwind_to: to, bad_block };
|
||||
self.listeners.notify(PipelineEvent::Unwinding { stage_id, input });
|
||||
self.listeners.notify(PipelineEvent::Unwind { stage_id, input });
|
||||
|
||||
let output = stage.unwind(&provider_rw, input);
|
||||
match output {
|
||||
@@ -378,13 +378,14 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
self.listeners.notify(PipelineEvent::Running {
|
||||
self.listeners.notify(PipelineEvent::Run {
|
||||
pipeline_stages_progress: event::PipelineStagesProgress {
|
||||
current: stage_index + 1,
|
||||
total: total_stages,
|
||||
},
|
||||
stage_id,
|
||||
checkpoint: prev_checkpoint,
|
||||
target,
|
||||
});
|
||||
|
||||
let provider_rw = factory.provider_rw()?;
|
||||
@@ -393,26 +394,6 @@ where
|
||||
made_progress |=
|
||||
checkpoint.block_number != prev_checkpoint.unwrap_or_default().block_number;
|
||||
|
||||
if let Some(progress) = checkpoint.entities() {
|
||||
debug!(
|
||||
target: "sync::pipeline",
|
||||
stage = %stage_id,
|
||||
checkpoint = checkpoint.block_number,
|
||||
?target,
|
||||
%progress,
|
||||
%done,
|
||||
"Stage committed progress"
|
||||
);
|
||||
} else {
|
||||
debug!(
|
||||
target: "sync::pipeline",
|
||||
stage = %stage_id,
|
||||
checkpoint = checkpoint.block_number,
|
||||
?target,
|
||||
%done,
|
||||
"Stage committed progress"
|
||||
);
|
||||
}
|
||||
if let Some(metrics_tx) = &mut self.metrics_tx {
|
||||
let _ = metrics_tx.send(MetricEvent::StageCheckpoint {
|
||||
stage_id,
|
||||
@@ -608,20 +589,22 @@ mod tests {
|
||||
assert_eq!(
|
||||
events.collect::<Vec<PipelineEvent>>().await,
|
||||
vec![
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
result: ExecOutput { checkpoint: StageCheckpoint::new(20), done: true },
|
||||
},
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 2 },
|
||||
stage_id: StageId::Other("B"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 2 },
|
||||
@@ -671,30 +654,33 @@ mod tests {
|
||||
events.collect::<Vec<PipelineEvent>>().await,
|
||||
vec![
|
||||
// Executing
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 3 },
|
||||
stage_id: StageId::Other("A"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 3 },
|
||||
stage_id: StageId::Other("A"),
|
||||
result: ExecOutput { checkpoint: StageCheckpoint::new(100), done: true },
|
||||
},
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 3 },
|
||||
stage_id: StageId::Other("B"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 3 },
|
||||
stage_id: StageId::Other("B"),
|
||||
result: ExecOutput { checkpoint: StageCheckpoint::new(10), done: true },
|
||||
},
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 3, total: 3 },
|
||||
stage_id: StageId::Other("C"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 3, total: 3 },
|
||||
@@ -702,7 +688,7 @@ mod tests {
|
||||
result: ExecOutput { checkpoint: StageCheckpoint::new(20), done: true },
|
||||
},
|
||||
// Unwinding
|
||||
PipelineEvent::Unwinding {
|
||||
PipelineEvent::Unwind {
|
||||
stage_id: StageId::Other("C"),
|
||||
input: UnwindInput {
|
||||
checkpoint: StageCheckpoint::new(20),
|
||||
@@ -714,7 +700,7 @@ mod tests {
|
||||
stage_id: StageId::Other("C"),
|
||||
result: UnwindOutput { checkpoint: StageCheckpoint::new(1) },
|
||||
},
|
||||
PipelineEvent::Unwinding {
|
||||
PipelineEvent::Unwind {
|
||||
stage_id: StageId::Other("B"),
|
||||
input: UnwindInput {
|
||||
checkpoint: StageCheckpoint::new(10),
|
||||
@@ -726,7 +712,7 @@ mod tests {
|
||||
stage_id: StageId::Other("B"),
|
||||
result: UnwindOutput { checkpoint: StageCheckpoint::new(1) },
|
||||
},
|
||||
PipelineEvent::Unwinding {
|
||||
PipelineEvent::Unwind {
|
||||
stage_id: StageId::Other("A"),
|
||||
input: UnwindInput {
|
||||
checkpoint: StageCheckpoint::new(100),
|
||||
@@ -775,20 +761,22 @@ mod tests {
|
||||
events.collect::<Vec<PipelineEvent>>().await,
|
||||
vec![
|
||||
// Executing
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
result: ExecOutput { checkpoint: StageCheckpoint::new(100), done: true },
|
||||
},
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 2 },
|
||||
stage_id: StageId::Other("B"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 2 },
|
||||
@@ -798,7 +786,7 @@ mod tests {
|
||||
// Unwinding
|
||||
// Nothing to unwind in stage "B"
|
||||
PipelineEvent::Skipped { stage_id: StageId::Other("B") },
|
||||
PipelineEvent::Unwinding {
|
||||
PipelineEvent::Unwind {
|
||||
stage_id: StageId::Other("A"),
|
||||
input: UnwindInput {
|
||||
checkpoint: StageCheckpoint::new(100),
|
||||
@@ -865,23 +853,25 @@ mod tests {
|
||||
assert_eq!(
|
||||
events.collect::<Vec<PipelineEvent>>().await,
|
||||
vec![
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
result: ExecOutput { checkpoint: StageCheckpoint::new(10), done: true },
|
||||
},
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 2 },
|
||||
stage_id: StageId::Other("B"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Error { stage_id: StageId::Other("B") },
|
||||
PipelineEvent::Unwinding {
|
||||
PipelineEvent::Unwind {
|
||||
stage_id: StageId::Other("A"),
|
||||
input: UnwindInput {
|
||||
checkpoint: StageCheckpoint::new(10),
|
||||
@@ -893,20 +883,22 @@ mod tests {
|
||||
stage_id: StageId::Other("A"),
|
||||
result: UnwindOutput { checkpoint: StageCheckpoint::new(0) },
|
||||
},
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
checkpoint: Some(StageCheckpoint::new(0))
|
||||
checkpoint: Some(StageCheckpoint::new(0)),
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 1, total: 2 },
|
||||
stage_id: StageId::Other("A"),
|
||||
result: ExecOutput { checkpoint: StageCheckpoint::new(10), done: true },
|
||||
},
|
||||
PipelineEvent::Running {
|
||||
PipelineEvent::Run {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 2 },
|
||||
stage_id: StageId::Other("B"),
|
||||
checkpoint: None
|
||||
checkpoint: None,
|
||||
target: Some(10),
|
||||
},
|
||||
PipelineEvent::Ran {
|
||||
pipeline_stages_progress: PipelineStagesProgress { current: 2, total: 2 },
|
||||
|
||||
Reference in New Issue
Block a user