Skip to content

Commit

Permalink
PeerDAS parameter changes for devnet-0 (#5779)
Browse files Browse the repository at this point in the history
* Update PeerDAS parameters to latest values.

* Lint fix

* Fix lint.
  • Loading branch information
jimmygchen authored May 15, 2024
1 parent 07df74c commit aa80950
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 42 deletions.
17 changes: 7 additions & 10 deletions beacon_node/lighthouse_network/src/discovery/enr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait Eth2Enr {
) -> Result<EnrSyncCommitteeBitfield<E>, &'static str>;

/// The peerdas custody subnet count associated with the ENR.
fn custody_subnet_count<E: EthSpec>(&self) -> Result<u64, &'static str>;
fn custody_subnet_count<E: EthSpec>(&self) -> u64;

fn eth2(&self) -> Result<EnrForkId, &'static str>;
}
Expand All @@ -64,15 +64,12 @@ impl Eth2Enr for Enr {
.map_err(|_| "Could not decode the ENR syncnets bitfield")
}

fn custody_subnet_count<E: EthSpec>(&self) -> Result<u64, &'static str> {
// NOTE: if the custody value is non-existent in the ENR, then we assume the minimum
// custody value defined in the spec.
let min_custody_bytes = E::min_custody_requirement().as_ssz_bytes();
let custody_bytes = self
.get(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
.unwrap_or(&min_custody_bytes);
u64::from_ssz_bytes(custody_bytes)
.map_err(|_| "Could not decode the ENR custody subnet count")
/// if the custody value is non-existent in the ENR, then we assume the minimum custody value
/// defined in the spec.
fn custody_subnet_count<E: EthSpec>(&self) -> u64 {
self.get(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
.and_then(|custody_bytes| u64::from_ssz_bytes(custody_bytes).ok())
.unwrap_or(E::min_custody_requirement() as u64)
}

fn eth2(&self) -> Result<EnrForkId, &'static str> {
Expand Down
12 changes: 4 additions & 8 deletions beacon_node/lighthouse_network/src/discovery/subnet_predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ where
let sync_committee_bitfield: Result<EnrSyncCommitteeBitfield<E>, _> =
enr.sync_committee_bitfield::<E>();

// Pre-fork/fork-boundary enrs may not contain a peerdas custody field.
// Don't return early here.
//
// NOTE: we could map to minimum custody requirement here.
let custody_subnet_count: Result<u64, _> = enr.custody_subnet_count::<E>();
let custody_subnet_count = enr.custody_subnet_count::<E>();

let predicate = subnets.iter().any(|subnet| match subnet {
Subnet::Attestation(s) => attestation_bitfield
Expand All @@ -38,13 +34,13 @@ where
Subnet::SyncCommittee(s) => sync_committee_bitfield
.as_ref()
.map_or(false, |b| b.get(*s.deref() as usize).unwrap_or(false)),
Subnet::DataColumn(s) => custody_subnet_count.map_or(false, |count| {
Subnet::DataColumn(s) => {
let mut subnets = DataColumnSubnetId::compute_custody_subnets::<E>(
enr.node_id().raw().into(),
count,
custody_subnet_count,
);
subnets.contains(s)
}),
}
});

if !predicate {
Expand Down
9 changes: 6 additions & 3 deletions beacon_node/lighthouse_network/src/rpc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ 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);
// 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);
// 320 blocks worth of columns for regular node, or 40 blocks for supernode.
// Range sync load balances when requesting blocks, and each batch is 32 blocks.
pub const DEFAULT_DATA_COLUMNS_BY_RANGE_QUOTA: Quota = Quota::n_every(5120, 10);
// 512 columns per request from spec. This should be plenty as peers are unlikely to send all
// sampling requests to a single peer.
pub const DEFAULT_DATA_COLUMNS_BY_ROOT_QUOTA: Quota = Quota::n_every(512, 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 Down
5 changes: 2 additions & 3 deletions beacon_node/lighthouse_network/src/types/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ impl<E: EthSpec> NetworkGlobals<E> {
pub fn custody_columns(&self, _epoch: Epoch) -> Result<Vec<ColumnIndex>, &'static str> {
let enr = self.local_enr();
let node_id = enr.node_id().raw().into();
// TODO(das): cache this number at start-up to not make this fallible
let custody_subnet_count = enr.custody_subnet_count::<E>()?;
let custody_subnet_count = enr.custody_subnet_count::<E>();
Ok(
DataColumnSubnetId::compute_custody_columns::<E>(node_id, custody_subnet_count)
.collect(),
Expand Down Expand Up @@ -152,7 +151,7 @@ mod test {
fn test_custody_count_default() {
let log = logging::test_logger();
let default_custody_requirement_column_count =
E::number_of_columns() / E::data_column_subnet_count();
E::number_of_columns() / E::data_column_subnet_count() * E::min_custody_requirement();
let globals = NetworkGlobals::<E>::new_test_globals(vec![], &log);
let any_epoch = Epoch::new(0);
let columns = globals.custody_columns(any_epoch).unwrap();
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
self.network_globals.local_enr().node_id().raw().into(),
self.network_globals
.local_enr()
.custody_subnet_count::<<T as BeaconChainTypes>::EthSpec>()
.unwrap_or(self.beacon_chain.spec.custody_requirement),
.custody_subnet_count::<<T as BeaconChainTypes>::EthSpec>(),
) {
for fork_digest in self.required_gossip_fork_digests() {
let gossip_kind = Subnet::DataColumn(column_subnet).into();
Expand Down
5 changes: 1 addition & 4 deletions beacon_node/network/src/sync/network_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {

for (peer_id, peer_info) in self.network_globals().peers.read().connected_peers() {
if let Some(enr) = peer_info.enr() {
// TODO(das): ignores decode errors
let custody_subnet_count = enr
.custody_subnet_count::<T::EthSpec>()
.unwrap_or(T::EthSpec::min_custody_requirement() as u64);
let custody_subnet_count = enr.custody_subnet_count::<T::EthSpec>();
// TODO(das): consider caching a map of subnet -> Vec<PeerId> and invalidating
// whenever a peer connected or disconnect event in received
let mut subnets = DataColumnSubnetId::compute_custody_subnets::<T::EthSpec>(
Expand Down
5 changes: 1 addition & 4 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ pub struct ChainSpec {
* DAS params
*/
pub eip7594_fork_epoch: Option<Epoch>,
pub custody_requirement: u64,

/*
* Networking
Expand Down Expand Up @@ -772,7 +771,6 @@ impl ChainSpec {
* DAS params
*/
eip7594_fork_epoch: None,
custody_requirement: 1,

/*
* Network specific
Expand Down Expand Up @@ -1085,7 +1083,6 @@ impl ChainSpec {
* DAS params
*/
eip7594_fork_epoch: None,
custody_requirement: 1,
/*
* Network specific
*/
Expand Down Expand Up @@ -1436,7 +1433,7 @@ const fn default_max_request_blob_sidecars() -> u64 {
}

const fn default_max_request_data_column_sidecars() -> u64 {
16384
512
}

const fn default_min_epochs_for_blob_sidecars_requests() -> u64 {
Expand Down
9 changes: 4 additions & 5 deletions consensus/types/src/data_column_subnet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl From<ArithError> for Error {
mod test {
use crate::data_column_subnet_id::DataColumnSubnetId;
use crate::EthSpec;
use crate::{ChainSpec, MainnetEthSpec};
use crate::MainnetEthSpec;

type E = MainnetEthSpec;

Expand All @@ -182,15 +182,14 @@ mod test {
.map(|v| ethereum_types::U256::from_dec_str(v).unwrap())
.collect::<Vec<_>>();

let spec = ChainSpec::mainnet();

let custody_requirement = 4;
for node_id in node_ids {
let computed_subnets =
DataColumnSubnetId::compute_custody_subnets::<E>(node_id, spec.custody_requirement);
DataColumnSubnetId::compute_custody_subnets::<E>(node_id, custody_requirement);
let computed_subnets: Vec<_> = computed_subnets.collect();

// the number of subnets is equal to the custody requirement
assert_eq!(computed_subnets.len() as u64, spec.custody_requirement);
assert_eq!(computed_subnets.len() as u64, custody_requirement);

let subnet_count = E::data_column_subnet_count();
for subnet in computed_subnets {
Expand Down
6 changes: 3 additions & 3 deletions consensus/types/src/eth_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl EthSpec for MainnetEthSpec {
type BytesPerBlob = U131072;
type BytesPerCell = U2048;
type KzgCommitmentInclusionProofDepth = U17;
type MinCustodyRequirement = U1;
type MinCustodyRequirement = U4;
type DataColumnSubnetCount = U32;
type DataColumnCount = U128;
type DataColumnsPerSubnet = U4;
Expand Down Expand Up @@ -471,7 +471,7 @@ impl EthSpec for MinimalEthSpec {
type MaxDepositReceiptsPerPayload = U4;
type MaxWithdrawalRequestsPerPayload = U2;
// DAS spec values copied from `MainnetEthSpec`
type MinCustodyRequirement = U1;
type MinCustodyRequirement = U4;
type DataColumnSubnetCount = U32;
type DataColumnCount = U128;
type DataColumnsPerSubnet = U4;
Expand Down Expand Up @@ -565,7 +565,7 @@ impl EthSpec for GnosisEthSpec {
type MaxAttestationsElectra = U8;
type MaxWithdrawalRequestsPerPayload = U16;
// DAS spec values copied from `MainnetEthSpec`
type MinCustodyRequirement = U1;
type MinCustodyRequirement = U4;
type DataColumnSubnetCount = U32;
type DataColumnCount = U128;
type DataColumnsPerSubnet = U4;
Expand Down

0 comments on commit aa80950

Please sign in to comment.