Skip to content

Commit

Permalink
Added stages to the sync info rpc type (#1079)
Browse files Browse the repository at this point in the history
* added stages detail

* boxed enum

* from hashmap to vec with helper type

* serde alias and renames and dos

* Update crates/rpc-types-eth/src/syncing.rs

Co-authored-by: Matthias Seitz <[email protected]>

* Update crates/rpc-types-eth/src/syncing.rs

Co-authored-by: Matthias Seitz <[email protected]>

* property to pub

---------

Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
loocapro and mattsse authored Jul 19, 2024
1 parent 067cc46 commit 0ddad90
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit 0ddad90

Please sign in to comment.