Limit GetBlocks response size (#515)
Put a hard limit of 512 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
a58d3fb63c
commit
df683ad154
@ -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…
x
Reference in New Issue
Block a user