Limit GetBlocks response size

Put a hard limit of 1024 blocks in the response returned by
GetBlocks to avoid slowing things down. This number was chosen
rather arbitrarily. We might want to do some more fine tuning.
This commit is contained in:
Giacomo Pasini 2023-11-06 20:54:24 +01:00
parent 0730e05a6f
commit 4818d551c4
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
1 changed files with 5 additions and 1 deletions

View File

@ -55,6 +55,9 @@ use overwatch_rs::services::{
};
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
// Limit the number of blocks returned by GetBlocks
// Approx 64KB of data
const BLOCKS_LIMIT: usize = 512;
fn default_timeout() -> Duration {
DEFAULT_TIMEOUT
@ -441,7 +444,8 @@ where
while let Some(block) = blocks.get(&cur) {
res.push(block.clone());
if cur == to || cur == carnot.genesis_block().id {
// limit the response size
if cur == to || cur == carnot.genesis_block().id || res.len() >= BLOCKS_LIMIT {
break;
}
cur = block.parent();