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:
parent
0730e05a6f
commit
4818d551c4
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue