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

Commit fe658f6

Browse files
author
Andronik Ordian
committed
Merge branch 'master' into rococo-experimental
* master: double the allocator limit (#9102) Make it possible to override maximum payload of RPC (#9019) Aura: Skip initialize block & remove cache (#9132) Avoid running some test 2 times when unneeded (#9124)
2 parents 36d2578 + f6b1197 commit fe658f6

File tree

21 files changed

+121
-83
lines changed

21 files changed

+121
-83
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ test-linux-stable: &test-linux
319319
script:
320320
# this job runs all tests in former runtime-benchmarks, frame-staking and wasmtime tests
321321
- time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml
322-
- time cargo test -p frame-support-test --features=conditional-storage --manifest-path frame/support/test/Cargo.toml # does not reuse cache 1 min 44 sec
322+
- time cargo test -p frame-support-test --features=conditional-storage --manifest-path frame/support/test/Cargo.toml --test pallet # does not reuse cache 1 min 44 sec
323323
- SUBSTRATE_TEST_TIMEOUT=1 time cargo test -p substrate-test-utils --release --verbose --locked -- --ignored timeout
324324
- sccache -s
325325

client/cli/src/commands/run_cmd.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ pub struct RunCmd {
4242
/// The node will be started with the authority role and actively
4343
/// participate in any consensus task that it can (e.g. depending on
4444
/// availability of local keys).
45-
#[structopt(
46-
long = "validator"
47-
)]
45+
#[structopt(long)]
4846
pub validator: bool,
4947

50-
/// Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA observer.
48+
/// Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA
49+
/// observer.
5150
#[structopt(long)]
5251
pub no_grandpa: bool,
5352

@@ -57,8 +56,8 @@ pub struct RunCmd {
5756

5857
/// Listen to all RPC interfaces.
5958
///
60-
/// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC proxy
61-
/// server to filter out dangerous methods. More details:
59+
/// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC
60+
/// proxy server to filter out dangerous methods. More details:
6261
/// <https://github.com/paritytech/substrate/wiki/Public-RPC>.
6362
/// Use `--unsafe-rpc-external` to suppress the warning if you understand the risks.
6463
#[structopt(long = "rpc-external")]
@@ -74,8 +73,8 @@ pub struct RunCmd {
7473
///
7574
/// - `Unsafe`: Exposes every RPC method.
7675
/// - `Safe`: Exposes only a safe subset of RPC methods, denying unsafe RPC methods.
77-
/// - `Auto`: Acts as `Safe` if RPC is served externally, e.g. when `--{rpc,ws}-external` is passed,
78-
/// otherwise acts as `Unsafe`.
76+
/// - `Auto`: Acts as `Safe` if RPC is served externally, e.g. when `--{rpc,ws}-external` is
77+
/// passed, otherwise acts as `Unsafe`.
7978
#[structopt(
8079
long,
8180
value_name = "METHOD SET",
@@ -88,8 +87,9 @@ pub struct RunCmd {
8887

8988
/// Listen to all Websocket interfaces.
9089
///
91-
/// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC proxy
92-
/// server to filter out dangerous methods. More details: <https://github.com/paritytech/substrate/wiki/Public-RPC>.
90+
/// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC
91+
/// proxy server to filter out dangerous methods. More details:
92+
/// <https://github.com/paritytech/substrate/wiki/Public-RPC>.
9393
/// Use `--unsafe-ws-external` to suppress the warning if you understand the risks.
9494
#[structopt(long = "ws-external")]
9595
pub ws_external: bool,
@@ -100,6 +100,11 @@ pub struct RunCmd {
100100
#[structopt(long = "unsafe-ws-external")]
101101
pub unsafe_ws_external: bool,
102102

103+
/// Set the the maximum RPC payload size for both requests and responses (both http and ws), in
104+
/// megabytes. Default is 15MiB.
105+
#[structopt(long = "rpc-max-payload")]
106+
pub rpc_max_payload: Option<usize>,
107+
103108
/// Listen to all Prometheus data source interfaces.
104109
///
105110
/// Default is local.
@@ -194,7 +199,8 @@ pub struct RunCmd {
194199
#[structopt(long, conflicts_with_all = &["alice", "charlie", "dave", "eve", "ferdie", "one", "two"])]
195200
pub bob: bool,
196201

197-
/// Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to keystore.
202+
/// Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to
203+
/// keystore.
198204
#[structopt(long, conflicts_with_all = &["alice", "bob", "dave", "eve", "ferdie", "one", "two"])]
199205
pub charlie: bool,
200206

@@ -435,6 +441,10 @@ impl CliConfiguration for RunCmd {
435441
Ok(self.rpc_methods.into())
436442
}
437443

444+
fn rpc_max_payload(&self) -> Result<Option<usize>> {
445+
Ok(self.rpc_max_payload)
446+
}
447+
438448
fn transaction_pool(&self) -> Result<TransactionPoolOptions> {
439449
Ok(self.pool_config.transaction_pool())
440450
}

client/cli/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
372372
Ok(Some(Vec::new()))
373373
}
374374

375+
/// Get maximum RPC payload.
376+
fn rpc_max_payload(&self) -> Result<Option<usize>> {
377+
Ok(None)
378+
}
379+
375380
/// Get the prometheus configuration (`None` if disabled)
376381
///
377382
/// By default this is `None`.
@@ -535,6 +540,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
535540
rpc_ws_max_connections: self.rpc_ws_max_connections()?,
536541
rpc_http_threads: self.rpc_http_threads()?,
537542
rpc_cors: self.rpc_cors(is_dev)?,
543+
rpc_max_payload: self.rpc_max_payload()?,
538544
prometheus_config: self.prometheus_config(DCV::prometheus_listen_port())?,
539545
telemetry_endpoints,
540546
telemetry_external_transport: self.telemetry_external_transport()?,

client/consensus/aura/src/import_queue.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -317,43 +317,6 @@ impl<B: BlockT, C, P, CAW, CIDP> Verifier<B> for AuraVerifier<C, P, CAW, CIDP> w
317317
}
318318
}
319319

320-
fn initialize_authorities_cache<A, B, C>(client: &C) -> Result<(), ConsensusError> where
321-
A: Codec + Debug,
322-
B: BlockT,
323-
C: ProvideRuntimeApi<B> + BlockOf + ProvideCache<B> + UsageProvider<B>,
324-
C::Api: AuraApi<B, A>,
325-
{
326-
// no cache => no initialization
327-
let cache = match client.cache() {
328-
Some(cache) => cache,
329-
None => return Ok(()),
330-
};
331-
332-
let best_hash = client.usage_info().chain.best_hash;
333-
334-
// check if we already have initialized the cache
335-
let map_err = |error| sp_consensus::Error::from(sp_consensus::Error::ClientImport(
336-
format!(
337-
"Error initializing authorities cache: {}",
338-
error,
339-
)));
340-
341-
let block_id = BlockId::hash(best_hash);
342-
let authorities: Option<Vec<A>> = cache
343-
.get_at(&well_known_cache_keys::AUTHORITIES, &block_id)
344-
.unwrap_or(None)
345-
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]).ok());
346-
if authorities.is_some() {
347-
return Ok(());
348-
}
349-
350-
let authorities = crate::authorities(client, &block_id)?;
351-
cache.initialize(&well_known_cache_keys::AUTHORITIES, authorities.encode())
352-
.map_err(map_err)?;
353-
354-
Ok(())
355-
}
356-
357320
/// Should we check for equivocation of a block author?
358321
#[derive(Debug, Clone, Copy)]
359322
pub enum CheckForEquivocation {
@@ -438,8 +401,6 @@ pub fn import_queue<'a, P, Block, I, C, S, CAW, CIDP>(
438401
CIDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
439402
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
440403
{
441-
initialize_authorities_cache(&*client)?;
442-
443404
let verifier = build_verifier::<P, _, _, _>(
444405
BuildVerifierParams {
445406
client,

client/consensus/aura/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use sp_consensus::{
4545
BlockOrigin, Error as ConsensusError, SelectChain,
4646
};
4747
use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider};
48-
use sp_blockchain::{Result as CResult, well_known_cache_keys, ProvideCache, HeaderBackend};
48+
use sp_blockchain::{Result as CResult, ProvideCache, HeaderBackend};
4949
use sp_core::crypto::Public;
5050
use sp_application_crypto::{AppKey, AppPublic};
5151
use sp_runtime::{generic::BlockId, traits::NumberFor};
@@ -546,14 +546,9 @@ fn authorities<A, B, C>(client: &C, at: &BlockId<B>) -> Result<Vec<A>, Consensus
546546
C: ProvideRuntimeApi<B> + BlockOf + ProvideCache<B>,
547547
C::Api: AuraApi<B, A>,
548548
{
549-
client
550-
.cache()
551-
.and_then(|cache| cache
552-
.get_at(&well_known_cache_keys::AUTHORITIES, at)
553-
.unwrap_or(None)
554-
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]).ok())
555-
)
556-
.or_else(|| AuraApi::authorities(&*client.runtime_api(), at).ok())
549+
client.runtime_api()
550+
.authorities(at)
551+
.ok()
557552
.ok_or_else(|| sp_consensus::Error::InvalidAuthoritiesSet.into())
558553
}
559554

client/executor/src/native_executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<D: NativeExecutionDispatch> NativeExecutor<D> {
291291
default_heap_pages: Option<u64>,
292292
max_runtime_instances: usize,
293293
) -> Self {
294-
let extended = D::ExtendHostFunctions::host_functions();
294+
let extended = D::ExtendHostFunctions::host_functions();
295295
let mut host_functions = sp_io::SubstrateHostFunctions::host_functions()
296296
.into_iter()
297297
// filter out any host function overrides provided.

client/rpc-servers/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ use jsonrpc_core::{IoHandlerExtension, MetaIoHandler};
2727
use log::error;
2828
use pubsub::PubSubMetadata;
2929

30+
const MEGABYTE: usize = 1024 * 1024;
31+
3032
/// Maximal payload accepted by RPC servers.
31-
pub const MAX_PAYLOAD: usize = 15 * 1024 * 1024;
33+
pub const RPC_MAX_PAYLOAD_DEFAULT: usize = 15 * MEGABYTE;
3234

3335
/// Default maximum number of connections for WS RPC servers.
3436
const WS_MAX_CONNECTIONS: usize = 100;
@@ -85,7 +87,10 @@ mod inner {
8587
thread_pool_size: Option<usize>,
8688
cors: Option<&Vec<String>>,
8789
io: RpcHandler<M>,
90+
maybe_max_payload_mb: Option<usize>,
8891
) -> io::Result<http::Server> {
92+
let max_request_body_size = maybe_max_payload_mb.map(|mb| mb.saturating_mul(MEGABYTE))
93+
.unwrap_or(RPC_MAX_PAYLOAD_DEFAULT);
8994
http::ServerBuilder::new(io)
9095
.threads(thread_pool_size.unwrap_or(HTTP_THREADS))
9196
.health_api(("/health", "system_health"))
@@ -96,7 +101,7 @@ mod inner {
96101
http::RestApi::Unsecure
97102
})
98103
.cors(map_cors::<http::AccessControlAllowOrigin>(cors))
99-
.max_request_body_size(MAX_PAYLOAD)
104+
.max_request_body_size(max_request_body_size)
100105
.start_http(addr)
101106
}
102107

@@ -120,14 +125,19 @@ mod inner {
120125
/// Start WS server listening on given address.
121126
///
122127
/// **Note**: Only available if `not(target_os = "unknown")`.
123-
pub fn start_ws<M: pubsub::PubSubMetadata + From<jsonrpc_core::futures::sync::mpsc::Sender<String>>> (
128+
pub fn start_ws<
129+
M: pubsub::PubSubMetadata + From<jsonrpc_core::futures::sync::mpsc::Sender<String>>,
130+
>(
124131
addr: &std::net::SocketAddr,
125132
max_connections: Option<usize>,
126133
cors: Option<&Vec<String>>,
127134
io: RpcHandler<M>,
135+
maybe_max_payload_mb: Option<usize>,
128136
) -> io::Result<ws::Server> {
137+
let rpc_max_payload = maybe_max_payload_mb.map(|mb| mb.saturating_mul(MEGABYTE))
138+
.unwrap_or(RPC_MAX_PAYLOAD_DEFAULT);
129139
ws::ServerBuilder::with_meta_extractor(io, |context: &ws::RequestContext| context.sender().into())
130-
.max_payload(MAX_PAYLOAD)
140+
.max_payload(rpc_max_payload)
131141
.max_connections(max_connections.unwrap_or(WS_MAX_CONNECTIONS))
132142
.allowed_origins(map_cors(cors))
133143
.allowed_hosts(hosts_filtering(cors.is_some()))

client/rpc/src/state/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ pub fn new_full<BE, Block: BlockT, Client>(
182182
client: Arc<Client>,
183183
subscriptions: SubscriptionManager,
184184
deny_unsafe: DenyUnsafe,
185+
rpc_max_payload: Option<usize>,
185186
) -> (State<Block, Client>, ChildState<Block, Client>)
186187
where
187188
Block: BlockT + 'static,
@@ -193,9 +194,11 @@ pub fn new_full<BE, Block: BlockT, Client>(
193194
Client::Api: Metadata<Block>,
194195
{
195196
let child_backend = Box::new(
196-
self::state_full::FullState::new(client.clone(), subscriptions.clone())
197+
self::state_full::FullState::new(
198+
client.clone(), subscriptions.clone(), rpc_max_payload
199+
)
197200
);
198-
let backend = Box::new(self::state_full::FullState::new(client, subscriptions));
201+
let backend = Box::new(self::state_full::FullState::new(client, subscriptions, rpc_max_payload));
199202
(State { backend, deny_unsafe }, ChildState { backend: child_backend })
200203
}
201204

client/rpc/src/state/state_full.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ struct QueryStorageRange<Block: BlockT> {
6767
pub struct FullState<BE, Block: BlockT, Client> {
6868
client: Arc<Client>,
6969
subscriptions: SubscriptionManager,
70-
_phantom: PhantomData<(BE, Block)>
70+
_phantom: PhantomData<(BE, Block)>,
71+
rpc_max_payload: Option<usize>,
7172
}
7273

7374
impl<BE, Block: BlockT, Client> FullState<BE, Block, Client>
@@ -78,8 +79,12 @@ impl<BE, Block: BlockT, Client> FullState<BE, Block, Client>
7879
Block: BlockT + 'static,
7980
{
8081
/// Create new state API backend for full nodes.
81-
pub fn new(client: Arc<Client>, subscriptions: SubscriptionManager) -> Self {
82-
Self { client, subscriptions, _phantom: PhantomData }
82+
pub fn new(
83+
client: Arc<Client>,
84+
subscriptions: SubscriptionManager,
85+
rpc_max_payload: Option<usize>,
86+
) -> Self {
87+
Self { client, subscriptions, _phantom: PhantomData, rpc_max_payload }
8388
}
8489

8590
/// Returns given block hash or best block hash if None is passed.
@@ -540,9 +545,15 @@ impl<BE, Block, Client> StateBackend<Block, Client> for FullState<BE, Block, Cli
540545
targets: Option<String>,
541546
storage_keys: Option<String>,
542547
) -> FutureResult<sp_rpc::tracing::TraceBlockResponse> {
548+
let block_executor = sc_tracing::block::BlockExecutor::new(
549+
self.client.clone(),
550+
block,
551+
targets,
552+
storage_keys,
553+
self.rpc_max_payload,
554+
);
543555
Box::new(result(
544-
sc_tracing::block::BlockExecutor::new(self.client.clone(), block, targets, storage_keys)
545-
.trace_block()
556+
block_executor.trace_block()
546557
.map_err(|e| invalid_block::<Block>(block, None, e.to_string()))
547558
))
548559
}

client/rpc/src/state/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn should_return_storage() {
6363
Arc::new(client),
6464
SubscriptionManager::new(Arc::new(TaskExecutor)),
6565
DenyUnsafe::No,
66+
None,
6667
);
6768
let key = StorageKey(KEY.to_vec());
6869

@@ -105,6 +106,7 @@ fn should_return_child_storage() {
105106
client,
106107
SubscriptionManager::new(Arc::new(TaskExecutor)),
107108
DenyUnsafe::No,
109+
None,
108110
);
109111
let child_key = prefixed_storage_key();
110112
let key = StorageKey(b"key".to_vec());
@@ -144,6 +146,7 @@ fn should_call_contract() {
144146
client,
145147
SubscriptionManager::new(Arc::new(TaskExecutor)),
146148
DenyUnsafe::No,
149+
None,
147150
);
148151

149152
assert_matches!(
@@ -162,6 +165,7 @@ fn should_notify_about_storage_changes() {
162165
client.clone(),
163166
SubscriptionManager::new(Arc::new(TaskExecutor)),
164167
DenyUnsafe::No,
168+
None,
165169
);
166170

167171
api.subscribe_storage(Default::default(), subscriber, None.into());
@@ -200,6 +204,7 @@ fn should_send_initial_storage_changes_and_notifications() {
200204
client.clone(),
201205
SubscriptionManager::new(Arc::new(TaskExecutor)),
202206
DenyUnsafe::No,
207+
None,
203208
);
204209

205210
let alice_balance_key = blake2_256(&runtime::system::balance_of_key(AccountKeyring::Alice.into()));
@@ -242,6 +247,7 @@ fn should_query_storage() {
242247
client.clone(),
243248
SubscriptionManager::new(Arc::new(TaskExecutor)),
244249
DenyUnsafe::No,
250+
None,
245251
);
246252

247253
let mut add_block = |nonce| {
@@ -463,6 +469,7 @@ fn should_return_runtime_version() {
463469
client.clone(),
464470
SubscriptionManager::new(Arc::new(TaskExecutor)),
465471
DenyUnsafe::No,
472+
None,
466473
);
467474

468475
let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\
@@ -490,6 +497,7 @@ fn should_notify_on_runtime_version_initially() {
490497
client.clone(),
491498
SubscriptionManager::new(Arc::new(TaskExecutor)),
492499
DenyUnsafe::No,
500+
None,
493501
);
494502

495503
api.subscribe_runtime_version(Default::default(), subscriber);

0 commit comments

Comments
 (0)