Skip to content

Commit

Permalink
Merge pull request #1745 from subspace/fix-segment-headers-limit
Browse files Browse the repository at this point in the history
Fix segment headers limit
  • Loading branch information
nazar-pc authored Aug 3, 2023
2 parents 13c49a0 + 22b5922 commit 26105b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ use subspace_networking::{
PieceByHashRequestHandler, PieceByHashResponse, SegmentHeaderBySegmentIndexesRequestHandler,
SegmentHeaderRequest, SegmentHeaderResponse,
};
use subspace_rpc_primitives::MAX_SEGMENT_HEADERS_PER_REQUEST;
use tracing::{debug, error, info, Instrument};

const SEGMENT_HEADER_NUMBER_LIMIT: u64 = 1000;
/// How many segment headers can be requested at a time.
///
/// Must be the same as RPC limit since all requests go to the node anyway.
const SEGMENT_HEADER_NUMBER_LIMIT: u64 = MAX_SEGMENT_HEADERS_PER_REQUEST as u64;

#[allow(clippy::type_complexity, clippy::too_many_arguments)]
pub(super) fn configure_dsn(
Expand Down Expand Up @@ -210,14 +214,15 @@ pub(super) fn configure_dsn(
segment_indexes.clone()
}
SegmentHeaderRequest::LastSegmentHeaders {
segment_header_number,
mut segment_header_number,
} => {
if segment_header_number > SEGMENT_HEADER_NUMBER_LIMIT {
debug!(
%segment_header_number,
"Segment header number exceeded the limit."
);
return None;

segment_header_number = SEGMENT_HEADER_NUMBER_LIMIT;
}

let last_segment_index = SegmentIndex::from(
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-rpc-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use subspace_farmer_components::FarmerProtocolInfo;
use subspace_networking::libp2p::Multiaddr;

/// Defines a limit for number of segments that can be requested over RPC
pub const MAX_SEGMENT_HEADERS_PER_REQUEST: usize = 300;
pub const MAX_SEGMENT_HEADERS_PER_REQUEST: usize = 1000;

/// Information necessary for farmer application
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-service/src/dsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use subspace_networking::{
use thiserror::Error;
use tracing::{debug, error, trace};

const SEGMENT_HEADERS_NUMBER_LIMIT: u64 = 100;
const SEGMENT_HEADERS_NUMBER_LIMIT: u64 = 1000;

/// Errors that might happen during DSN configuration.
#[derive(Debug, Error)]
Expand Down

0 comments on commit 26105b3

Please sign in to comment.