mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Implement data columns by network boilerplate (#6224)
* Implement data columns by network boilerplate * Use correct quota values * Address PR review * Update currently_supported * Merge remote-tracking branch 'sigp/unstable' into peerdas-network-boilerplate * PR reviews * Fix data column rpc request not being sent due to incorrect limits set. (#6000)
This commit is contained in:
@@ -16,10 +16,11 @@ use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use tokio_util::codec::{Decoder, Encoder};
|
||||
use types::{
|
||||
BlobSidecar, ChainSpec, EthSpec, ForkContext, ForkName, Hash256, LightClientBootstrap,
|
||||
LightClientFinalityUpdate, LightClientOptimisticUpdate, RuntimeVariableList, SignedBeaconBlock,
|
||||
SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockBellatrix,
|
||||
SignedBeaconBlockCapella, SignedBeaconBlockDeneb, SignedBeaconBlockElectra,
|
||||
BlobSidecar, ChainSpec, DataColumnSidecar, EthSpec, ForkContext, ForkName, Hash256,
|
||||
LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate,
|
||||
RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase,
|
||||
SignedBeaconBlockBellatrix, SignedBeaconBlockCapella, SignedBeaconBlockDeneb,
|
||||
SignedBeaconBlockElectra,
|
||||
};
|
||||
use unsigned_varint::codec::Uvi;
|
||||
|
||||
@@ -70,6 +71,8 @@ impl<E: EthSpec> Encoder<RPCCodedResponse<E>> for SSZSnappyInboundCodec<E> {
|
||||
RPCResponse::BlocksByRoot(res) => res.as_ssz_bytes(),
|
||||
RPCResponse::BlobsByRange(res) => res.as_ssz_bytes(),
|
||||
RPCResponse::BlobsByRoot(res) => res.as_ssz_bytes(),
|
||||
RPCResponse::DataColumnsByRoot(res) => res.as_ssz_bytes(),
|
||||
RPCResponse::DataColumnsByRange(res) => res.as_ssz_bytes(),
|
||||
RPCResponse::LightClientBootstrap(res) => res.as_ssz_bytes(),
|
||||
RPCResponse::LightClientOptimisticUpdate(res) => res.as_ssz_bytes(),
|
||||
RPCResponse::LightClientFinalityUpdate(res) => res.as_ssz_bytes(),
|
||||
@@ -224,6 +227,8 @@ impl<E: EthSpec> Encoder<OutboundRequest<E>> for SSZSnappyOutboundCodec<E> {
|
||||
},
|
||||
OutboundRequest::BlobsByRange(req) => req.as_ssz_bytes(),
|
||||
OutboundRequest::BlobsByRoot(req) => req.blob_ids.as_ssz_bytes(),
|
||||
OutboundRequest::DataColumnsByRange(req) => req.as_ssz_bytes(),
|
||||
OutboundRequest::DataColumnsByRoot(req) => req.data_column_ids.as_ssz_bytes(),
|
||||
OutboundRequest::Ping(req) => req.as_ssz_bytes(),
|
||||
OutboundRequest::MetaData(_) => return Ok(()), // no metadata to encode
|
||||
};
|
||||
@@ -414,7 +419,12 @@ fn context_bytes<E: EthSpec>(
|
||||
}
|
||||
};
|
||||
}
|
||||
RPCResponse::BlobsByRange(_) | RPCResponse::BlobsByRoot(_) => {
|
||||
RPCResponse::BlobsByRange(_)
|
||||
| RPCResponse::BlobsByRoot(_)
|
||||
| RPCResponse::DataColumnsByRoot(_)
|
||||
| RPCResponse::DataColumnsByRange(_) => {
|
||||
// TODO(das): If DataColumnSidecar is defined as an Electra type, update the
|
||||
// context bytes to point to ForkName::Electra
|
||||
return fork_context.to_context_bytes(ForkName::Deneb);
|
||||
}
|
||||
RPCResponse::LightClientBootstrap(lc_bootstrap) => {
|
||||
@@ -512,6 +522,17 @@ fn handle_rpc_request<E: EthSpec>(
|
||||
)?,
|
||||
})))
|
||||
}
|
||||
SupportedProtocol::DataColumnsByRootV1 => Ok(Some(InboundRequest::DataColumnsByRoot(
|
||||
DataColumnsByRootRequest {
|
||||
data_column_ids: RuntimeVariableList::from_ssz_bytes(
|
||||
decoded_buffer,
|
||||
spec.max_request_data_column_sidecars as usize,
|
||||
)?,
|
||||
},
|
||||
))),
|
||||
SupportedProtocol::DataColumnsByRangeV1 => Ok(Some(InboundRequest::DataColumnsByRange(
|
||||
DataColumnsByRangeRequest::from_ssz_bytes(decoded_buffer)?,
|
||||
))),
|
||||
SupportedProtocol::PingV1 => Ok(Some(InboundRequest::Ping(Ping {
|
||||
data: u64::from_ssz_bytes(decoded_buffer)?,
|
||||
}))),
|
||||
@@ -604,6 +625,51 @@ fn handle_rpc_response<E: EthSpec>(
|
||||
),
|
||||
)),
|
||||
},
|
||||
SupportedProtocol::DataColumnsByRootV1 => match fork_name {
|
||||
Some(fork_name) => {
|
||||
// TODO(das): PeerDAS is currently supported for both deneb and electra. This check
|
||||
// does not advertise the topic on deneb, simply allows it to decode it. Advertise
|
||||
// logic is in `SupportedTopic::currently_supported`.
|
||||
if fork_name.deneb_enabled() {
|
||||
Ok(Some(RPCResponse::DataColumnsByRoot(Arc::new(
|
||||
DataColumnSidecar::from_ssz_bytes(decoded_buffer)?,
|
||||
))))
|
||||
} else {
|
||||
Err(RPCError::ErrorResponse(
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
"Invalid fork name for data columns by root".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
format!(
|
||||
"No context bytes provided for {:?} response",
|
||||
versioned_protocol
|
||||
),
|
||||
)),
|
||||
},
|
||||
SupportedProtocol::DataColumnsByRangeV1 => match fork_name {
|
||||
Some(fork_name) => {
|
||||
if fork_name.deneb_enabled() {
|
||||
Ok(Some(RPCResponse::DataColumnsByRange(Arc::new(
|
||||
DataColumnSidecar::from_ssz_bytes(decoded_buffer)?,
|
||||
))))
|
||||
} else {
|
||||
Err(RPCError::ErrorResponse(
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
"Invalid fork name for data columns by range".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RPCResponseErrorCode::InvalidRequest,
|
||||
format!(
|
||||
"No context bytes provided for {:?} response",
|
||||
versioned_protocol
|
||||
),
|
||||
)),
|
||||
},
|
||||
SupportedProtocol::PingV1 => Ok(Some(RPCResponse::Pong(Ping {
|
||||
data: u64::from_ssz_bytes(decoded_buffer)?,
|
||||
}))),
|
||||
@@ -747,7 +813,8 @@ mod tests {
|
||||
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield};
|
||||
use types::{
|
||||
blob_sidecar::BlobIdentifier, BeaconBlock, BeaconBlockAltair, BeaconBlockBase,
|
||||
BeaconBlockBellatrix, EmptyBlock, Epoch, FullPayload, Signature, Slot,
|
||||
BeaconBlockBellatrix, DataColumnIdentifier, EmptyBlock, Epoch, FullPayload, Signature,
|
||||
Slot,
|
||||
};
|
||||
|
||||
type Spec = types::MainnetEthSpec;
|
||||
@@ -794,6 +861,10 @@ mod tests {
|
||||
Arc::new(BlobSidecar::empty())
|
||||
}
|
||||
|
||||
fn empty_data_column_sidecar() -> Arc<DataColumnSidecar<Spec>> {
|
||||
Arc::new(DataColumnSidecar::empty())
|
||||
}
|
||||
|
||||
/// Bellatrix block with length < max_rpc_size.
|
||||
fn bellatrix_block_small(
|
||||
fork_context: &ForkContext,
|
||||
@@ -855,6 +926,27 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn dcbrange_request() -> DataColumnsByRangeRequest {
|
||||
DataColumnsByRangeRequest {
|
||||
start_slot: 0,
|
||||
count: 10,
|
||||
columns: vec![1, 2, 3],
|
||||
}
|
||||
}
|
||||
|
||||
fn dcbroot_request(spec: &ChainSpec) -> DataColumnsByRootRequest {
|
||||
DataColumnsByRootRequest {
|
||||
data_column_ids: RuntimeVariableList::new(
|
||||
vec![DataColumnIdentifier {
|
||||
block_root: Hash256::zero(),
|
||||
index: 0,
|
||||
}],
|
||||
spec.max_request_data_column_sidecars as usize,
|
||||
)
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn bbroot_request_v1(spec: &ChainSpec) -> BlocksByRootRequest {
|
||||
BlocksByRootRequest::new_v1(vec![Hash256::zero()], spec)
|
||||
}
|
||||
@@ -1012,6 +1104,12 @@ mod tests {
|
||||
OutboundRequest::BlobsByRoot(bbroot) => {
|
||||
assert_eq!(decoded, InboundRequest::BlobsByRoot(bbroot))
|
||||
}
|
||||
OutboundRequest::DataColumnsByRoot(dcbroot) => {
|
||||
assert_eq!(decoded, InboundRequest::DataColumnsByRoot(dcbroot))
|
||||
}
|
||||
OutboundRequest::DataColumnsByRange(dcbrange) => {
|
||||
assert_eq!(decoded, InboundRequest::DataColumnsByRange(dcbrange))
|
||||
}
|
||||
OutboundRequest::Ping(ping) => {
|
||||
assert_eq!(decoded, InboundRequest::Ping(ping))
|
||||
}
|
||||
@@ -1138,6 +1236,34 @@ mod tests {
|
||||
),
|
||||
Ok(Some(RPCResponse::BlobsByRoot(empty_blob_sidecar()))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::DataColumnsByRangeV1,
|
||||
RPCCodedResponse::Success(RPCResponse::DataColumnsByRange(
|
||||
empty_data_column_sidecar()
|
||||
)),
|
||||
ForkName::Deneb,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RPCResponse::DataColumnsByRange(
|
||||
empty_data_column_sidecar()
|
||||
))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::DataColumnsByRootV1,
|
||||
RPCCodedResponse::Success(RPCResponse::DataColumnsByRoot(
|
||||
empty_data_column_sidecar()
|
||||
)),
|
||||
ForkName::Deneb,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RPCResponse::DataColumnsByRoot(
|
||||
empty_data_column_sidecar()
|
||||
))),
|
||||
);
|
||||
}
|
||||
|
||||
// Test RPCResponse encoding/decoding for V1 messages
|
||||
@@ -1491,6 +1617,8 @@ mod tests {
|
||||
OutboundRequest::MetaData(MetadataRequest::new_v1()),
|
||||
OutboundRequest::BlobsByRange(blbrange_request()),
|
||||
OutboundRequest::BlobsByRoot(blbroot_request(&chain_spec)),
|
||||
OutboundRequest::DataColumnsByRange(dcbrange_request()),
|
||||
OutboundRequest::DataColumnsByRoot(dcbroot_request(&chain_spec)),
|
||||
OutboundRequest::MetaData(MetadataRequest::new_v2()),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user