fn override_method_response_sizes(
        rpc: RpcModule<()>,
        response_size_overrides: &MaxResponseSizeOverrides,
    ) -> anyhow::Result<Methods> {
        let rpc = Methods::from(rpc);
        let mut output_rpc = Methods::new();

        for method_name in rpc.method_names() {
            let method = rpc
                .method(method_name)
                .with_context(|| format!("method `{method_name}` disappeared from RPC module"))?;
            let response_size_limit = response_size_overrides.get(method_name);

            let method = match (method, response_size_limit) {
                (MethodCallback::Sync(sync_method), Some(limit)) => {
                    tracing::info!(
                        "Overriding max response size to {limit}B for sync method `{method_name}`"
                    );
                    let sync_method = sync_method.clone();
                    MethodCallback::Sync(Arc::new(move |id, params, _max_response_size, ext| {
                        sync_method(id, params, limit, ext)
                    }))
                }
                (MethodCallback::Async(async_method), Some(limit)) => {
                    tracing::info!(
                        "Overriding max response size to {limit}B for async method `{method_name}`"
                    );
                    let async_method = async_method.clone();
                    MethodCallback::Async(Arc::new(
                        move |id, params, connection_id, _max_response_size, ext| {
                            async_method(id, params, connection_id, limit, ext)
                        },
                    ))
                }
                (MethodCallback::Unsubscription(unsub_method), Some(limit)) => {
                    tracing::info!(
                        "Overriding max response size to {limit}B for unsub method `{method_name}`"
                    );
                    let unsub_method = unsub_method.clone();
                    MethodCallback::Unsubscription(Arc::new(
                        move |id, params, connection_id, _max_response_size, ext| {
                            unsub_method(id, params, connection_id, limit, ext)
                        },
                    ))
                }
                _ => method.clone(),
            };
            output_rpc.verify_and_insert(method_name, method)?;
        }

        Ok(output_rpc)
    }
Overrides max response sizes for specific RPC methods by additionally wrapping their callbacks
to which the max response size is passed as a param.
core/node/api_server/src/web3/mod.rs