mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
Expose GRANDPA round state through RPC (#5375)
* grandpa: wire up basic RPC call * grandpa: make it compile against GRANDPA with expose round state * grandpa: use shared voter state to expose RPC endpoint * grandpa: restructure into nested structs * grandpa: return background rounds too * grandpa: return error when endpoint not ready * grandpa: collect grandpa rpc deps * grandpa: decide to use concrete AuthorityId in finality-grandpa-rpc * grandpa: remove unncessary type annotation * grandpa: move error code to const * grandpa: remove unnecessary WIP comment * grandpa: remove Id type parameter for SharedVoterState * grandpa: update tests to add shared_voter_state in parameters * grandpa: remove old deprecated test * grandpa: fix getting the correct set_id * grandpa: make SharedVoterState a struct * grandpa: wrap shared_voter_state in rpc_setup * grandpa: replace spaces with tabs * grandpa: limit RwLock write attempt to 1 sec * grandpa: add missing doc comments and remove some pub * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> Co-Authored-By: Hernando Castano <HCastano@users.noreply.github.com> * grandpa: update function name call after change in finality-grandpa * grandpa: group pub use and only export voter::report * grandpa: add missing docs * grandpa: extract out structs used for json serialization * grandpa: stick to u32 for fields intended for js * grandpa: move Error type to its own file * grandpa: group pub use better * Apply code review suggestion Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * grandpa: use correct version of finality-granpda in rpc crate * grandpa: add back basic rpc unit test * grandpa: replace SharedVoterState::new() with empty() * node: cleanup grandpa::SharedVoterState usage in macro * grandpa: remove VoterState error variant * grandpa: enable missing futures compat feature * grandpa: fix typo in error variant * grandpa: remove test_utils * grandpa: allow mocking rpc handler components * grandpa: rename serialized to report in rpc module * grandpa: add proper test for RPC * grandpa: update to finality-grandpa v0.12.1 Co-authored-by: André Silva <andre.beat@gmail.com> Co-authored-by: Demi Obenour <demi@parity.io> Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,9 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use sc_consensus_babe;
|
||||
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider};
|
||||
use grandpa::{
|
||||
self, FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider,
|
||||
};
|
||||
use node_executor;
|
||||
use node_primitives::Block;
|
||||
use node_runtime::RuntimeApi;
|
||||
@@ -38,8 +40,10 @@ use sc_consensus::LongestChain;
|
||||
macro_rules! new_full_start {
|
||||
($config:expr) => {{
|
||||
use std::sync::Arc;
|
||||
|
||||
type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
|
||||
let mut import_setup = None;
|
||||
let mut rpc_setup = None;
|
||||
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
|
||||
|
||||
let builder = sc_service::ServiceBuilder::new_full::<
|
||||
@@ -88,6 +92,10 @@ macro_rules! new_full_start {
|
||||
.with_rpc_extensions(|builder| -> std::result::Result<RpcExtension, _> {
|
||||
let babe_link = import_setup.as_ref().map(|s| &s.2)
|
||||
.expect("BabeLink is present for full services or set up failed; qed.");
|
||||
let grandpa_link = import_setup.as_ref().map(|s| &s.1)
|
||||
.expect("GRANDPA LinkHalf is present for full services or set up failed; qed.");
|
||||
let shared_authority_set = grandpa_link.shared_authority_set();
|
||||
let shared_voter_state = grandpa::SharedVoterState::empty();
|
||||
let deps = node_rpc::FullDeps {
|
||||
client: builder.client().clone(),
|
||||
pool: builder.pool(),
|
||||
@@ -97,12 +105,17 @@ macro_rules! new_full_start {
|
||||
keystore: builder.keystore(),
|
||||
babe_config: sc_consensus_babe::BabeLink::config(babe_link).clone(),
|
||||
shared_epoch_changes: sc_consensus_babe::BabeLink::epoch_changes(babe_link).clone()
|
||||
}
|
||||
},
|
||||
grandpa: node_rpc::GrandpaDeps {
|
||||
shared_voter_state: shared_voter_state.clone(),
|
||||
shared_authority_set: shared_authority_set.clone(),
|
||||
},
|
||||
};
|
||||
rpc_setup = Some((shared_voter_state));
|
||||
Ok(node_rpc::create_full(deps))
|
||||
})?;
|
||||
|
||||
(builder, import_setup, inherent_data_providers)
|
||||
(builder, import_setup, inherent_data_providers, rpc_setup)
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -128,7 +141,8 @@ macro_rules! new_full {
|
||||
$config.disable_grandpa,
|
||||
);
|
||||
|
||||
let (builder, mut import_setup, inherent_data_providers) = new_full_start!($config);
|
||||
let (builder, mut import_setup, inherent_data_providers, mut rpc_setup) =
|
||||
new_full_start!($config);
|
||||
|
||||
let service = builder
|
||||
.with_finality_proof_provider(|client, backend| {
|
||||
@@ -139,7 +153,10 @@ macro_rules! new_full {
|
||||
.build()?;
|
||||
|
||||
let (block_import, grandpa_link, babe_link) = import_setup.take()
|
||||
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
|
||||
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
|
||||
|
||||
let shared_voter_state = rpc_setup.take()
|
||||
.expect("The SharedVoterState is present for Full Services or setup failed before. qed");
|
||||
|
||||
($with_startup_data)(&block_import, &babe_link);
|
||||
|
||||
@@ -240,6 +257,7 @@ macro_rules! new_full {
|
||||
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
|
||||
voting_rule: grandpa::VotingRulesBuilder::default().build(),
|
||||
prometheus_registry: service.prometheus_registry(),
|
||||
shared_voter_state,
|
||||
};
|
||||
|
||||
// the GRANDPA voter task is considered infallible, i.e.
|
||||
|
||||
Reference in New Issue
Block a user