Added sync stages status to eth_sync (#10042)

This commit is contained in:
Luca Provini
2024-08-03 04:53:47 +02:00
committed by GitHub
parent 1290260da3
commit 52cdcf0a9a
5 changed files with 36 additions and 10 deletions

View File

@@ -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::{
@@ -108,7 +108,7 @@ where
N: FullNodeComponents,
{
#[inline]
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader {
fn provider(&self) -> impl ChainSpecProvider + BlockNumReader + StageCheckpointReader {
self.inner.provider()
}

View File

@@ -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;
@@ -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;
@@ -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

View File

@@ -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;
@@ -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()
}

View File

@@ -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};
@@ -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();

View File

@@ -52,6 +52,7 @@ pub trait FullRpcProvider:
+ BlockReaderIdExt
+ HeaderProvider
+ TransactionsProvider
+ StageCheckpointReader
+ Clone
+ Unpin
+ 'static
@@ -65,6 +66,7 @@ impl<T> FullRpcProvider for T where
+ BlockReaderIdExt
+ HeaderProvider
+ TransactionsProvider
+ StageCheckpointReader
+ Clone
+ Unpin
+ 'static