Skip to content
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

Added stages to the sync info rpc type #1079

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions crates/rpc-types-eth/src/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::BTreeMap;

/// Syncing info
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncInfo {
/// Starting block
Expand All @@ -16,6 +16,22 @@ pub struct SyncInfo {
pub warp_chunks_amount: Option<U256>,
/// Warp sync snapshot chunks processed.
pub warp_chunks_processed: Option<U256>,
/// The details of the sync stages as an hashmap
/// where the key is the name of the stage and the value is the block number.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub stages: Option<Vec<Stage>>,
}

/// The detail of the sync stages.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Stage {
/// The name of the sync stage.
#[serde(alias = "stage_name")]
pub name: String,
/// Indicates the progress of the sync stage.
#[serde(alias = "block_number", with = "alloy_serde::quantity")]
pub block: u64,
}

/// Peers info
Expand Down Expand Up @@ -99,10 +115,10 @@ pub struct PipProtocolInfo {
}

/// Sync status
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SyncStatus {
/// Info when syncing
Info(SyncInfo),
Info(Box<SyncInfo>),
/// Not syncing
None,
}
Expand All @@ -117,7 +133,7 @@ impl<'de> Deserialize<'de> for SyncStatus {
enum Syncing {
/// When client is synced to the highest block, eth_syncing with return "false"
None(bool),
IsSyncing(SyncInfo),
IsSyncing(Box<SyncInfo>),
}

match Syncing::deserialize(deserializer)? {
Expand Down