Skip to content

Commit

Permalink
Enforce blocks response limit (#12146)
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc authored Sep 5, 2022
1 parent 6d84315 commit 19e6280
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions client/network/sync/src/block_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,20 @@ where
indexed_body,
};

total_size += block_data.body.iter().map(|ex| ex.len()).sum::<usize>();
total_size += block_data.indexed_body.iter().map(|ex| ex.len()).sum::<usize>();
let new_total_size = total_size +
block_data.body.iter().map(|ex| ex.len()).sum::<usize>() +
block_data.indexed_body.iter().map(|ex| ex.len()).sum::<usize>();

// Send at least one block, but make sure to not exceed the limit.
if !blocks.is_empty() && new_total_size > MAX_BODY_BYTES {
break
}

total_size = new_total_size;

blocks.push(block_data);

if blocks.len() >= max_blocks as usize || total_size > MAX_BODY_BYTES {
if blocks.len() >= max_blocks as usize {
break
}

Expand Down

0 comments on commit 19e6280

Please sign in to comment.