Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: handle SyncingStatus from erigon #2700

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
91 changes: 90 additions & 1 deletion ethers-core/src/types/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ impl<'de> Deserialize<'de> for SyncingStatus {
/// > highestBlock: QUANTITY - The estimated highest block
///
/// Geth returns additional fields: <https://github.com/ethereum/go-ethereum/blob/0ce494b60cd00d70f1f9f2dd0b9bfbd76204168a/ethclient/ethclient.go#L597-L617>
///
/// Erigon does not return the startingBlock field and also returns an additional staging field <https://github.com/ledgerwatch/erigon/blob/6a1bb1dff1deca7a50d66bfbc9e0b89bb4e335a1/turbo/jsonrpc/eth_system.go#L70-L74>
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncProgress {
pub current_block: U64,
pub highest_block: U64,
pub starting_block: U64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub stages: Option<Vec<SyncStage>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub starting_block: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pulled_states: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -98,6 +103,12 @@ pub struct SyncProgress {
pub synced_storage_bytes: Option<U64>,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct SyncStage {
pub stage_name: String,
pub block_number: U64,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -132,6 +143,84 @@ mod tests {
}
}

// <https://github.com/ledgerwatch/erigon/blob/6a1bb1dff1deca7a50d66bfbc9e0b89bb4e335a1/turbo/jsonrpc/eth_system.go#L70-L74>
#[test]
fn deserialize_sync_erigon() {
let s = r#"{
"currentBlock": "0x11ef283",
"highestBlock": "0x11ef284",
"stages": [
{
"block_number": "0x11ef283",
"stage_name": "Snapshots"
},
{
"block_number": "0x11ef284",
"stage_name": "Headers"
},
{
"block_number": "0x11ef284",
"stage_name": "BlockHashes"
},
{
"block_number": "0x11ef284",
"stage_name": "Bodies"
},
{
"block_number": "0x11ef284",
"stage_name": "Senders"
},
{
"block_number": "0x11ef284",
"stage_name": "Execution"
},
{
"block_number": "0x0",
"stage_name": "Translation"
},
{
"block_number": "0x11ef284",
"stage_name": "HashState"
},
{
"block_number": "0x11ef284",
"stage_name": "IntermediateHashes"
},
{
"block_number": "0x11ef283",
"stage_name": "AccountHistoryIndex"
},
{
"block_number": "0x11ef283",
"stage_name": "StorageHistoryIndex"
},
{
"block_number": "0x11ef283",
"stage_name": "LogIndex"
},
{
"block_number": "0x11ef284",
"stage_name": "CallTraces"
},
{
"block_number": "0x11ef283",
"stage_name": "TxLookup"
},
{
"block_number": "0x11ef283",
"stage_name": "Finish"
}
]}"#;

let sync: SyncingStatus = serde_json::from_str(s).unwrap();
match sync {
SyncingStatus::IsFalse => {
panic!("unexpected variant")
}
SyncingStatus::IsSyncing(_) => {}
}
}

#[test]
fn deserialize_sync_minimal() {
let s = r#"{
Expand Down