Skip to content

Commit

Permalink
refactor(peer_loop): Limit block-batch size to 250
Browse files Browse the repository at this point in the history
Ensure that messages with more than 250 blocks are never sent.

In e491b2e, the default reorganization
tolerance was increased from 100 to 1.000 blocks, and the max number of
blocks in these messages are affected by that value. So this commit
intends to prevent too big messages from being sent, as I though 1.000
blocks (~600MB) were too big messages.
  • Loading branch information
Sword-Smith committed Jan 16, 2025
1 parent 09671d0 commit 3ab413c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/peer_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::models::state::mempool::MEMPOOL_IGNORE_TRANSACTIONS_THIS_MANY_SECS_AH
use crate::models::state::mempool::MEMPOOL_TX_THRESHOLD_AGE_IN_SECS;
use crate::models::state::GlobalStateLock;

const STANDARD_BLOCK_BATCH_SIZE: usize = 50;
const STANDARD_BLOCK_BATCH_SIZE: usize = 250;
const MAX_PEER_LIST_LENGTH: usize = 10;
const MINIMUM_BLOCK_BATCH_SIZE: usize = 2;

Expand Down Expand Up @@ -643,14 +643,16 @@ impl PeerLoopHandler {
);

// Get the relevant blocks, at most batch-size many, descending from the
// peer's (alleged) most canonical block.
// peer's (alleged) most canonical block. Don't exceed `max_response_len`
// or `STANDARD_BLOCK_BATCH_SIZE` number of blocks in response.
let len_of_response = cmp::min(
max_response_len,
self.global_state_lock
.cli()
.max_number_of_blocks_before_syncing,
);
let len_of_response = cmp::max(len_of_response, MINIMUM_BLOCK_BATCH_SIZE);
let len_of_response = cmp::min(len_of_response, STANDARD_BLOCK_BATCH_SIZE);

let mut digests_of_returned_blocks = Vec::with_capacity(len_of_response);
let response_start_height: u64 = peers_preferred_canonical_block.into();
Expand Down

0 comments on commit 3ab413c

Please sign in to comment.