Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions bin/node-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ where
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};

let mut module = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

module.merge(SystemRpc::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
module.merge(TransactionPaymentRpc::new(client).into_rpc())?;
module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client).into_rpc())?;

// Extend this RPC with a custom API by using the following syntax.
// `YourRpcStruct` should have a reference to a client, which is needed
Expand Down
37 changes: 16 additions & 21 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 @@ -120,15 +118,15 @@ where
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
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 pallet_contracts_rpc::{Contracts, ContractsApiServer};
use pallet_mmr_rpc::{Mmr, MmrApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer};
use sc_rpc::dev::{Dev, DevApiServer};
use sc_sync_state_rpc::{SyncStateRpc, SyncStateRpcApiServer};
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc};
use substrate_state_trie_migration_rpc::StateMigrationApiServer;
use sc_sync_state_rpc::{SyncState, SyncStateApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};

let mut io = RpcModule::new(());
let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa } = deps;
Expand All @@ -142,15 +140,15 @@ where
finality_provider,
} = grandpa;

io.merge(SystemRpc::new(client.clone(), pool, deny_unsafe).into_rpc())?;
io.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
// Making synchronous calls in light client freezes the browser currently,
// more context: https://github.com/paritytech/substrate/pull/3480
// These RPCs should use an asynchronous caller instead.
io.merge(ContractsRpc::new(client.clone()).into_rpc())?;
io.merge(MmrRpc::new(client.clone()).into_rpc())?;
io.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;
io.merge(Contracts::new(client.clone()).into_rpc())?;
io.merge(Mmr::new(client.clone()).into_rpc())?;
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
io.merge(
BabeRpc::new(
Babe::new(
client.clone(),
shared_epoch_changes.clone(),
keystore,
Expand All @@ -161,7 +159,7 @@ where
.into_rpc(),
)?;
io.merge(
GrandpaRpc::new(
Grandpa::new(
subscription_executor,
shared_authority_set.clone(),
shared_voter_state,
Expand All @@ -172,14 +170,11 @@ where
)?;

io.merge(
SyncStateRpc::new(chain_spec, client.clone(), shared_authority_set, shared_epoch_changes)?
SyncState::new(chain_spec, client.clone(), shared_authority_set, shared_epoch_changes)?
.into_rpc(),
)?;

io.merge(
substrate_state_trie_migration_rpc::MigrationRpc::new(client.clone(), backend, deny_unsafe)
.into_rpc(),
)?;
io.merge(StateMigration::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,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>,
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 Beefy<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<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)
}
Expand Down
17 changes: 17 additions & 0 deletions client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ pub struct RunCmd {
#[clap(long)]
pub rpc_max_response_size: Option<usize>,

/// Set the the maximum concurrent subscriptions per connection.
/// Default is 1024.
#[clap(long)]
pub rpc_max_subscriptions_per_connection: Option<usize>,

/// Expose Prometheus exporter on all interfaces.
///
/// Default is local.
Expand Down Expand Up @@ -459,6 +464,18 @@ impl CliConfiguration for RunCmd {
Ok(self.rpc_max_payload)
}

fn rpc_max_request_size(&self) -> Result<Option<usize>> {
Ok(self.rpc_max_request_size)
}

fn rpc_max_response_size(&self) -> Result<Option<usize>> {
Ok(self.rpc_max_response_size)
}

fn rpc_max_subscriptions_per_connection(&self) -> Result<Option<usize>> {
Ok(self.rpc_max_subscriptions_per_connection)
}

fn ws_max_out_buffer_capacity(&self) -> Result<Option<usize>> {
Ok(self.ws_max_out_buffer_capacity)
}
Expand Down
7 changes: 6 additions & 1 deletion client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
Ok(None)
}

/// Get maximum number of subscriptions per connection.
fn rpc_max_subscriptions_per_connection(&self) -> Result<Option<usize>> {
Ok(None)
}

/// Get maximum WS output buffer capacity.
fn ws_max_out_buffer_capacity(&self) -> Result<Option<usize>> {
Ok(None)
Expand Down Expand Up @@ -539,7 +544,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
rpc_max_request_size: self.rpc_max_request_size()?,
rpc_max_response_size: self.rpc_max_response_size()?,
rpc_id_provider: None,
rpc_max_subs_per_conn: None,
rpc_max_subs_per_conn: self.rpc_max_subscriptions_per_connection()?,
ws_max_out_buffer_capacity: self.ws_max_out_buffer_capacity()?,
prometheus_config: self
.prometheus_config(DCV::prometheus_listen_port(), &chain_spec)?,
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl NetworkParams {
let port = self.port.unwrap_or(default_listen_port);

let listen_addresses = if self.listen_addr.is_empty() {
if is_validator {
if is_validator || is_dev {
vec![
Multiaddr::empty()
.with(Protocol::Ip6([0, 0, 0, 0, 0, 0, 0, 0].into()))
Expand Down
12 changes: 6 additions & 6 deletions client/consensus/babe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>,
Expand All @@ -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>
Expand Down Expand Up @@ -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);
Expand All @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions client/finality-grandpa/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ 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,
justification_stream: GrandpaJustificationStream<Block>,
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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
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 @@ -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,
Expand All @@ -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,
Expand Down
19 changes: 13 additions & 6 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,18 @@ where
}

fn legacy_cli_parsing(config: &Configuration) -> (Option<usize>, Option<usize>, Option<usize>) {
let ws_max_response_size = config.ws_max_out_buffer_capacity.map(|max| {
eprintln!("DEPRECATED: `--ws_max_out_buffer_capacity` has been removed use `rpc-max-response-size or rpc-max-request-size` instead");
eprintln!("Setting WS `rpc-max-response-size` to `max(ws_max_out_buffer_capacity, rpc_max_response_size)`");
std::cmp::max(max, config.rpc_max_response_size.unwrap_or(0))
});
let ws_max_response_size = match (
config.ws_max_out_buffer_capacity,
config.rpc_max_response_size,
) {
(Some(legacy_max), max) => {
eprintln!("DEPRECATED: `--ws_max_out_buffer_capacity` has been removed; use `rpc-max-response-size or rpc-max-request-size` instead");
eprintln!("Setting WS `rpc-max-response-size` to `max(ws_max_out_buffer_capacity, rpc_max_response_size)`");
Some(std::cmp::max(legacy_max, max.unwrap_or(0)))
},
(None, Some(m)) => Some(m),
(None, None) => None,
};

let max_request_size = match (config.rpc_max_payload, config.rpc_max_request_size) {
(Some(legacy_max), max) => {
Expand All @@ -498,7 +505,7 @@ fn legacy_cli_parsing(config: &Configuration) -> (Option<usize>, Option<usize>,
(None, None) => None,
};

let http_max_response_size = match (config.rpc_max_payload, config.rpc_max_request_size) {
let http_max_response_size = match (config.rpc_max_payload, config.rpc_max_response_size) {
(Some(legacy_max), max) => {
eprintln!("DEPRECATED: `--rpc_max_payload` has been removed use `rpc-max-response-size or rpc-max-request-size` instead");
eprintln!(
Expand Down
Loading