mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Avoid computing rpc_blob_limits multiple times (#6595)
* Compute blob rpc limits in static block * Fix min size * Use MainnetEthSpec in rpc tests * Revert MainnetEthSpec; add another constant for blob size minimal
This commit is contained in:
@@ -18,11 +18,11 @@ use tokio_util::{
|
|||||||
};
|
};
|
||||||
use types::{
|
use types::{
|
||||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockCapella, BeaconBlockElectra,
|
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockCapella, BeaconBlockElectra,
|
||||||
BlobSidecar, ChainSpec, DataColumnSidecar, EmptyBlock, EthSpec, ForkContext, ForkName,
|
BlobSidecar, ChainSpec, DataColumnSidecar, EmptyBlock, EthSpec, EthSpecId, ForkContext,
|
||||||
LightClientBootstrap, LightClientBootstrapAltair, LightClientFinalityUpdate,
|
ForkName, LightClientBootstrap, LightClientBootstrapAltair, LightClientFinalityUpdate,
|
||||||
LightClientFinalityUpdateAltair, LightClientOptimisticUpdate,
|
LightClientFinalityUpdateAltair, LightClientOptimisticUpdate,
|
||||||
LightClientOptimisticUpdateAltair, LightClientUpdate, MainnetEthSpec, Signature,
|
LightClientOptimisticUpdateAltair, LightClientUpdate, MainnetEthSpec, MinimalEthSpec,
|
||||||
SignedBeaconBlock,
|
Signature, SignedBeaconBlock,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: Hardcoding the `EthSpec` type for `SignedBeaconBlock` as min/max values is
|
// Note: Hardcoding the `EthSpec` type for `SignedBeaconBlock` as min/max values is
|
||||||
@@ -105,6 +105,20 @@ pub static SIGNED_BEACON_BLOCK_ELECTRA_MAX: LazyLock<usize> = LazyLock::new(|| {
|
|||||||
+ ssz::BYTES_PER_LENGTH_OFFSET
|
+ ssz::BYTES_PER_LENGTH_OFFSET
|
||||||
}); // Length offset for the blob commitments field.
|
}); // Length offset for the blob commitments field.
|
||||||
|
|
||||||
|
pub static BLOB_SIDECAR_SIZE: LazyLock<usize> =
|
||||||
|
LazyLock::new(BlobSidecar::<MainnetEthSpec>::max_size);
|
||||||
|
|
||||||
|
pub static BLOB_SIDECAR_SIZE_MINIMAL: LazyLock<usize> =
|
||||||
|
LazyLock::new(BlobSidecar::<MinimalEthSpec>::max_size);
|
||||||
|
|
||||||
|
pub static DATA_COLUMNS_SIDECAR_MIN: LazyLock<usize> = LazyLock::new(|| {
|
||||||
|
DataColumnSidecar::<MainnetEthSpec>::empty()
|
||||||
|
.as_ssz_bytes()
|
||||||
|
.len()
|
||||||
|
});
|
||||||
|
pub static DATA_COLUMNS_SIDECAR_MAX: LazyLock<usize> =
|
||||||
|
LazyLock::new(DataColumnSidecar::<MainnetEthSpec>::max_size);
|
||||||
|
|
||||||
pub static ERROR_TYPE_MIN: LazyLock<usize> = LazyLock::new(|| {
|
pub static ERROR_TYPE_MIN: LazyLock<usize> = LazyLock::new(|| {
|
||||||
VariableList::<u8, MaxErrorLen>::from(Vec::<u8>::new())
|
VariableList::<u8, MaxErrorLen>::from(Vec::<u8>::new())
|
||||||
.as_ssz_bytes()
|
.as_ssz_bytes()
|
||||||
@@ -597,8 +611,8 @@ impl ProtocolId {
|
|||||||
Protocol::BlocksByRoot => rpc_block_limits_by_fork(fork_context.current_fork()),
|
Protocol::BlocksByRoot => rpc_block_limits_by_fork(fork_context.current_fork()),
|
||||||
Protocol::BlobsByRange => rpc_blob_limits::<E>(),
|
Protocol::BlobsByRange => rpc_blob_limits::<E>(),
|
||||||
Protocol::BlobsByRoot => rpc_blob_limits::<E>(),
|
Protocol::BlobsByRoot => rpc_blob_limits::<E>(),
|
||||||
Protocol::DataColumnsByRoot => rpc_data_column_limits::<E>(),
|
Protocol::DataColumnsByRoot => rpc_data_column_limits(),
|
||||||
Protocol::DataColumnsByRange => rpc_data_column_limits::<E>(),
|
Protocol::DataColumnsByRange => rpc_data_column_limits(),
|
||||||
Protocol::Ping => RpcLimits::new(
|
Protocol::Ping => RpcLimits::new(
|
||||||
<Ping as Encode>::ssz_fixed_len(),
|
<Ping as Encode>::ssz_fixed_len(),
|
||||||
<Ping as Encode>::ssz_fixed_len(),
|
<Ping as Encode>::ssz_fixed_len(),
|
||||||
@@ -668,17 +682,18 @@ impl ProtocolId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn rpc_blob_limits<E: EthSpec>() -> RpcLimits {
|
pub fn rpc_blob_limits<E: EthSpec>() -> RpcLimits {
|
||||||
RpcLimits::new(
|
match E::spec_name() {
|
||||||
BlobSidecar::<E>::empty().as_ssz_bytes().len(),
|
EthSpecId::Minimal => {
|
||||||
BlobSidecar::<E>::max_size(),
|
RpcLimits::new(*BLOB_SIDECAR_SIZE_MINIMAL, *BLOB_SIDECAR_SIZE_MINIMAL)
|
||||||
)
|
}
|
||||||
|
EthSpecId::Mainnet | EthSpecId::Gnosis => {
|
||||||
|
RpcLimits::new(*BLOB_SIDECAR_SIZE, *BLOB_SIDECAR_SIZE)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rpc_data_column_limits<E: EthSpec>() -> RpcLimits {
|
pub fn rpc_data_column_limits() -> RpcLimits {
|
||||||
RpcLimits::new(
|
RpcLimits::new(*DATA_COLUMNS_SIDECAR_MIN, *DATA_COLUMNS_SIDECAR_MAX)
|
||||||
DataColumnSidecar::<E>::empty().as_ssz_bytes().len(),
|
|
||||||
DataColumnSidecar::<E>::max_size(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Inbound upgrade */
|
/* Inbound upgrade */
|
||||||
|
|||||||
Reference in New Issue
Block a user