Make it possible to override maximum payload of RPC (#9019)

* Make it possible to override maximum payload of RPC

* Finish it.

* remove todo.

* Update client/cli/src/commands/run_cmd.rs

* Apply suggestions from code review

Co-authored-by: David <dvdplm@gmail.com>

* Apply suggestions from code review

Co-authored-by: David <dvdplm@gmail.com>

* Incorporate suggestions

* Thread rpc_max_payload from configuration to trace_block

* Try obey line gitlab/check_line_width.sh

* update state rpc tests

* Improve readbility

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>
Co-authored-by: David <dvdplm@gmail.com>
This commit is contained in:
Kian Paimani
2021-06-17 16:37:43 +02:00
committed by GitHub
parent 1278b9a6d4
commit 4d6802c530
14 changed files with 87 additions and 26 deletions
+5 -2
View File
@@ -182,6 +182,7 @@ pub fn new_full<BE, Block: BlockT, Client>(
client: Arc<Client>,
subscriptions: SubscriptionManager,
deny_unsafe: DenyUnsafe,
rpc_max_payload: Option<usize>,
) -> (State<Block, Client>, ChildState<Block, Client>)
where
Block: BlockT + 'static,
@@ -193,9 +194,11 @@ pub fn new_full<BE, Block: BlockT, Client>(
Client::Api: Metadata<Block>,
{
let child_backend = Box::new(
self::state_full::FullState::new(client.clone(), subscriptions.clone())
self::state_full::FullState::new(
client.clone(), subscriptions.clone(), rpc_max_payload
)
);
let backend = Box::new(self::state_full::FullState::new(client, subscriptions));
let backend = Box::new(self::state_full::FullState::new(client, subscriptions, rpc_max_payload));
(State { backend, deny_unsafe }, ChildState { backend: child_backend })
}
+16 -5
View File
@@ -67,7 +67,8 @@ struct QueryStorageRange<Block: BlockT> {
pub struct FullState<BE, Block: BlockT, Client> {
client: Arc<Client>,
subscriptions: SubscriptionManager,
_phantom: PhantomData<(BE, Block)>
_phantom: PhantomData<(BE, Block)>,
rpc_max_payload: Option<usize>,
}
impl<BE, Block: BlockT, Client> FullState<BE, Block, Client>
@@ -78,8 +79,12 @@ impl<BE, Block: BlockT, Client> FullState<BE, Block, Client>
Block: BlockT + 'static,
{
/// Create new state API backend for full nodes.
pub fn new(client: Arc<Client>, subscriptions: SubscriptionManager) -> Self {
Self { client, subscriptions, _phantom: PhantomData }
pub fn new(
client: Arc<Client>,
subscriptions: SubscriptionManager,
rpc_max_payload: Option<usize>,
) -> Self {
Self { client, subscriptions, _phantom: PhantomData, rpc_max_payload }
}
/// 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
targets: Option<String>,
storage_keys: Option<String>,
) -> FutureResult<sp_rpc::tracing::TraceBlockResponse> {
let block_executor = sc_tracing::block::BlockExecutor::new(
self.client.clone(),
block,
targets,
storage_keys,
self.rpc_max_payload,
);
Box::new(result(
sc_tracing::block::BlockExecutor::new(self.client.clone(), block, targets, storage_keys)
.trace_block()
block_executor.trace_block()
.map_err(|e| invalid_block::<Block>(block, None, e.to_string()))
))
}
+8
View File
@@ -63,6 +63,7 @@ fn should_return_storage() {
Arc::new(client),
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
let key = StorageKey(KEY.to_vec());
@@ -105,6 +106,7 @@ fn should_return_child_storage() {
client,
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
let child_key = prefixed_storage_key();
let key = StorageKey(b"key".to_vec());
@@ -144,6 +146,7 @@ fn should_call_contract() {
client,
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
assert_matches!(
@@ -162,6 +165,7 @@ fn should_notify_about_storage_changes() {
client.clone(),
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
api.subscribe_storage(Default::default(), subscriber, None.into());
@@ -200,6 +204,7 @@ fn should_send_initial_storage_changes_and_notifications() {
client.clone(),
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
let alice_balance_key = blake2_256(&runtime::system::balance_of_key(AccountKeyring::Alice.into()));
@@ -242,6 +247,7 @@ fn should_query_storage() {
client.clone(),
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
let mut add_block = |nonce| {
@@ -463,6 +469,7 @@ fn should_return_runtime_version() {
client.clone(),
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\
@@ -490,6 +497,7 @@ fn should_notify_on_runtime_version_initially() {
client.clone(),
SubscriptionManager::new(Arc::new(TaskExecutor)),
DenyUnsafe::No,
None,
);
api.subscribe_runtime_version(Default::default(), subscriber);