mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Enforce stricter checks on certain constants (#8500)
Which issue # does this PR address?
None
All of these are performing a check, and adding a batch, or creating a new lookup, or a new query, etc..
Hence all of these limits would be off by one.
Example:
```rust
// BACKFILL_BATCH_BUFFER_SIZE = 5
if self.batches.iter().filter(...).count() >= BACKFILL_BATCH_BUFFER_SIZE {
return None; // ← REJECT
}
// ... later adds batch via Entry::Vacant(entry).insert(...)
```
Without the `>` being changed to a `>=` , we would allow 6. The same idea applies to all changes proposed.
Co-Authored-By: Antoine James <antoine@ethereum.org>
Co-Authored-By: Jimmy Chen <jimmy@sigmaprime.io>
Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>
This commit is contained in:
@@ -674,7 +674,7 @@ impl<E: EthSpec> Discovery<E> {
|
|||||||
/// updates the min_ttl field.
|
/// updates the min_ttl field.
|
||||||
fn add_subnet_query(&mut self, subnet: Subnet, min_ttl: Option<Instant>, retries: usize) {
|
fn add_subnet_query(&mut self, subnet: Subnet, min_ttl: Option<Instant>, retries: usize) {
|
||||||
// remove the entry and complete the query if greater than the maximum search count
|
// remove the entry and complete the query if greater than the maximum search count
|
||||||
if retries > MAX_DISCOVERY_RETRY {
|
if retries >= MAX_DISCOVERY_RETRY {
|
||||||
debug!("Subnet peer discovery did not find sufficient peers. Reached max retry limit");
|
debug!("Subnet peer discovery did not find sufficient peers. Reached max retry limit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1071,7 +1071,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|&(_epoch, batch)| in_buffer(batch))
|
.filter(|&(_epoch, batch)| in_buffer(batch))
|
||||||
.count()
|
.count()
|
||||||
> BACKFILL_BATCH_BUFFER_SIZE as usize
|
>= BACKFILL_BATCH_BUFFER_SIZE as usize
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
|
|
||||||
// Lookups contain untrusted data, bound the total count of lookups hold in memory to reduce
|
// Lookups contain untrusted data, bound the total count of lookups hold in memory to reduce
|
||||||
// the risk of OOM in case of bugs of malicious activity.
|
// the risk of OOM in case of bugs of malicious activity.
|
||||||
if self.single_block_lookups.len() > MAX_LOOKUPS {
|
if self.single_block_lookups.len() >= MAX_LOOKUPS {
|
||||||
warn!(?block_root, "Dropping lookup reached max");
|
warn!(?block_root, "Dropping lookup reached max");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ impl<T: BeaconChainTypes> CustodyBackFillSync<T> {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|&(_epoch, batch)| in_buffer(batch))
|
.filter(|&(_epoch, batch)| in_buffer(batch))
|
||||||
.count()
|
.count()
|
||||||
> BACKFILL_BATCH_BUFFER_SIZE as usize
|
>= BACKFILL_BATCH_BUFFER_SIZE as usize
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
|
|||||||
if let Some(wait_duration) = request.is_awaiting_download() {
|
if let Some(wait_duration) = request.is_awaiting_download() {
|
||||||
// Note: an empty response is considered a successful response, so we may end up
|
// Note: an empty response is considered a successful response, so we may end up
|
||||||
// retrying many more times than `MAX_CUSTODY_COLUMN_DOWNLOAD_ATTEMPTS`.
|
// retrying many more times than `MAX_CUSTODY_COLUMN_DOWNLOAD_ATTEMPTS`.
|
||||||
if request.download_failures > MAX_CUSTODY_COLUMN_DOWNLOAD_ATTEMPTS {
|
if request.download_failures >= MAX_CUSTODY_COLUMN_DOWNLOAD_ATTEMPTS {
|
||||||
return Err(Error::TooManyFailures);
|
return Err(Error::TooManyFailures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1277,7 +1277,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|&(_epoch, batch)| in_buffer(batch))
|
.filter(|&(_epoch, batch)| in_buffer(batch))
|
||||||
.count()
|
.count()
|
||||||
> BATCH_BUFFER_SIZE as usize
|
>= BATCH_BUFFER_SIZE as usize
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user