Skip to content

Commit

Permalink
Added sync stages status to eth_sync (#10042)
Browse files Browse the repository at this point in the history
  • Loading branch information
loocapro authored Aug 3, 2024
1 parent 1290260 commit 52cdcf0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use reth_network_api::NetworkInfo;
use reth_node_api::{BuilderProvider, FullNodeComponents, FullNodeTypes};
use reth_provider::{
BlockIdReader, BlockNumReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider,
StateProviderFactory,
StageCheckpointReader, StateProviderFactory,
};
use reth_rpc::eth::{core::EthApiInner, DevSigner};
use reth_rpc_eth_api::{
Expand Down Expand Up @@ -108,7 +108,7 @@ where
N: FullNodeComponents,
{
#[inline]
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader {
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader {
self.inner.provider()
}

Expand Down
17 changes: 13 additions & 4 deletions crates/rpc/rpc-eth-api/src/helpers/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use reth_chainspec::{ChainInfo, ChainSpec};
use reth_errors::{RethError, RethResult};
use reth_network_api::NetworkInfo;
use reth_primitives::{Address, U256, U64};
use reth_provider::{BlockNumReader, ChainSpecProvider};
use reth_rpc_types::{SyncInfo, SyncStatus};
use reth_provider::{BlockNumReader, ChainSpecProvider, StageCheckpointReader};
use reth_rpc_types::{Stage, SyncInfo, SyncStatus};

use super::EthSigner;

Expand All @@ -18,7 +18,7 @@ use super::EthSigner;
#[auto_impl::auto_impl(&, Arc)]
pub trait EthApiSpec: Send + Sync {
/// Returns a handle for reading data from disk.
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader;
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader;

/// Returns a handle for reading network data summary.
fn network(&self) -> impl NetworkInfo;
Expand Down Expand Up @@ -63,13 +63,22 @@ pub trait EthApiSpec: Send + Sync {
let current_block = U256::from(
self.provider().chain_info().map(|info| info.best_number).unwrap_or_default(),
);

let stages = self
.provider()
.get_all_checkpoints()
.unwrap_or_default()
.into_iter()
.map(|(name, checkpoint)| Stage { name, block: checkpoint.block_number })
.collect();

SyncStatus::Info(Box::new(SyncInfo {
starting_block: self.starting_block(),
current_block,
highest_block: current_block,
warp_chunks_amount: None,
warp_chunks_processed: None,
stages: None,
stages: Some(stages),
}))
} else {
SyncStatus::None
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc/src/eth/helpers/spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use reth_network_api::NetworkInfo;
use reth_primitives::U256;
use reth_provider::{BlockNumReader, ChainSpecProvider};
use reth_provider::{BlockNumReader, ChainSpecProvider, StageCheckpointReader};
use reth_rpc_eth_api::helpers::EthApiSpec;
use reth_transaction_pool::TransactionPool;

Expand All @@ -9,11 +9,11 @@ use crate::EthApi;
impl<Provider, Pool, Network, EvmConfig> EthApiSpec for EthApi<Provider, Pool, Network, EvmConfig>
where
Pool: TransactionPool + 'static,
Provider: BlockNumReader + ChainSpecProvider + 'static,
Provider: ChainSpecProvider + BlockNumReader + StageCheckpointReader + 'static,
Network: NetworkInfo + 'static,
EvmConfig: Send + Sync,
{
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader {
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader {
self.inner.provider()
}

Expand Down
17 changes: 16 additions & 1 deletion crates/storage/provider/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use reth_primitives::{
SealedHeader, StorageKey, StorageValue, TransactionMeta, TransactionSigned,
TransactionSignedNoHash, TxHash, TxNumber, Withdrawal, Withdrawals, B256, U256,
};
use reth_storage_api::StateProofProvider;
use reth_stages_types::{StageCheckpoint, StageId};
use reth_storage_api::{StageCheckpointReader, StateProofProvider};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use reth_trie::{updates::TrieUpdates, AccountProof, HashedPostState, HashedStorage};
use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg};
Expand Down Expand Up @@ -546,6 +547,20 @@ impl AccountReader for MockEthProvider {
}
}

impl StageCheckpointReader for MockEthProvider {
fn get_stage_checkpoint(&self, _id: StageId) -> ProviderResult<Option<StageCheckpoint>> {
Ok(None)
}

fn get_stage_checkpoint_progress(&self, _id: StageId) -> ProviderResult<Option<Vec<u8>>> {
Ok(None)
}

fn get_all_checkpoints(&self) -> ProviderResult<Vec<(String, StageCheckpoint)>> {
Ok(vec![])
}
}

impl StateRootProvider for MockEthProvider {
fn hashed_state_root(&self, _state: HashedPostState) -> ProviderResult<B256> {
let state_root = self.state_roots.lock().pop().unwrap_or_default();
Expand Down
2 changes: 2 additions & 0 deletions crates/storage/provider/src/traits/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub trait FullRpcProvider:
+ BlockReaderIdExt
+ HeaderProvider
+ TransactionsProvider
+ StageCheckpointReader
+ Clone
+ Unpin
+ 'static
Expand All @@ -65,6 +66,7 @@ impl<T> FullRpcProvider for T where
+ BlockReaderIdExt
+ HeaderProvider
+ TransactionsProvider
+ StageCheckpointReader
+ Clone
+ Unpin
+ 'static
Expand Down

0 comments on commit 52cdcf0

Please sign in to comment.