mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Restrict network limits based on merge fork epoch (#2839)
This commit is contained in:
committed by
Paul Hauner
parent
144978f8f8
commit
f3c237cfa0
@@ -22,7 +22,7 @@ use tokio_util::{
|
||||
};
|
||||
use types::{
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, EthSpec, ForkContext,
|
||||
Hash256, MainnetEthSpec, Signature, SignedBeaconBlock,
|
||||
ForkName, Hash256, MainnetEthSpec, Signature, SignedBeaconBlock,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
@@ -92,8 +92,10 @@ lazy_static! {
|
||||
|
||||
}
|
||||
|
||||
/// The maximum bytes that can be sent across the RPC.
|
||||
pub const MAX_RPC_SIZE: usize = 10 * 1_048_576; // 10M
|
||||
/// The maximum bytes that can be sent across the RPC pre-merge.
|
||||
pub(crate) const MAX_RPC_SIZE: usize = 1_048_576; // 1M
|
||||
/// The maximum bytes that can be sent across the RPC post-merge.
|
||||
pub(crate) const MAX_RPC_SIZE_POST_MERGE: usize = 10 * 1_048_576; // 10M
|
||||
/// The protocol prefix the RPC protocol id.
|
||||
const PROTOCOL_PREFIX: &str = "/eth2/beacon_chain/req";
|
||||
/// Time allowed for the first byte of a request to arrive before we time out (Time To First Byte).
|
||||
@@ -102,6 +104,15 @@ const TTFB_TIMEOUT: u64 = 5;
|
||||
/// established before the stream is terminated.
|
||||
const REQUEST_TIMEOUT: u64 = 15;
|
||||
|
||||
/// Returns the maximum bytes that can be sent across the RPC.
|
||||
pub fn max_rpc_size(fork_context: &ForkContext) -> usize {
|
||||
if fork_context.fork_exists(ForkName::Merge) {
|
||||
MAX_RPC_SIZE_POST_MERGE
|
||||
} else {
|
||||
MAX_RPC_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
/// Protocol names to be used.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Protocol {
|
||||
@@ -170,6 +181,7 @@ impl std::fmt::Display for Version {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RPCProtocol<TSpec: EthSpec> {
|
||||
pub fork_context: Arc<ForkContext>,
|
||||
pub max_rpc_size: usize,
|
||||
pub phantom: PhantomData<TSpec>,
|
||||
}
|
||||
|
||||
@@ -206,7 +218,7 @@ impl RpcLimits {
|
||||
Self { min, max }
|
||||
}
|
||||
|
||||
/// Returns true if the given length is greater than `MAX_RPC_SIZE` or out of
|
||||
/// Returns true if the given length is greater than `max_rpc_size` or out of
|
||||
/// bounds for the given ssz type, returns false otherwise.
|
||||
pub fn is_out_of_bounds(&self, length: usize, max_rpc_size: usize) -> bool {
|
||||
length > std::cmp::min(self.max, max_rpc_size) || length < self.min
|
||||
@@ -365,7 +377,7 @@ where
|
||||
Encoding::SSZSnappy => {
|
||||
let ssz_snappy_codec = BaseInboundCodec::new(SSZSnappyInboundCodec::new(
|
||||
protocol,
|
||||
MAX_RPC_SIZE,
|
||||
self.max_rpc_size,
|
||||
self.fork_context.clone(),
|
||||
));
|
||||
InboundCodec::SSZSnappy(ssz_snappy_codec)
|
||||
|
||||
Reference in New Issue
Block a user