mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 17:57:56 +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:
@@ -31,7 +31,7 @@
|
||||
|
||||
use std::{sync::Arc, fmt};
|
||||
|
||||
use node_primitives::{Block, BlockNumber, AccountId, Index, Balance};
|
||||
use node_primitives::{Block, BlockNumber, AccountId, Index, Balance, Hash};
|
||||
use node_runtime::UncheckedExtrinsic;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_transaction_pool::TransactionPool;
|
||||
@@ -42,6 +42,8 @@ use sp_consensus_babe::BabeApi;
|
||||
use sc_consensus_epochs::SharedEpochChanges;
|
||||
use sc_consensus_babe::{Config, Epoch};
|
||||
use sc_consensus_babe_rpc::BabeRPCHandler;
|
||||
use sc_finality_grandpa::{SharedVoterState, SharedAuthoritySet};
|
||||
use sc_finality_grandpa_rpc::GrandpaRpcHandler;
|
||||
|
||||
/// Light client extra dependencies.
|
||||
pub struct LightDeps<C, F, P> {
|
||||
@@ -65,6 +67,14 @@ pub struct BabeDeps {
|
||||
pub keystore: KeyStorePtr,
|
||||
}
|
||||
|
||||
/// Extra dependencies for GRANDPA
|
||||
pub struct GrandpaDeps {
|
||||
/// Voting round info.
|
||||
pub shared_voter_state: SharedVoterState,
|
||||
/// Authority set info.
|
||||
pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,
|
||||
}
|
||||
|
||||
/// Full client dependencies.
|
||||
pub struct FullDeps<C, P, SC> {
|
||||
/// The client instance to use.
|
||||
@@ -75,6 +85,8 @@ pub struct FullDeps<C, P, SC> {
|
||||
pub select_chain: SC,
|
||||
/// BABE specific dependencies.
|
||||
pub babe: BabeDeps,
|
||||
/// GRANDPA specific dependencies.
|
||||
pub grandpa: GrandpaDeps,
|
||||
}
|
||||
|
||||
/// Instantiate all Full RPC extensions.
|
||||
@@ -102,13 +114,18 @@ pub fn create_full<C, P, M, SC>(
|
||||
client,
|
||||
pool,
|
||||
select_chain,
|
||||
babe
|
||||
babe,
|
||||
grandpa,
|
||||
} = deps;
|
||||
let BabeDeps {
|
||||
keystore,
|
||||
babe_config,
|
||||
shared_epoch_changes,
|
||||
} = babe;
|
||||
let GrandpaDeps {
|
||||
shared_voter_state,
|
||||
shared_authority_set,
|
||||
} = grandpa;
|
||||
|
||||
io.extend_with(
|
||||
SystemApi::to_delegate(FullSystem::new(client.clone(), pool))
|
||||
@@ -127,6 +144,11 @@ pub fn create_full<C, P, M, SC>(
|
||||
BabeRPCHandler::new(client, shared_epoch_changes, keystore, babe_config, select_chain)
|
||||
)
|
||||
);
|
||||
io.extend_with(
|
||||
sc_finality_grandpa_rpc::GrandpaApi::to_delegate(
|
||||
GrandpaRpcHandler::new(shared_authority_set, shared_voter_state)
|
||||
)
|
||||
);
|
||||
|
||||
io
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user