Unify rpc api and implementation name (#11469)

* Unify rpc api and implementation name

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* MauanlSeal ==> ManualSealRpc

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Remove extra Rpc naming in the structs

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Update doc

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* fix merge

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Qinxuan Chen
2022-05-21 14:13:09 +08:00
committed by GitHub
parent dcb8a8504e
commit 5497069d54
12 changed files with 72 additions and 83 deletions
+9 -14
View File
@@ -100,17 +100,17 @@ pub trait BeefyApi<Notification, Hash> {
}
/// Implements the BeefyApi RPC trait for interacting with BEEFY.
pub struct BeefyRpcHandler<Block: BlockT> {
pub struct Beefy<Block: BlockT> {
signed_commitment_stream: BeefySignedCommitmentStream<Block>,
beefy_best_block: Arc<RwLock<Option<Block::Hash>>>,
executor: SubscriptionTaskExecutor,
}
impl<Block> BeefyRpcHandler<Block>
impl<Block> Beefy<Block>
where
Block: BlockT,
{
/// Creates a new BeefyRpcHandler instance.
/// Creates a new Beefy Rpc handler instance.
pub fn new(
signed_commitment_stream: BeefySignedCommitmentStream<Block>,
best_block_stream: BeefyBestBlockStream<Block>,
@@ -131,8 +131,7 @@ where
}
#[async_trait]
impl<Block> BeefyApiServer<notification::EncodedSignedCommitment, Block::Hash>
for BeefyRpcHandler<Block>
impl<Block> BeefyApiServer<notification::EncodedSignedCommitment, Block::Hash> for Beefy<Block>
where
Block: BlockT,
{
@@ -174,24 +173,20 @@ mod tests {
use sp_runtime::traits::{BlakeTwo256, Hash};
use substrate_test_runtime_client::runtime::Block;
fn setup_io_handler() -> (RpcModule<BeefyRpcHandler<Block>>, BeefySignedCommitmentSender<Block>)
{
fn setup_io_handler() -> (RpcModule<Beefy<Block>>, BeefySignedCommitmentSender<Block>) {
let (_, stream) = BeefyBestBlockStream::<Block>::channel();
setup_io_handler_with_best_block_stream(stream)
}
fn setup_io_handler_with_best_block_stream(
best_block_stream: BeefyBestBlockStream<Block>,
) -> (RpcModule<BeefyRpcHandler<Block>>, BeefySignedCommitmentSender<Block>) {
) -> (RpcModule<Beefy<Block>>, BeefySignedCommitmentSender<Block>) {
let (commitment_sender, commitment_stream) =
BeefySignedCommitmentStream::<Block>::channel();
let handler = BeefyRpcHandler::new(
commitment_stream,
best_block_stream,
sc_rpc::testing::test_executor(),
)
.expect("Setting up the BEEFY RPC handler works");
let handler =
Beefy::new(commitment_stream, best_block_stream, sc_rpc::testing::test_executor())
.expect("Setting up the BEEFY RPC handler works");
(handler.into_rpc(), commitment_sender)
}
@@ -49,7 +49,7 @@ pub trait BabeApi {
}
/// Provides RPC methods for interacting with Babe.
pub struct BabeRpc<B: BlockT, C, SC> {
pub struct Babe<B: BlockT, C, SC> {
/// shared reference to the client.
client: Arc<C>,
/// shared reference to EpochChanges
@@ -64,8 +64,8 @@ pub struct BabeRpc<B: BlockT, C, SC> {
deny_unsafe: DenyUnsafe,
}
impl<B: BlockT, C, SC> BabeRpc<B, C, SC> {
/// Creates a new instance of the BabeRpc handler.
impl<B: BlockT, C, SC> Babe<B, C, SC> {
/// Creates a new instance of the Babe Rpc handler.
pub fn new(
client: Arc<C>,
shared_epoch_changes: SharedEpochChanges<B, Epoch>,
@@ -79,7 +79,7 @@ impl<B: BlockT, C, SC> BabeRpc<B, C, SC> {
}
#[async_trait]
impl<B: BlockT, C, SC> BabeApiServer for BabeRpc<B, C, SC>
impl<B: BlockT, C, SC> BabeApiServer for Babe<B, C, SC>
where
B: BlockT,
C: ProvideRuntimeApi<B>
@@ -239,7 +239,7 @@ mod tests {
fn test_babe_rpc_module(
deny_unsafe: DenyUnsafe,
) -> BabeRpc<Block, TestClient, sc_consensus::LongestChain<Backend, Block>> {
) -> Babe<Block, TestClient, sc_consensus::LongestChain<Backend, Block>> {
let builder = TestClientBuilder::new();
let (client, longest_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
@@ -250,7 +250,7 @@ mod tests {
let epoch_changes = link.epoch_changes().clone();
let keystore = create_temp_keystore::<AuthorityPair>(Sr25519Keyring::Alice).0;
BabeRpc::new(client.clone(), epoch_changes, keystore, config, longest_chain, deny_unsafe)
Babe::new(client.clone(), epoch_changes, keystore, config, longest_chain, deny_unsafe)
}
#[tokio::test]
@@ -66,7 +66,7 @@ pub trait GrandpaApi<Notification, Hash, Number> {
}
/// Provides RPC methods for interacting with GRANDPA.
pub struct GrandpaRpc<AuthoritySet, VoterState, Block: BlockT, ProofProvider> {
pub struct Grandpa<AuthoritySet, VoterState, Block: BlockT, ProofProvider> {
executor: SubscriptionTaskExecutor,
authority_set: AuthoritySet,
voter_state: VoterState,
@@ -74,9 +74,9 @@ pub struct GrandpaRpc<AuthoritySet, VoterState, Block: BlockT, ProofProvider> {
finality_proof_provider: Arc<ProofProvider>,
}
impl<AuthoritySet, VoterState, Block: BlockT, ProofProvider>
GrandpaRpc<AuthoritySet, VoterState, Block, ProofProvider>
Grandpa<AuthoritySet, VoterState, Block, ProofProvider>
{
/// Prepare a new [`GrandpaRpc`]
/// Prepare a new [`Grandpa`] Rpc handler.
pub fn new(
executor: SubscriptionTaskExecutor,
authority_set: AuthoritySet,
@@ -91,7 +91,7 @@ impl<AuthoritySet, VoterState, Block: BlockT, ProofProvider>
#[async_trait]
impl<AuthoritySet, VoterState, Block, ProofProvider>
GrandpaApiServer<JustificationNotification, Block::Hash, NumberFor<Block>>
for GrandpaRpc<AuthoritySet, VoterState, Block, ProofProvider>
for Grandpa<AuthoritySet, VoterState, Block, ProofProvider>
where
VoterState: ReportVoterState + Send + Sync + 'static,
AuthoritySet: ReportAuthoritySet + Send + Sync + 'static,
@@ -243,7 +243,7 @@ mod tests {
fn setup_io_handler<VoterState>(
voter_state: VoterState,
) -> (
RpcModule<GrandpaRpc<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
RpcModule<Grandpa<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
GrandpaJustificationSender<Block>,
)
where
@@ -256,7 +256,7 @@ mod tests {
voter_state: VoterState,
finality_proof: Option<FinalityProof<Header>>,
) -> (
RpcModule<GrandpaRpc<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
RpcModule<Grandpa<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
GrandpaJustificationSender<Block>,
)
where
@@ -266,7 +266,7 @@ mod tests {
let finality_proof_provider = Arc::new(TestFinalityProofProvider { finality_proof });
let executor = Arc::new(TaskExecutor::default());
let rpc = GrandpaRpc::new(
let rpc = Grandpa::new(
executor,
TestAuthoritySet,
voter_state,
+4 -4
View File
@@ -167,7 +167,7 @@ pub fn new_full<BE, Block: BlockT, Client>(
executor: SubscriptionTaskExecutor,
deny_unsafe: DenyUnsafe,
rpc_max_payload: Option<usize>,
) -> (StateApi<Block, Client>, ChildState<Block, Client>)
) -> (State<Block, Client>, ChildState<Block, Client>)
where
Block: BlockT + 'static,
Block::Hash: Unpin,
@@ -192,17 +192,17 @@ where
rpc_max_payload,
));
let backend = Box::new(self::state_full::FullState::new(client, executor, rpc_max_payload));
(StateApi { backend, deny_unsafe }, ChildState { backend: child_backend })
(State { backend, deny_unsafe }, ChildState { backend: child_backend })
}
/// State API with subscriptions support.
pub struct StateApi<Block, Client> {
pub struct State<Block, Client> {
backend: Box<dyn StateBackend<Block, Client>>,
/// Whether to deny unsafe calls
deny_unsafe: DenyUnsafe,
}
impl<Block, Client> StateApiServer<Block::Hash> for StateApi<Block, Client>
impl<Block, Client> StateApiServer<Block::Hash> for State<Block, Client>
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
+5 -5
View File
@@ -37,7 +37,7 @@
//! ```
//!
//! If the [`LightSyncStateExtension`] is not added as an extension to the chain spec,
//! the [`SyncStateRpc`] will fail at instantiation.
//! the [`SyncState`] will fail at instantiation.
#![deny(unused_crate_dependencies)]
@@ -125,21 +125,21 @@ pub struct LightSyncState<Block: BlockT> {
/// An api for sync state RPC calls.
#[rpc(client, server)]
pub trait SyncStateRpcApi {
pub trait SyncStateApi {
/// Returns the JSON serialized chainspec running the node, with a sync state.
#[method(name = "sync_state_genSyncSpec")]
fn system_gen_sync_spec(&self, raw: bool) -> RpcResult<serde_json::Value>;
}
/// An api for sync state RPC calls.
pub struct SyncStateRpc<Block: BlockT, Client> {
pub struct SyncState<Block: BlockT, Client> {
chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
client: Arc<Client>,
shared_authority_set: SharedAuthoritySet<Block>,
shared_epoch_changes: SharedEpochChanges<Block>,
}
impl<Block, Client> SyncStateRpc<Block, Client>
impl<Block, Client> SyncState<Block, Client>
where
Block: BlockT,
Client: HeaderBackend<Block> + sc_client_api::AuxStore + 'static,
@@ -180,7 +180,7 @@ where
}
}
impl<Block, Backend> SyncStateRpcApiServer for SyncStateRpc<Block, Backend>
impl<Block, Backend> SyncStateApiServer for SyncState<Block, Backend>
where
Block: BlockT,
Backend: HeaderBackend<Block> + sc_client_api::AuxStore + 'static,