From 2147407f5a129a69461319395da41d16ff6206ea Mon Sep 17 00:00:00 2001 From: tgmichel Date: Fri, 16 Oct 2020 12:41:02 +0200 Subject: [PATCH] Return correct response in `eth_syncing` (#164) --- rpc/src/eth.rs | 39 +++++++++++++++++++++++++-------------- template/node/src/rpc.rs | 1 + 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/rpc/src/eth.rs b/rpc/src/eth.rs index a7ab4c314..a4d4da157 100644 --- a/rpc/src/eth.rs +++ b/rpc/src/eth.rs @@ -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, @@ -38,22 +39,24 @@ use crate::internal_err; pub use frontier_rpc_core::{EthApiServer, NetApiServer}; -pub struct EthApi { +pub struct EthApi { pool: Arc

, client: Arc, convert_transaction: CT, + network: Arc>, is_authority: bool, _marker: PhantomData<(B, BE)>, } -impl EthApi { +impl EthApi { pub fn new( client: Arc, pool: Arc

, convert_transaction: CT, + network: Arc>, is_authority: bool ) -> Self { - Self { client, pool, convert_transaction, is_authority, _marker: PhantomData } + Self { client, pool, convert_transaction, network, is_authority, _marker: PhantomData } } } @@ -168,7 +171,7 @@ fn transaction_build( } } -impl EthApi where +impl EthApi where C: ProvideRuntimeApi + StorageProvider + AuxStore, C: HeaderBackend + HeaderMetadata + 'static, C::Api: EthereumRuntimeRPCApi, @@ -227,7 +230,7 @@ impl EthApi where } } -impl EthApiT for EthApi where +impl EthApiT for EthApi where C: ProvideRuntimeApi + StorageProvider + AuxStore, C: HeaderBackend + HeaderMetadata + 'static, C::Api: EthereumRuntimeRPCApi, @@ -243,15 +246,23 @@ impl EthApiT for EthApi where } fn syncing(&self) -> Result { - 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 { diff --git a/template/node/src/rpc.rs b/template/node/src/rpc.rs index 74ce5b593..828163b7d 100644 --- a/template/node/src/rpc.rs +++ b/template/node/src/rpc.rs @@ -106,6 +106,7 @@ pub fn create_full( client.clone(), pool.clone(), frontier_template_runtime::TransactionConverter, + network.clone(), is_authority, )) );