Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Unify rpc api and implementation name #11469

Merged
merged 6 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ use jsonrpsee::RpcModule;
use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index};
use sc_client_api::AuxStore;
use sc_consensus_babe::{Config, Epoch};
use sc_consensus_babe_rpc::BabeRpc;
use sc_consensus_epochs::SharedEpochChanges;
use sc_finality_grandpa::{
FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
};
use sc_finality_grandpa_rpc::GrandpaRpc;
use sc_rpc::SubscriptionTaskExecutor;
pub use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
Expand Down Expand Up @@ -123,12 +121,12 @@ where
use pallet_contracts_rpc::{ContractsApiServer, ContractsRpc};
use pallet_mmr_rpc::{MmrApiServer, MmrRpc};
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use sc_consensus_babe_rpc::BabeApiServer;
use sc_finality_grandpa_rpc::GrandpaApiServer;
use sc_consensus_babe_rpc::{BabeApiServer, BabeRpc};
use sc_finality_grandpa_rpc::{GrandpaApiServer, GrandpaRpc};
use sc_rpc::dev::{Dev, DevApiServer};
use sc_sync_state_rpc::{SyncStateRpc, SyncStateRpcApiServer};
use sc_sync_state_rpc::{SyncStateApiServer, SyncStateRpc};
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc};
use substrate_state_trie_migration_rpc::StateMigrationApiServer;
use substrate_state_trie_migration_rpc::{StateMigrationApiServer, StateMigrationRpc};

let mut io = RpcModule::new(());
let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa } = deps;
Expand Down Expand Up @@ -176,10 +174,7 @@ where
.into_rpc(),
)?;

io.merge(
substrate_state_trie_migration_rpc::MigrationRpc::new(client.clone(), backend, deny_unsafe)
.into_rpc(),
)?;
io.merge(StateMigrationRpc::new(client.clone(), backend, deny_unsafe).into_rpc())?;
io.merge(Dev::new(client, deny_unsafe).into_rpc())?;

Ok(io)
Expand Down
23 changes: 9 additions & 14 deletions client/beefy/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ pub trait BeefyApi<Notification, Hash> {
}

/// Implements the BeefyApi RPC trait for interacting with BEEFY.
pub struct BeefyRpcHandler<Block: BlockT> {
pub struct BeefyRpc<Block: BlockT> {
signed_commitment_stream: BeefySignedCommitmentStream<Block>,
beefy_best_block: Arc<RwLock<Option<Block::Hash>>>,
executor: SubscriptionTaskExecutor,
}

impl<Block> BeefyRpcHandler<Block>
impl<Block> BeefyRpc<Block>
where
Block: BlockT,
{
Expand All @@ -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 BeefyRpc<Block>
where
Block: BlockT,
{
Expand Down Expand Up @@ -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<BeefyRpc<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<BeefyRpc<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 =
BeefyRpc::new(commitment_stream, best_block_stream, sc_rpc::testing::test_executor())
.expect("Setting up the BEEFY RPC handler works");

(handler.into_rpc(), commitment_sender)
}
Expand All @@ -203,7 +198,7 @@ mod tests {
let expected_response = r#"{"jsonrpc":"2.0","error":{"code":1,"message":"BEEFY RPC endpoint not ready"},"id":1}"#.to_string();
let (result, _) = rpc.raw_json_request(&request).await.unwrap();

assert_eq!(expected_response, result,);
assert_eq!(expected_response, result);
}

#[tokio::test]
Expand Down
6 changes: 3 additions & 3 deletions client/consensus/manual-seal/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait ManualSealApi<Hash> {
}

/// A struct that implements the [`ManualSealApiServer`].
pub struct ManualSeal<Hash> {
pub struct ManualSealRpc<Hash> {
import_block_channel: mpsc::Sender<EngineCommand<Hash>>,
}

Expand All @@ -99,15 +99,15 @@ pub struct CreatedBlock<Hash> {
pub aux: ImportedAux,
}

impl<Hash> ManualSeal<Hash> {
impl<Hash> ManualSealRpc<Hash> {
/// Create new `ManualSeal` with the given reference to the client.
pub fn new(import_block_channel: mpsc::Sender<EngineCommand<Hash>>) -> Self {
Self { import_block_channel }
}
}

#[async_trait]
impl<Hash: Send + 'static> ManualSealApiServer<Hash> for ManualSeal<Hash> {
impl<Hash: Send + 'static> ManualSealApiServer<Hash> for ManualSealRpc<Hash> {
async fn create_block(
&self,
create_empty: bool,
Expand Down
8 changes: 4 additions & 4 deletions client/rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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,
Expand All @@ -193,18 +193,18 @@ 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,
}

#[async_trait]
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,
Expand Down
8 changes: 4 additions & 4 deletions client/sync-state-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#![deny(unused_crate_dependencies)]

use jsonrpsee::{
core::{Error as JsonRpseeError, RpcResult},
core::{Error as RpcError, RpcResult},
proc_macros::rpc,
types::{error::CallError, ErrorObject},
};
Expand Down Expand Up @@ -79,7 +79,7 @@ pub enum Error<Block: BlockT> {
LightSyncStateExtensionNotFound,
}

impl<Block: BlockT> From<Error<Block>> for JsonRpseeError {
impl<Block: BlockT> From<Error<Block>> for RpcError {
fn from(error: Error<Block>) -> Self {
let message = match error {
Error::JsonRpc(s) => s,
Expand Down Expand Up @@ -125,7 +125,7 @@ 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>;
Expand Down Expand Up @@ -180,7 +180,7 @@ where
}
}

impl<Block, Backend> SyncStateRpcApiServer for SyncStateRpc<Block, Backend>
impl<Block, Backend> SyncStateApiServer for SyncStateRpc<Block, Backend>
where
Block: BlockT,
Backend: HeaderBackend<Block> + sc_client_api::AuxStore + 'static,
Expand Down
8 changes: 4 additions & 4 deletions utils/frame/rpc/state-trie-migration-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ pub trait StateMigrationApi<BlockHash> {
}

/// An implementation of state migration specific RPC methods.
pub struct MigrationRpc<C, B, BA> {
pub struct StateMigrationRpc<C, B, BA> {
client: Arc<C>,
backend: Arc<BA>,
deny_unsafe: DenyUnsafe,
_marker: std::marker::PhantomData<(B, BA)>,
}

impl<C, B, BA> MigrationRpc<C, B, BA> {
impl<C, B, BA> StateMigrationRpc<C, B, BA> {
/// Create new state migration rpc for the given reference to the client.
pub fn new(client: Arc<C>, backend: Arc<BA>, deny_unsafe: DenyUnsafe) -> Self {
MigrationRpc { client, backend, deny_unsafe, _marker: Default::default() }
StateMigrationRpc { client, backend, deny_unsafe, _marker: Default::default() }
}
}

impl<C, B, BA> StateMigrationApiServer<<B as BlockT>::Hash> for MigrationRpc<C, B, BA>
impl<C, B, BA> StateMigrationApiServer<<B as BlockT>::Hash> for StateMigrationRpc<C, B, BA>
where
B: BlockT,
C: Send + Sync + 'static + sc_client_api::HeaderBackend<B>,
Expand Down