Skip to content

Commit

Permalink
Return correct response in eth_syncing (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel committed Oct 16, 2020
1 parent 9d42605 commit 2147407
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
39 changes: 25 additions & 14 deletions rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use sc_client_api::backend::{StorageProvider, Backend, StateBackend, AuxStore};
use sha3::{Keccak256, Digest};
use sp_runtime::traits::BlakeTwo256;
use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend};
use sc_network::{NetworkService, ExHashT};
use frontier_rpc_core::{EthApi as EthApiT, NetApi as NetApiT};
use frontier_rpc_core::types::{
BlockNumber, Bytes, CallRequest, Filter, Index, Log, Receipt, RichBlock,
Expand All @@ -38,22 +39,24 @@ use crate::internal_err;

pub use frontier_rpc_core::{EthApiServer, NetApiServer};

pub struct EthApi<B: BlockT, C, P, CT, BE> {
pub struct EthApi<B: BlockT, C, P, CT, BE, H: ExHashT> {
pool: Arc<P>,
client: Arc<C>,
convert_transaction: CT,
network: Arc<NetworkService<B, H>>,
is_authority: bool,
_marker: PhantomData<(B, BE)>,
}

impl<B: BlockT, C, P, CT, BE> EthApi<B, C, P, CT, BE> {
impl<B: BlockT, C, P, CT, BE, H: ExHashT> EthApi<B, C, P, CT, BE, H> {
pub fn new(
client: Arc<C>,
pool: Arc<P>,
convert_transaction: CT,
network: Arc<NetworkService<B, H>>,
is_authority: bool
) -> Self {
Self { client, pool, convert_transaction, is_authority, _marker: PhantomData }
Self { client, pool, convert_transaction, network, is_authority, _marker: PhantomData }
}
}

Expand Down Expand Up @@ -168,7 +171,7 @@ fn transaction_build(
}
}

impl<B, C, P, CT, BE> EthApi<B, C, P, CT, BE> where
impl<B, C, P, CT, BE, H: ExHashT> EthApi<B, C, P, CT, BE, H> where
C: ProvideRuntimeApi<B> + StorageProvider<B, BE> + AuxStore,
C: HeaderBackend<B> + HeaderMetadata<B, Error=BlockChainError> + 'static,
C::Api: EthereumRuntimeRPCApi<B>,
Expand Down Expand Up @@ -227,7 +230,7 @@ impl<B, C, P, CT, BE> EthApi<B, C, P, CT, BE> where
}
}

impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
impl<B, C, P, CT, BE, H: ExHashT> EthApiT for EthApi<B, C, P, CT, BE, H> where
C: ProvideRuntimeApi<B> + StorageProvider<B, BE> + AuxStore,
C: HeaderBackend<B> + HeaderMetadata<B, Error=BlockChainError> + 'static,
C::Api: EthereumRuntimeRPCApi<B>,
Expand All @@ -243,15 +246,23 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
}

fn syncing(&self) -> Result<SyncStatus> {
let block_number = U256::from(self.client.info().best_number.clone().unique_saturated_into());

Ok(SyncStatus::Info(SyncInfo {
starting_block: U256::zero(),
current_block: block_number,
highest_block: block_number,
warp_chunks_amount: None,
warp_chunks_processed: None,
}))
if self.network.is_major_syncing() {
let block_number = U256::from(
self.client.info().best_number.clone().unique_saturated_into()
);
Ok(SyncStatus::Info(SyncInfo {
starting_block: U256::zero(),
current_block: block_number,
// TODO `highest_block` is not correct, should load `best_seen_block` from NetworkWorker,
// but afaik that is not currently possible in Substrate:
// https://github.com/paritytech/substrate/issues/7311
highest_block: block_number,
warp_chunks_amount: None,
warp_chunks_processed: None,
}))
} else {
Ok(SyncStatus::None)
}
}

fn hashrate(&self) -> Result<U256> {
Expand Down
1 change: 1 addition & 0 deletions template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn create_full<C, P, BE>(
client.clone(),
pool.clone(),
frontier_template_runtime::TransactionConverter,
network.clone(),
is_authority,
))
);
Expand Down

0 comments on commit 2147407

Please sign in to comment.