Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Thread rpc_max_payload from configuration to trace_block
  • Loading branch information
emostov committed Jun 17, 2021
commit 24eaa76bfae1bd4262f5fa5d86024ca9bd5ef468
4 changes: 3 additions & 1 deletion client/rpc-servers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ mod inner {
io: RpcHandler<M>,
maybe_max_payload_mb: Option<usize>,
) -> io::Result<http::Server> {
let max_request_body_size = maybe_max_payload_mb.map(|mb| mb.saturating_mul(MEGABYTE))
.unwrap_or(RPC_MAX_PAYLOAD_DEFAULT);
http::ServerBuilder::new(io)
.threads(thread_pool_size.unwrap_or(HTTP_THREADS))
.health_api(("/health", "system_health"))
Expand All @@ -99,7 +101,7 @@ mod inner {
http::RestApi::Unsecure
})
.cors(map_cors::<http::AccessControlAllowOrigin>(cors))
.max_request_body_size(maybe_max_payload_mb.map(|mb| mb * MEGABYTE).unwrap_or(RPC_MAX_PAYLOAD_DEFAULT))
.max_request_body_size(max_request_body_size)
.start_http(addr)
}

Expand Down
7 changes: 5 additions & 2 deletions client/rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 })
}

Expand Down
19 changes: 13 additions & 6 deletions client/rpc/src/state/state_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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.
Expand Down Expand Up @@ -541,9 +546,11 @@ impl<BE, Block, Client> StateBackend<Block, Client> for FullState<BE, Block, Cli
storage_keys: Option<String>,
) -> FutureResult<sp_rpc::tracing::TraceBlockResponse> {
Box::new(result(
sc_tracing::block::BlockExecutor::new(self.client.clone(), block, targets, storage_keys)
.trace_block()
.map_err(|e| invalid_block::<Block>(block, None, e.to_string()))
sc_tracing::block::BlockExecutor::new(
self.client.clone(), block, targets, storage_keys, self.rpc_max_payload
)
.trace_block()
.map_err(|e| invalid_block::<Block>(block, None, e.to_string()))
))
}
}
Expand Down
1 change: 1 addition & 0 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ fn gen_handler<TBl, TBackend, TExPool, TRpc, TCl>(
client.clone(),
subscriptions.clone(),
deny_unsafe,
config.rpc_max_payload,
);
(chain, state, child_state)
};
Expand Down
10 changes: 8 additions & 2 deletions client/tracing/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const DEFAULT_TARGETS: &str = "pallet,frame,state";
const TRACE_TARGET: &str = "block_trace";
// The name of a field required for all events.
const REQUIRED_EVENT_FIELD: &str = "method";
const MEGABYTE: usize = 1024 * 1024;

/// Tracing Block Result type alias
pub type TraceBlockResult<T> = Result<T, Error>;
Expand Down Expand Up @@ -174,6 +175,7 @@ pub struct BlockExecutor<Block: BlockT, Client> {
block: Block::Hash,
targets: Option<String>,
storage_keys: Option<String>,
rpc_max_payload: usize,
}

impl<Block, Client> BlockExecutor<Block, Client>
Expand All @@ -189,8 +191,12 @@ impl<Block, Client> BlockExecutor<Block, Client>
block: Block::Hash,
targets: Option<String>,
storage_keys: Option<String>,
rpc_max_payload: Option<usize>,
) -> Self {
Self { client, block, targets, storage_keys }
let rpc_max_payload = rpc_max_payload.map(|mb| mb.saturating_mul(MEGABYTE))
.unwrap_or(RPC_MAX_PAYLOAD_DEFAULT);

Self { client, block, targets, storage_keys, rpc_max_payload }
}

/// Execute block, record all spans and events belonging to `Self::targets`
Expand Down Expand Up @@ -260,7 +266,7 @@ impl<Block, Client> BlockExecutor<Block, Client>
tracing::debug!(target: "state_tracing", "Captured {} spans and {} events", spans.len(), events.len());

let approx_payload_size = BASE_PAYLOAD + events.len() * AVG_EVENT + spans.len() * AVG_SPAN;
let response = if approx_payload_size > RPC_MAX_PAYLOAD_DEFAULT {
let response = if approx_payload_size > self.rpc_max_payload {
TraceBlockResponse::TraceError(TraceError {
error:
"Payload likely exceeds max payload size of RPC server.".to_string()
Expand Down