mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 20:57:10 +00:00
peerdas-devnet-7: update DataColumnSidecarsByRoot request to use DataColumnsByRootIdentifier (#7399)
Update DataColumnSidecarsByRoot request to use DataColumnsByRootIdentifier #7377 As described in https://github.com/ethereum/consensus-specs/pull/4284
This commit is contained in:
@@ -16,11 +16,12 @@ use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use tokio_util::codec::{Decoder, Encoder};
|
||||
use types::{
|
||||
BlobSidecar, ChainSpec, DataColumnSidecar, EthSpec, ForkContext, ForkName, Hash256,
|
||||
LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate,
|
||||
LightClientUpdate, RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair,
|
||||
SignedBeaconBlockBase, SignedBeaconBlockBellatrix, SignedBeaconBlockCapella,
|
||||
SignedBeaconBlockDeneb, SignedBeaconBlockElectra, SignedBeaconBlockFulu,
|
||||
BlobSidecar, ChainSpec, DataColumnSidecar, DataColumnsByRootIdentifier, EthSpec, ForkContext,
|
||||
ForkName, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
|
||||
LightClientOptimisticUpdate, LightClientUpdate, RuntimeVariableList, SignedBeaconBlock,
|
||||
SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockBellatrix,
|
||||
SignedBeaconBlockCapella, SignedBeaconBlockDeneb, SignedBeaconBlockElectra,
|
||||
SignedBeaconBlockFulu,
|
||||
};
|
||||
use unsigned_varint::codec::Uvi;
|
||||
|
||||
@@ -596,10 +597,12 @@ fn handle_rpc_request<E: EthSpec>(
|
||||
))),
|
||||
SupportedProtocol::DataColumnsByRootV1 => Ok(Some(RequestType::DataColumnsByRoot(
|
||||
DataColumnsByRootRequest {
|
||||
data_column_ids: RuntimeVariableList::from_ssz_bytes(
|
||||
decoded_buffer,
|
||||
spec.max_request_data_column_sidecars as usize,
|
||||
)?,
|
||||
data_column_ids:
|
||||
<RuntimeVariableList<DataColumnsByRootIdentifier>>::from_ssz_bytes_with_nested(
|
||||
decoded_buffer,
|
||||
spec.max_request_blocks(current_fork),
|
||||
spec.number_of_columns as usize,
|
||||
)?,
|
||||
},
|
||||
))),
|
||||
SupportedProtocol::PingV1 => Ok(Some(RequestType::Ping(Ping {
|
||||
@@ -935,8 +938,8 @@ mod tests {
|
||||
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield};
|
||||
use types::{
|
||||
blob_sidecar::BlobIdentifier, data_column_sidecar::Cell, BeaconBlock, BeaconBlockAltair,
|
||||
BeaconBlockBase, BeaconBlockBellatrix, BeaconBlockHeader, DataColumnIdentifier, EmptyBlock,
|
||||
Epoch, FixedBytesExtended, FullPayload, KzgCommitment, KzgProof, Signature,
|
||||
BeaconBlockBase, BeaconBlockBellatrix, BeaconBlockHeader, DataColumnsByRootIdentifier,
|
||||
EmptyBlock, Epoch, FixedBytesExtended, FullPayload, KzgCommitment, KzgProof, Signature,
|
||||
SignedBeaconBlockHeader, Slot,
|
||||
};
|
||||
|
||||
@@ -1066,14 +1069,15 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn dcbroot_request(spec: &ChainSpec) -> DataColumnsByRootRequest {
|
||||
fn dcbroot_request(spec: &ChainSpec, fork_name: ForkName) -> DataColumnsByRootRequest {
|
||||
let number_of_columns = spec.number_of_columns as usize;
|
||||
DataColumnsByRootRequest {
|
||||
data_column_ids: RuntimeVariableList::new(
|
||||
vec![DataColumnIdentifier {
|
||||
vec![DataColumnsByRootIdentifier {
|
||||
block_root: Hash256::zero(),
|
||||
index: 0,
|
||||
columns: RuntimeVariableList::from_vec(vec![0, 1, 2], number_of_columns),
|
||||
}],
|
||||
spec.max_request_data_column_sidecars as usize,
|
||||
spec.max_request_blocks(fork_name),
|
||||
)
|
||||
.unwrap(),
|
||||
}
|
||||
@@ -1904,7 +1908,6 @@ mod tests {
|
||||
RequestType::MetaData(MetadataRequest::new_v1()),
|
||||
RequestType::BlobsByRange(blbrange_request()),
|
||||
RequestType::DataColumnsByRange(dcbrange_request()),
|
||||
RequestType::DataColumnsByRoot(dcbroot_request(&chain_spec)),
|
||||
RequestType::MetaData(MetadataRequest::new_v2()),
|
||||
];
|
||||
for req in requests.iter() {
|
||||
@@ -1920,6 +1923,7 @@ mod tests {
|
||||
RequestType::BlobsByRoot(blbroot_request(fork_name)),
|
||||
RequestType::BlocksByRoot(bbroot_request_v1(fork_name)),
|
||||
RequestType::BlocksByRoot(bbroot_request_v2(fork_name)),
|
||||
RequestType::DataColumnsByRoot(dcbroot_request(&chain_spec, fork_name)),
|
||||
]
|
||||
};
|
||||
for fork_name in ForkName::list_all() {
|
||||
|
||||
@@ -6,7 +6,6 @@ use serde::Serialize;
|
||||
use ssz::Encode;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::{typenum::U256, VariableList};
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::Display;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
@@ -16,9 +15,10 @@ use superstruct::superstruct;
|
||||
use types::blob_sidecar::BlobIdentifier;
|
||||
use types::light_client_update::MAX_REQUEST_LIGHT_CLIENT_UPDATES;
|
||||
use types::{
|
||||
blob_sidecar::BlobSidecar, ChainSpec, ColumnIndex, DataColumnIdentifier, DataColumnSidecar,
|
||||
Epoch, EthSpec, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
|
||||
LightClientOptimisticUpdate, LightClientUpdate, RuntimeVariableList, SignedBeaconBlock, Slot,
|
||||
blob_sidecar::BlobSidecar, ChainSpec, ColumnIndex, DataColumnSidecar,
|
||||
DataColumnsByRootIdentifier, Epoch, EthSpec, Hash256, LightClientBootstrap,
|
||||
LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, RuntimeVariableList,
|
||||
SignedBeaconBlock, Slot,
|
||||
};
|
||||
use types::{ForkContext, ForkName};
|
||||
|
||||
@@ -479,31 +479,20 @@ impl BlobsByRootRequest {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DataColumnsByRootRequest {
|
||||
/// The list of beacon block roots and column indices being requested.
|
||||
pub data_column_ids: RuntimeVariableList<DataColumnIdentifier>,
|
||||
pub data_column_ids: RuntimeVariableList<DataColumnsByRootIdentifier>,
|
||||
}
|
||||
|
||||
impl DataColumnsByRootRequest {
|
||||
pub fn new(data_column_ids: Vec<DataColumnIdentifier>, spec: &ChainSpec) -> Self {
|
||||
let data_column_ids = RuntimeVariableList::from_vec(
|
||||
data_column_ids,
|
||||
spec.max_request_data_column_sidecars as usize,
|
||||
);
|
||||
pub fn new(
|
||||
data_column_ids: Vec<DataColumnsByRootIdentifier>,
|
||||
max_request_blocks: usize,
|
||||
) -> Self {
|
||||
let data_column_ids = RuntimeVariableList::from_vec(data_column_ids, max_request_blocks);
|
||||
Self { data_column_ids }
|
||||
}
|
||||
|
||||
pub fn new_single(block_root: Hash256, index: ColumnIndex, spec: &ChainSpec) -> Self {
|
||||
Self::new(vec![DataColumnIdentifier { block_root, index }], spec)
|
||||
}
|
||||
|
||||
pub fn group_by_ordered_block_root(&self) -> Vec<(Hash256, Vec<ColumnIndex>)> {
|
||||
let mut column_indexes_by_block = BTreeMap::<Hash256, Vec<ColumnIndex>>::new();
|
||||
for request_id in self.data_column_ids.as_slice() {
|
||||
column_indexes_by_block
|
||||
.entry(request_id.block_root)
|
||||
.or_default()
|
||||
.push(request_id.index);
|
||||
}
|
||||
column_indexes_by_block.into_iter().collect()
|
||||
pub fn max_requested(&self) -> usize {
|
||||
self.data_column_ids.iter().map(|id| id.columns.len()).sum()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -740,7 +740,7 @@ impl<E: EthSpec> RequestType<E> {
|
||||
RequestType::BlocksByRoot(req) => req.block_roots().len() as u64,
|
||||
RequestType::BlobsByRange(req) => req.max_blobs_requested(current_fork, spec),
|
||||
RequestType::BlobsByRoot(req) => req.blob_ids.len() as u64,
|
||||
RequestType::DataColumnsByRoot(req) => req.data_column_ids.len() as u64,
|
||||
RequestType::DataColumnsByRoot(req) => req.max_requested() as u64,
|
||||
RequestType::DataColumnsByRange(req) => req.max_requested::<E>(),
|
||||
RequestType::Ping(_) => 1,
|
||||
RequestType::MetaData(_) => 1,
|
||||
|
||||
Reference in New Issue
Block a user