Skip to content

Commit e8a416b

Browse files
AndreiEressandreim
authored andcommitted
Use maximum allowed response size for request/response protocols (#5753)
# Description Adjust the PoV response size to the default values used in the substrate. Fixes #5503 ## Integration The changes shouldn't impact downstream projects since we are only increasing the limit. ## Review Notes You can't see it from the changes, but it affects all protocols that use the `POV_RESPONSE_SIZE` constant. - Protocol::ChunkFetchingV1 - Protocol::ChunkFetchingV2 - Protocol::CollationFetchingV1 - Protocol::CollationFetchingV2 - Protocol::PoVFetchingV1 - Protocol::AvailableDataFetchingV1 ## Increasing timeouts https://github.com/paritytech/polkadot-sdk/blob/fae15379cba0c876aa16c77e11809c83d1db8f5c/polkadot/node/network/protocol/src/request_response/mod.rs#L126-L129 I assume the current PoV request timeout is set to 1.2s to handle 5 consecutive requests during a 6s block. This setting does not relate to the PoV response size. I see no reason to change the current timeouts after adjusting the response size. However, we should consider networking speed limitations if we want to increase the maximum PoV size to 10 MB. With the number of parallel requests set to 10, validators will need the following networking speeds: - 5 MB PoV: at least 42 MB/s, ideally 50 MB/s. - 10 MB PoV: at least 84 MB/s, ideally 100 MB/s. The current required speed of 50 MB/s aligns with the 62.5 MB/s specified [in the reference hardware requirements](https://wiki.polkadot.network/docs/maintain-guides-how-to-validate-polkadot#reference-hardware). Increasing the PoV size to 10 MB may require a higher networking speed. --------- Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com> (cherry picked from commit 0c9d8fe)
1 parent 87971b3 commit e8a416b

10 files changed

Lines changed: 44 additions & 20 deletions

File tree

polkadot/node/network/protocol/src/request_response/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
5252
use std::{collections::HashMap, time::Duration, u64};
5353

54-
use polkadot_primitives::{MAX_CODE_SIZE, MAX_POV_SIZE};
55-
use sc_network::NetworkBackend;
54+
use polkadot_primitives::MAX_CODE_SIZE;
55+
use sc_network::{NetworkBackend, MAX_RESPONSE_SIZE};
5656
use sp_runtime::traits::Block;
5757
use strum::{EnumIter, IntoEnumIterator};
5858

@@ -159,11 +159,8 @@ pub const MAX_PARALLEL_ATTESTED_CANDIDATE_REQUESTS: u32 = 5;
159159

160160
/// Response size limit for responses of POV like data.
161161
///
162-
/// This is larger than `MAX_POV_SIZE` to account for protocol overhead and for additional data in
163-
/// `CollationFetchingV1` or `AvailableDataFetchingV1` for example. We try to err on larger limits
164-
/// here as a too large limit only allows an attacker to waste our bandwidth some more, a too low
165-
/// limit might have more severe effects.
166-
const POV_RESPONSE_SIZE: u64 = MAX_POV_SIZE as u64 + 10_000;
162+
/// Same as what we use in substrate networking.
163+
const POV_RESPONSE_SIZE: u64 = MAX_RESPONSE_SIZE;
167164

168165
/// Maximum response sizes for `StatementFetchingV1`.
169166
///
@@ -217,7 +214,7 @@ impl Protocol {
217214
name,
218215
legacy_names,
219216
1_000,
220-
POV_RESPONSE_SIZE as u64 * 3,
217+
POV_RESPONSE_SIZE,
221218
// We are connected to all validators:
222219
CHUNK_REQUEST_TIMEOUT,
223220
tx,

prdoc/pr_5753.prdoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Use maximum allowed response size for request/response protocols
5+
6+
doc:
7+
- audience: Node Dev
8+
description: |
9+
Increase maximum PoV response size to 16MB which is equal to the default value used in the substrate.
10+
11+
crates:
12+
- name: sc-network
13+
bump: patch
14+
- name: sc-network-light
15+
bump: patch
16+
- name: sc-network-sync
17+
bump: patch
18+
- name: polkadot-node-network-protocol
19+
bump: patch
20+
- name: sc-network-transactions
21+
bump: patch

substrate/client/network/light/src/light_client_requests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
//! Helpers for outgoing and incoming light client requests.
2020
21-
use sc_network::{config::ProtocolId, request_responses::IncomingRequest, NetworkBackend};
21+
use sc_network::{
22+
config::ProtocolId, request_responses::IncomingRequest, NetworkBackend, MAX_RESPONSE_SIZE,
23+
};
2224
use sp_runtime::traits::Block;
2325

2426
use std::time::Duration;
@@ -57,7 +59,7 @@ pub fn generate_protocol_config<
5759
generate_protocol_name(genesis_hash, fork_id).into(),
5860
std::iter::once(generate_legacy_protocol_name(protocol_id).into()).collect(),
5961
1 * 1024 * 1024,
60-
16 * 1024 * 1024,
62+
MAX_RESPONSE_SIZE,
6163
Duration::from_secs(15),
6264
Some(inbound_queue),
6365
)

substrate/client/network/src/bitswap/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use crate::{
2424
request_responses::{IncomingRequest, OutgoingResponse, ProtocolConfig},
2525
types::ProtocolName,
26+
MAX_RESPONSE_SIZE,
2627
};
2728

2829
use cid::{self, Version};
@@ -47,7 +48,7 @@ const LOG_TARGET: &str = "bitswap";
4748
// https://github.com/ipfs/js-ipfs-bitswap/blob/
4849
// d8f80408aadab94c962f6b88f343eb9f39fa0fcc/src/decision-engine/index.js#L16
4950
// We set it to the same value as max substrate protocol message
50-
const MAX_PACKET_SIZE: u64 = 16 * 1024 * 1024;
51+
const MAX_PACKET_SIZE: u64 = MAX_RESPONSE_SIZE;
5152

5253
/// Max number of queued responses before denying requests.
5354
const MAX_REQUEST_QUEUE: usize = 20;

substrate/client/network/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,6 @@ const MAX_CONNECTIONS_PER_PEER: usize = 2;
302302

303303
/// The maximum number of concurrent established connections that were incoming.
304304
const MAX_CONNECTIONS_ESTABLISHED_INCOMING: u32 = 10_000;
305+
306+
/// Maximum response size limit.
307+
pub const MAX_RESPONSE_SIZE: u64 = 16 * 1024 * 1024;

substrate/client/network/src/protocol.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
protocol_controller::{self, SetId},
2323
service::{metrics::NotificationMetrics, traits::Direction},
2424
types::ProtocolName,
25+
MAX_RESPONSE_SIZE,
2526
};
2627

2728
use codec::Encode;
@@ -56,7 +57,7 @@ pub mod message;
5657

5758
/// Maximum size used for notifications in the block announce and transaction protocols.
5859
// Must be equal to `max(MAX_BLOCK_ANNOUNCE_SIZE, MAX_TRANSACTIONS_SIZE)`.
59-
pub(crate) const BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE: u64 = 16 * 1024 * 1024;
60+
pub(crate) const BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE: u64 = MAX_RESPONSE_SIZE;
6061

6162
/// Identifier of the peerset for the block announces protocol.
6263
const HARDCODED_PEERSETS_SYNC: SetId = SetId::from(0);

substrate/client/network/sync/src/block_request_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use sc_network::{
3939
request_responses::{IfDisconnected, IncomingRequest, OutgoingResponse, RequestFailure},
4040
service::traits::RequestResponseConfig,
4141
types::ProtocolName,
42-
NetworkBackend,
42+
NetworkBackend, MAX_RESPONSE_SIZE,
4343
};
4444
use sc_network_common::sync::message::{BlockAttributes, BlockData, BlockRequest, FromBlock};
4545
use sc_network_types::PeerId;
@@ -89,7 +89,7 @@ pub fn generate_protocol_config<
8989
generate_protocol_name(genesis_hash, fork_id).into(),
9090
std::iter::once(generate_legacy_protocol_name(protocol_id).into()).collect(),
9191
1024 * 1024,
92-
16 * 1024 * 1024,
92+
MAX_RESPONSE_SIZE,
9393
Duration::from_secs(20),
9494
Some(inbound_queue),
9595
)

substrate/client/network/sync/src/state_request_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sc_client_api::{BlockBackend, ProofProvider};
3333
use sc_network::{
3434
config::ProtocolId,
3535
request_responses::{IncomingRequest, OutgoingResponse},
36-
NetworkBackend,
36+
NetworkBackend, MAX_RESPONSE_SIZE,
3737
};
3838
use sp_runtime::traits::Block as BlockT;
3939

@@ -69,7 +69,7 @@ pub fn generate_protocol_config<
6969
generate_protocol_name(genesis_hash, fork_id).into(),
7070
std::iter::once(generate_legacy_protocol_name(protocol_id).into()).collect(),
7171
1024 * 1024,
72-
16 * 1024 * 1024,
72+
MAX_RESPONSE_SIZE,
7373
Duration::from_secs(40),
7474
Some(inbound_queue),
7575
)

substrate/client/network/sync/src/warp_request_handler.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ use crate::{
2727
use sc_network::{
2828
config::ProtocolId,
2929
request_responses::{IncomingRequest, OutgoingResponse},
30-
NetworkBackend,
30+
NetworkBackend, MAX_RESPONSE_SIZE,
3131
};
3232
use sp_runtime::traits::Block as BlockT;
3333

3434
use std::{sync::Arc, time::Duration};
3535

36-
const MAX_RESPONSE_SIZE: u64 = 16 * 1024 * 1024;
37-
3836
/// Incoming warp requests bounded queue size.
3937
const MAX_WARP_REQUEST_QUEUE: usize = 20;
4038

substrate/client/network/transactions/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! Configuration of the transaction protocol
2020
2121
use futures::prelude::*;
22+
use sc_network::MAX_RESPONSE_SIZE;
2223
use sc_network_common::ExHashT;
2324
use sp_runtime::traits::Block as BlockT;
2425
use std::{collections::HashMap, future::Future, pin::Pin, time};
@@ -32,7 +33,7 @@ pub(crate) const PROPAGATE_TIMEOUT: time::Duration = time::Duration::from_millis
3233
pub(crate) const MAX_KNOWN_TRANSACTIONS: usize = 10240; // ~300kb per peer + overhead.
3334

3435
/// Maximum allowed size for a transactions notification.
35-
pub(crate) const MAX_TRANSACTIONS_SIZE: u64 = 16 * 1024 * 1024;
36+
pub(crate) const MAX_TRANSACTIONS_SIZE: u64 = MAX_RESPONSE_SIZE;
3637

3738
/// Maximum number of transaction validation request we keep at any moment.
3839
pub(crate) const MAX_PENDING_TRANSACTIONS: usize = 8192;

0 commit comments

Comments
 (0)