Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch custody columns in range sync #5747

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions beacon_node/beacon_chain/src/block_verification_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ impl<E: EthSpec> RpcBlock<E> {
) -> Result<Self, AvailabilityCheckError> {
let block_root = block_root.unwrap_or_else(|| get_block_root(&block));

if let Ok(block_commitments) = block.message().body().blob_kzg_commitments() {
if block.num_expected_blobs() > 0 && custody_columns.is_empty() {
// The number of required custody columns is out of scope here.
if !block_commitments.is_empty() && custody_columns.is_empty() {
return Err(AvailabilityCheckError::MissingCustodyColumns);
}
return Err(AvailabilityCheckError::MissingCustodyColumns);
}
// Treat empty blob lists as if they are missing.
let inner = if custody_columns.is_empty() {
Expand Down
26 changes: 13 additions & 13 deletions beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +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::DataColumnsByRange(req) => req.data_column_ids.as_ssz_bytes(),
OutboundRequest::Ping(req) => req.as_ssz_bytes(),
OutboundRequest::MetaData(_) => return Ok(()), // no metadata to encode
};
Expand Down Expand Up @@ -521,6 +521,9 @@ fn handle_rpc_request<E: EthSpec>(
)?,
})))
}
SupportedProtocol::DataColumnsByRangeV1 => Ok(Some(InboundRequest::DataColumnsByRange(
DataColumnsByRangeRequest::from_ssz_bytes(decoded_buffer)?,
))),
SupportedProtocol::DataColumnsByRootV1 => Ok(Some(InboundRequest::DataColumnsByRoot(
DataColumnsByRootRequest {
data_column_ids: RuntimeVariableList::from_ssz_bytes(
Expand All @@ -529,9 +532,6 @@ fn handle_rpc_request<E: EthSpec>(
)?,
},
))),
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)?,
}))),
Expand Down Expand Up @@ -624,14 +624,14 @@ fn handle_rpc_response<E: EthSpec>(
),
)),
},
SupportedProtocol::DataColumnsByRootV1 => match fork_name {
SupportedProtocol::DataColumnsByRangeV1 => match fork_name {
// TODO(das): update fork name
Some(ForkName::Deneb) => Ok(Some(RPCResponse::DataColumnsByRoot(Arc::new(
Some(ForkName::Deneb) => Ok(Some(RPCResponse::DataColumnsByRange(Arc::new(
DataColumnSidecar::from_ssz_bytes(decoded_buffer)?,
)))),
Some(_) => Err(RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
"Invalid fork name for data columns by root".to_string(),
"Invalid fork name for data columns by range".to_string(),
)),
None => Err(RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
Expand All @@ -641,14 +641,14 @@ fn handle_rpc_response<E: EthSpec>(
),
)),
},
SupportedProtocol::DataColumnsByRangeV1 => match fork_name {
SupportedProtocol::DataColumnsByRootV1 => match fork_name {
// TODO(das): update fork name
Some(ForkName::Deneb) => Ok(Some(RPCResponse::DataColumnsByRange(Arc::new(
Some(ForkName::Deneb) => Ok(Some(RPCResponse::DataColumnsByRoot(Arc::new(
DataColumnSidecar::from_ssz_bytes(decoded_buffer)?,
)))),
Some(_) => Err(RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
"Invalid fork name for data columns by range".to_string(),
"Invalid fork name for data columns by root".to_string(),
)),
None => Err(RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
Expand Down Expand Up @@ -1066,12 +1066,12 @@ mod tests {
OutboundRequest::BlobsByRoot(bbroot) => {
assert_eq!(decoded, InboundRequest::BlobsByRoot(bbroot))
}
OutboundRequest::DataColumnsByRange(value) => {
assert_eq!(decoded, InboundRequest::DataColumnsByRange(value))
}
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))
}
Expand Down
23 changes: 14 additions & 9 deletions beacon_node/lighthouse_network/src/rpc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub struct RateLimiterConfig {
pub(super) blocks_by_root_quota: Quota,
pub(super) blobs_by_range_quota: Quota,
pub(super) blobs_by_root_quota: Quota,
pub(super) data_columns_by_root_quota: Quota,
pub(super) data_columns_by_range_quota: Quota,
pub(super) data_columns_by_root_quota: Quota,
pub(super) light_client_bootstrap_quota: Quota,
pub(super) light_client_optimistic_update_quota: Quota,
pub(super) light_client_finality_update_quota: Quota,
Expand All @@ -107,8 +107,9 @@ impl RateLimiterConfig {
pub const DEFAULT_BLOCKS_BY_ROOT_QUOTA: Quota = Quota::n_every(128, 10);
pub const DEFAULT_BLOBS_BY_RANGE_QUOTA: Quota = Quota::n_every(768, 10);
pub const DEFAULT_BLOBS_BY_ROOT_QUOTA: Quota = Quota::n_every(128, 10);
pub const DEFAULT_DATA_COLUMNS_BY_ROOT_QUOTA: Quota = Quota::n_every(128, 10);
// TODO(das): random value without thought
pub const DEFAULT_DATA_COLUMNS_BY_RANGE_QUOTA: Quota = Quota::n_every(128, 10);
pub const DEFAULT_DATA_COLUMNS_BY_ROOT_QUOTA: Quota = Quota::n_every(128, 10);
pub const DEFAULT_LIGHT_CLIENT_BOOTSTRAP_QUOTA: Quota = Quota::one_every(10);
pub const DEFAULT_LIGHT_CLIENT_OPTIMISTIC_UPDATE_QUOTA: Quota = Quota::one_every(10);
pub const DEFAULT_LIGHT_CLIENT_FINALITY_UPDATE_QUOTA: Quota = Quota::one_every(10);
Expand All @@ -125,8 +126,8 @@ impl Default for RateLimiterConfig {
blocks_by_root_quota: Self::DEFAULT_BLOCKS_BY_ROOT_QUOTA,
blobs_by_range_quota: Self::DEFAULT_BLOBS_BY_RANGE_QUOTA,
blobs_by_root_quota: Self::DEFAULT_BLOBS_BY_ROOT_QUOTA,
data_columns_by_root_quota: Self::DEFAULT_DATA_COLUMNS_BY_ROOT_QUOTA,
data_columns_by_range_quota: Self::DEFAULT_DATA_COLUMNS_BY_RANGE_QUOTA,
data_columns_by_root_quota: Self::DEFAULT_DATA_COLUMNS_BY_ROOT_QUOTA,
light_client_bootstrap_quota: Self::DEFAULT_LIGHT_CLIENT_BOOTSTRAP_QUOTA,
light_client_optimistic_update_quota:
Self::DEFAULT_LIGHT_CLIENT_OPTIMISTIC_UPDATE_QUOTA,
Expand Down Expand Up @@ -156,6 +157,10 @@ impl Debug for RateLimiterConfig {
.field("blocks_by_root", fmt_q!(&self.blocks_by_root_quota))
.field("blobs_by_range", fmt_q!(&self.blobs_by_range_quota))
.field("blobs_by_root", fmt_q!(&self.blobs_by_root_quota))
.field(
"data_columns_by_range",
fmt_q!(&self.data_columns_by_range_quota),
)
.field(
"data_columns_by_root",
fmt_q!(&self.data_columns_by_root_quota),
Expand All @@ -180,8 +185,8 @@ impl FromStr for RateLimiterConfig {
let mut blocks_by_root_quota = None;
let mut blobs_by_range_quota = None;
let mut blobs_by_root_quota = None;
let mut data_columns_by_root_quota = None;
let mut data_columns_by_range_quota = None;
let mut data_columns_by_root_quota = None;
let mut light_client_bootstrap_quota = None;
let mut light_client_optimistic_update_quota = None;
let mut light_client_finality_update_quota = None;
Expand All @@ -196,12 +201,12 @@ impl FromStr for RateLimiterConfig {
Protocol::BlocksByRoot => blocks_by_root_quota = blocks_by_root_quota.or(quota),
Protocol::BlobsByRange => blobs_by_range_quota = blobs_by_range_quota.or(quota),
Protocol::BlobsByRoot => blobs_by_root_quota = blobs_by_root_quota.or(quota),
Protocol::DataColumnsByRoot => {
data_columns_by_root_quota = data_columns_by_root_quota.or(quota)
}
Protocol::DataColumnsByRange => {
data_columns_by_range_quota = data_columns_by_range_quota.or(quota)
}
Protocol::DataColumnsByRoot => {
data_columns_by_root_quota = data_columns_by_root_quota.or(quota)
}
Protocol::Ping => ping_quota = ping_quota.or(quota),
Protocol::MetaData => meta_data_quota = meta_data_quota.or(quota),
Protocol::LightClientBootstrap => {
Expand Down Expand Up @@ -229,10 +234,10 @@ impl FromStr for RateLimiterConfig {
blobs_by_range_quota: blobs_by_range_quota
.unwrap_or(Self::DEFAULT_BLOBS_BY_RANGE_QUOTA),
blobs_by_root_quota: blobs_by_root_quota.unwrap_or(Self::DEFAULT_BLOBS_BY_ROOT_QUOTA),
data_columns_by_root_quota: data_columns_by_root_quota
.unwrap_or(Self::DEFAULT_DATA_COLUMNS_BY_ROOT_QUOTA),
data_columns_by_range_quota: data_columns_by_range_quota
.unwrap_or(Self::DEFAULT_DATA_COLUMNS_BY_RANGE_QUOTA),
data_columns_by_root_quota: data_columns_by_root_quota
.unwrap_or(Self::DEFAULT_DATA_COLUMNS_BY_ROOT_QUOTA),
light_client_bootstrap_quota: light_client_bootstrap_quota
.unwrap_or(Self::DEFAULT_LIGHT_CLIENT_BOOTSTRAP_QUOTA),
light_client_optimistic_update_quota: light_client_optimistic_update_quota
Expand Down
12 changes: 6 additions & 6 deletions beacon_node/lighthouse_network/src/rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,17 @@ impl BlobsByRangeRequest {
pub struct DataColumnsByRangeRequest {
/// The starting slot to request data columns.
pub start_slot: u64,

/// The number of slots from the start slot.
pub count: u64,

/// The list of beacon block roots and column indices being requested.
pub data_column_ids: Vec<DataColumnIdentifier>,
/// The list column indices being requested.
pub columns: Vec<ColumnIndex>,
}

impl DataColumnsByRangeRequest {
pub fn max_data_columns_requested<E: EthSpec>(&self) -> u64 {
self.count.saturating_mul(E::max_blobs_per_block() as u64)
pub fn max_requested<E: EthSpec>(&self) -> u64 {
self.count
.saturating_mul(E::max_blobs_per_block() as u64)
.saturating_mul(self.columns.len() as u64)
}
}

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/lighthouse_network/src/rpc/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub enum OutboundRequest<E: EthSpec> {
BlocksByRoot(BlocksByRootRequest),
BlobsByRange(BlobsByRangeRequest),
BlobsByRoot(BlobsByRootRequest),
DataColumnsByRoot(DataColumnsByRootRequest),
DataColumnsByRange(DataColumnsByRangeRequest),
DataColumnsByRoot(DataColumnsByRootRequest),
Ping(Ping),
MetaData(MetadataRequest<E>),
}
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<E: EthSpec> OutboundRequest<E> {
OutboundRequest::BlobsByRange(req) => req.max_blobs_requested::<E>(),
OutboundRequest::BlobsByRoot(req) => req.blob_ids.len() as u64,
OutboundRequest::DataColumnsByRoot(req) => req.data_column_ids.len() as u64,
OutboundRequest::DataColumnsByRange(req) => req.data_column_ids.len() as u64,
OutboundRequest::DataColumnsByRange(req) => req.max_requested::<E>(),
OutboundRequest::Ping(_) => 1,
OutboundRequest::MetaData(_) => 1,
}
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/lighthouse_network/src/rpc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ impl SupportedProtocol {
ProtocolId::new(SupportedProtocol::BlobsByRangeV1, Encoding::SSZSnappy),
// TODO(das): add to PeerDAS fork
ProtocolId::new(SupportedProtocol::DataColumnsByRootV1, Encoding::SSZSnappy),
ProtocolId::new(SupportedProtocol::DataColumnsByRangeV1, Encoding::SSZSnappy),
]);
}
supported
Expand Down Expand Up @@ -704,7 +705,7 @@ impl<E: EthSpec> InboundRequest<E> {
InboundRequest::BlobsByRange(req) => req.max_blobs_requested::<E>(),
InboundRequest::BlobsByRoot(req) => req.blob_ids.len() as u64,
InboundRequest::DataColumnsByRoot(req) => req.data_column_ids.len() as u64,
InboundRequest::DataColumnsByRange(req) => req.data_column_ids.len() as u64,
InboundRequest::DataColumnsByRange(req) => req.max_requested::<E>(),
InboundRequest::Ping(_) => 1,
InboundRequest::MetaData(_) => 1,
InboundRequest::LightClientBootstrap(_) => 1,
Expand Down
31 changes: 15 additions & 16 deletions beacon_node/lighthouse_network/src/rpc/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ pub struct RPCRateLimiter {
blbrange_rl: Limiter<PeerId>,
/// BlobsByRoot rate limiter.
blbroot_rl: Limiter<PeerId>,
/// DataColumnssByRange rate limiter.
dcbrange_rl: Limiter<PeerId>,
/// DataColumnssByRoot rate limiter.
dcbroot_rl: Limiter<PeerId>,
/// DataColumnsByRange rate limiter.
dcbrange_rl: Limiter<PeerId>,
/// LightClientBootstrap rate limiter.
lc_bootstrap_rl: Limiter<PeerId>,
/// LightClientOptimisticUpdate rate limiter.
Expand Down Expand Up @@ -137,10 +137,10 @@ pub struct RPCRateLimiterBuilder {
blbrange_quota: Option<Quota>,
/// Quota for the BlobsByRoot protocol.
blbroot_quota: Option<Quota>,
/// Quota for the DataColumnsByRoot protocol.
dcbroot_quota: Option<Quota>,
/// Quota for the DataColumnsByRange protocol.
dcbrange_quota: Option<Quota>,
/// Quota for the DataColumnsByRoot protocol.
dcbroot_quota: Option<Quota>,
/// Quota for the LightClientBootstrap protocol.
lcbootstrap_quota: Option<Quota>,
/// Quota for the LightClientOptimisticUpdate protocol.
Expand All @@ -162,8 +162,8 @@ impl RPCRateLimiterBuilder {
Protocol::BlocksByRoot => self.bbroots_quota = q,
Protocol::BlobsByRange => self.blbrange_quota = q,
Protocol::BlobsByRoot => self.blbroot_quota = q,
Protocol::DataColumnsByRoot => self.dcbroot_quota = q,
Protocol::DataColumnsByRange => self.dcbrange_quota = q,
Protocol::DataColumnsByRoot => self.dcbroot_quota = q,
Protocol::LightClientBootstrap => self.lcbootstrap_quota = q,
Protocol::LightClientOptimisticUpdate => self.lc_optimistic_update_quota = q,
Protocol::LightClientFinalityUpdate => self.lc_finality_update_quota = q,
Expand Down Expand Up @@ -196,18 +196,15 @@ impl RPCRateLimiterBuilder {
let blbrange_quota = self
.blbrange_quota
.ok_or("BlobsByRange quota not specified")?;

let blbroots_quota = self
.blbroot_quota
.ok_or("BlobsByRoot quota not specified")?;

let dcbroot_quota = self
.dcbroot_quota
.ok_or("DataColumnsByRoot quota not specified")?;

let dcbrange_quota = self
.dcbrange_quota
.ok_or("DataColumnsByRange quota not specified")?;
let dcbroot_quota = self
.dcbroot_quota
.ok_or("DataColumnsByRoot quota not specified")?;

// create the rate limiters
let ping_rl = Limiter::from_quota(ping_quota)?;
Expand All @@ -218,8 +215,8 @@ impl RPCRateLimiterBuilder {
let bbrange_rl = Limiter::from_quota(bbrange_quota)?;
let blbrange_rl = Limiter::from_quota(blbrange_quota)?;
let blbroot_rl = Limiter::from_quota(blbroots_quota)?;
let dcbroot_rl = Limiter::from_quota(dcbroot_quota)?;
let dcbrange_rl = Limiter::from_quota(dcbrange_quota)?;
let dcbroot_rl = Limiter::from_quota(dcbroot_quota)?;
let lc_bootstrap_rl = Limiter::from_quota(lc_bootstrap_quota)?;
let lc_optimistic_update_rl = Limiter::from_quota(lc_optimistic_update_quota)?;
let lc_finality_update_rl = Limiter::from_quota(lc_finality_update_quota)?;
Expand All @@ -238,8 +235,8 @@ impl RPCRateLimiterBuilder {
bbrange_rl,
blbrange_rl,
blbroot_rl,
dcbroot_rl,
dcbrange_rl,
dcbroot_rl,
lc_bootstrap_rl,
lc_optimistic_update_rl,
lc_finality_update_rl,
Expand Down Expand Up @@ -284,8 +281,8 @@ impl RPCRateLimiter {
blocks_by_root_quota,
blobs_by_range_quota,
blobs_by_root_quota,
data_columns_by_root_quota,
data_columns_by_range_quota,
data_columns_by_root_quota,
light_client_bootstrap_quota,
light_client_optimistic_update_quota,
light_client_finality_update_quota,
Expand All @@ -300,8 +297,8 @@ impl RPCRateLimiter {
.set_quota(Protocol::BlocksByRoot, blocks_by_root_quota)
.set_quota(Protocol::BlobsByRange, blobs_by_range_quota)
.set_quota(Protocol::BlobsByRoot, blobs_by_root_quota)
.set_quota(Protocol::DataColumnsByRoot, data_columns_by_root_quota)
.set_quota(Protocol::DataColumnsByRange, data_columns_by_range_quota)
.set_quota(Protocol::DataColumnsByRoot, data_columns_by_root_quota)
.set_quota(Protocol::LightClientBootstrap, light_client_bootstrap_quota)
.set_quota(
Protocol::LightClientOptimisticUpdate,
Expand Down Expand Up @@ -338,8 +335,8 @@ impl RPCRateLimiter {
Protocol::BlocksByRoot => &mut self.bbroots_rl,
Protocol::BlobsByRange => &mut self.blbrange_rl,
Protocol::BlobsByRoot => &mut self.blbroot_rl,
Protocol::DataColumnsByRoot => &mut self.dcbroot_rl,
Protocol::DataColumnsByRange => &mut self.dcbrange_rl,
Protocol::DataColumnsByRoot => &mut self.dcbroot_rl,
Protocol::LightClientBootstrap => &mut self.lc_bootstrap_rl,
Protocol::LightClientOptimisticUpdate => &mut self.lc_optimistic_update_rl,
Protocol::LightClientFinalityUpdate => &mut self.lc_finality_update_rl,
Expand All @@ -357,6 +354,8 @@ impl RPCRateLimiter {
self.bbroots_rl.prune(time_since_start);
self.blbrange_rl.prune(time_since_start);
self.blbroot_rl.prune(time_since_start);
self.dcbrange_rl.prune(time_since_start);
self.dcbroot_rl.prune(time_since_start);
}
}

Expand Down
8 changes: 4 additions & 4 deletions beacon_node/lighthouse_network/src/service/api_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use types::{
LightClientOptimisticUpdate, SignedBeaconBlock,
};

use crate::rpc::methods::{BlobsByRangeRequest, BlobsByRootRequest, DataColumnsByRootRequest};
use crate::rpc::methods::{
BlobsByRangeRequest, BlobsByRootRequest, DataColumnsByRangeRequest, DataColumnsByRootRequest,
};
use crate::rpc::{
methods::{
BlocksByRangeRequest, BlocksByRootRequest, LightClientBootstrapRequest,
Expand All @@ -16,8 +18,6 @@ use crate::rpc::{
OutboundRequest, SubstreamId,
};

use super::methods::DataColumnsByRangeRequest;

/// Identifier of requests sent by a peer.
pub type PeerRequestId = (ConnectionId, SubstreamId);

Expand Down Expand Up @@ -84,8 +84,8 @@ impl<E: EthSpec> std::convert::From<Request> for OutboundRequest<E> {
}
Request::BlobsByRange(r) => OutboundRequest::BlobsByRange(r),
Request::BlobsByRoot(r) => OutboundRequest::BlobsByRoot(r),
Request::DataColumnsByRoot(r) => OutboundRequest::DataColumnsByRoot(r),
Request::DataColumnsByRange(r) => OutboundRequest::DataColumnsByRange(r),
Request::DataColumnsByRoot(r) => OutboundRequest::DataColumnsByRoot(r),
Request::Status(s) => OutboundRequest::Status(s),
}
}
Expand Down
Loading