Add an system_syncState RPC method (#7315)

* Add system_syncState RPC method

* Update client/rpc-api/src/system/helpers.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Pierre Krieger
2020-10-13 17:53:49 +02:00
committed by GitHub
parent e4cb862123
commit bcde7b4f3f
6 changed files with 83 additions and 5 deletions
+14 -2
View File
@@ -80,7 +80,7 @@ pub use sc_tracing::TracingReceiver;
pub use task_manager::SpawnTaskHandle;
pub use task_manager::TaskManager;
pub use sp_consensus::import_queue::ImportQueue;
use sc_client_api::BlockchainEvents;
use sc_client_api::{blockchain::HeaderBackend, BlockchainEvents};
const DEFAULT_PROTOCOL_ID: &str = "sup";
@@ -199,7 +199,7 @@ pub struct PartialComponents<Client, Backend, SelectChain, ImportQueue, Transact
/// The `status_sink` contain a list of senders to send a periodic network status to.
async fn build_network_future<
B: BlockT,
C: BlockchainEvents<B>,
C: BlockchainEvents<B> + HeaderBackend<B>,
H: sc_network::ExHashT
> (
role: Role,
@@ -212,6 +212,9 @@ async fn build_network_future<
) {
let mut imported_blocks_stream = client.import_notification_stream().fuse();
// Current best block at initialization, to report to the RPC layer.
let starting_block = client.info().best_number;
// Stream of finalized blocks reported by the client.
let mut finality_notification_stream = {
let mut finality_notification_stream = client.finality_notification_stream().fuse();
@@ -323,6 +326,15 @@ async fn build_network_future<
let _ = sender.send(vec![node_role]);
}
sc_rpc::system::Request::SyncState(sender) => {
use sc_rpc::system::SyncState;
let _ = sender.send(SyncState {
starting_block: starting_block,
current_block: client.info().best_number,
highest_block: network.best_seen_block(),
});
}
}
}