Make max_blobs_per_block a config parameter (#6329)

* First pass

* Add restrictions to RuntimeVariableList api

* Use empty_uninitialized and fix warnings

* Fix some todos

* Merge branch 'unstable' into max-blobs-preset

* Fix take impl on RuntimeFixedList

* cleanup

* Fix test compilations

* Fix some more tests

* Fix test from unstable

* Merge branch 'unstable' into max-blobs-preset

* Merge remote-tracking branch 'origin/unstable' into max-blobs-preset

* Remove footgun function

* Minor simplifications

* Move from preset to config

* Fix typo

* Revert "Remove footgun function"

This reverts commit de01f923c7.

* Try fixing tests

* Thread through ChainSpec

* Fix release tests

* Move RuntimeFixedVector into module and rename

* Add test

* Remove empty RuntimeVarList awefullness

* Fix tests

* Simplify BlobSidecarListFromRoot

* Merge remote-tracking branch 'origin/unstable' into max-blobs-preset

* Bump quota to account for new target (6)

* Remove clone

* Fix issue from review

* Try to remove ugliness

* Merge branch 'unstable' into max-blobs-preset

* Fix max value

* Fix doctest

* Fix formatting

* Fix max check

* Delete hardcoded max_blobs_per_block in RPC limits

* Merge remote-tracking branch 'origin/unstable' into max-blobs-preset
This commit is contained in:
Pawan Dhananjay
2025-01-10 12:04:58 +05:30
committed by GitHub
parent ecdf2d891f
commit 05727290fb
61 changed files with 655 additions and 335 deletions

View File

@@ -6,10 +6,11 @@ use serde::{Deserialize, Serialize};
use std::future::Future;
use std::hash::Hash;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
use tokio::time::Interval;
use types::EthSpec;
use types::{ChainSpec, EthSpec, ForkContext, ForkName};
/// Nanoseconds since a given time.
// Maintained as u64 to reduce footprint
@@ -109,6 +110,7 @@ pub struct RPCRateLimiter {
lc_finality_update_rl: Limiter<PeerId>,
/// LightClientUpdatesByRange rate limiter.
lc_updates_by_range_rl: Limiter<PeerId>,
fork_context: Arc<ForkContext>,
}
/// Error type for non conformant requests
@@ -176,7 +178,7 @@ impl RPCRateLimiterBuilder {
self
}
pub fn build(self) -> Result<RPCRateLimiter, &'static str> {
pub fn build(self, fork_context: Arc<ForkContext>) -> Result<RPCRateLimiter, &'static str> {
// get our quotas
let ping_quota = self.ping_quota.ok_or("Ping quota not specified")?;
let metadata_quota = self.metadata_quota.ok_or("MetaData quota not specified")?;
@@ -253,13 +255,14 @@ impl RPCRateLimiterBuilder {
lc_finality_update_rl,
lc_updates_by_range_rl,
init_time: Instant::now(),
fork_context,
})
}
}
pub trait RateLimiterItem {
fn protocol(&self) -> Protocol;
fn max_responses(&self) -> u64;
fn max_responses(&self, current_fork: ForkName, spec: &ChainSpec) -> u64;
}
impl<E: EthSpec> RateLimiterItem for super::RequestType<E> {
@@ -267,13 +270,16 @@ impl<E: EthSpec> RateLimiterItem for super::RequestType<E> {
self.versioned_protocol().protocol()
}
fn max_responses(&self) -> u64 {
self.max_responses()
fn max_responses(&self, current_fork: ForkName, spec: &ChainSpec) -> u64 {
self.max_responses(current_fork, spec)
}
}
impl RPCRateLimiter {
pub fn new_with_config(config: RateLimiterConfig) -> Result<Self, &'static str> {
pub fn new_with_config(
config: RateLimiterConfig,
fork_context: Arc<ForkContext>,
) -> Result<Self, &'static str> {
// Destructure to make sure every configuration value is used.
let RateLimiterConfig {
ping_quota,
@@ -316,7 +322,7 @@ impl RPCRateLimiter {
Protocol::LightClientUpdatesByRange,
light_client_updates_by_range_quota,
)
.build()
.build(fork_context)
}
/// Get a builder instance.
@@ -330,7 +336,9 @@ impl RPCRateLimiter {
request: &Item,
) -> Result<(), RateLimitedErr> {
let time_since_start = self.init_time.elapsed();
let tokens = request.max_responses().max(1);
let tokens = request
.max_responses(self.fork_context.current_fork(), &self.fork_context.spec)
.max(1);
let check =
|limiter: &mut Limiter<PeerId>| limiter.allows(time_since_start, peer_id, tokens);