Skip to content

Commit

Permalink
Update subscription filter. (#5797)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen authored May 16, 2024
1 parent 7c3c173 commit 4946e72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 44 deletions.
7 changes: 4 additions & 3 deletions beacon_node/lighthouse_network/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
let max_topics = ctx.chain_spec.attestation_subnet_count as usize
+ SYNC_COMMITTEE_SUBNET_COUNT as usize
+ ctx.chain_spec.blob_sidecar_subnet_count as usize
+ ctx.chain_spec.data_column_sidecar_subnet_count as usize
// TODO: move to chainspec
+ E::data_column_subnet_count()
+ BASE_CORE_TOPICS.len()
+ ALTAIR_CORE_TOPICS.len()
+ CAPELLA_CORE_TOPICS.len()
Expand All @@ -254,11 +255,11 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
ctx.chain_spec.attestation_subnet_count,
SYNC_COMMITTEE_SUBNET_COUNT,
ctx.chain_spec.blob_sidecar_subnet_count,
ctx.chain_spec.data_column_sidecar_subnet_count,
E::data_column_subnet_count() as u64,
),
// during a fork we subscribe to both the old and new topics
max_subscribed_topics: max_topics * 4,
// 162 in theory = (64 attestation + 4 sync committee + 7 core topics + 6 blob topics) * 2
// 209 in theory = (64 attestation + 4 sync committee + 7 core topics + 6 blob topics + 64 column topics) * 2
max_subscriptions_per_request: max_topics * 2,
};

Expand Down
13 changes: 0 additions & 13 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ pub struct ChainSpec {
pub max_request_data_column_sidecars: u64,
pub min_epochs_for_blob_sidecars_requests: u64,
pub blob_sidecar_subnet_count: u64,
pub data_column_sidecar_subnet_count: u64,

/*
* Networking Derived
Expand Down Expand Up @@ -804,7 +803,6 @@ impl ChainSpec {
max_request_data_column_sidecars: default_max_request_data_column_sidecars(),
min_epochs_for_blob_sidecars_requests: default_min_epochs_for_blob_sidecars_requests(),
blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(),
data_column_sidecar_subnet_count: default_data_column_sidecar_subnet_count(),

/*
* Derived Deneb Specific
Expand Down Expand Up @@ -1115,7 +1113,6 @@ impl ChainSpec {
max_request_data_column_sidecars: default_max_request_data_column_sidecars(),
min_epochs_for_blob_sidecars_requests: 16384,
blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(),
data_column_sidecar_subnet_count: default_data_column_sidecar_subnet_count(),

/*
* Derived Deneb Specific
Expand Down Expand Up @@ -1316,9 +1313,6 @@ pub struct Config {
#[serde(default = "default_blob_sidecar_subnet_count")]
#[serde(with = "serde_utils::quoted_u64")]
blob_sidecar_subnet_count: u64,
#[serde(default = "default_data_column_sidecar_subnet_count")]
#[serde(with = "serde_utils::quoted_u64")]
data_column_sidecar_subnet_count: u64,

#[serde(default = "default_min_per_epoch_churn_limit_electra")]
#[serde(with = "serde_utils::quoted_u64")]
Expand Down Expand Up @@ -1444,10 +1438,6 @@ const fn default_blob_sidecar_subnet_count() -> u64 {
6
}

const fn default_data_column_sidecar_subnet_count() -> u64 {
32
}

const fn default_min_per_epoch_churn_limit_electra() -> u64 {
128_000_000_000
}
Expand Down Expand Up @@ -1655,7 +1645,6 @@ impl Config {
max_request_data_column_sidecars: spec.max_request_data_column_sidecars,
min_epochs_for_blob_sidecars_requests: spec.min_epochs_for_blob_sidecars_requests,
blob_sidecar_subnet_count: spec.blob_sidecar_subnet_count,
data_column_sidecar_subnet_count: spec.data_column_sidecar_subnet_count,

min_per_epoch_churn_limit_electra: spec.min_per_epoch_churn_limit_electra,
max_per_epoch_activation_exit_churn_limit: spec
Expand Down Expand Up @@ -1729,7 +1718,6 @@ impl Config {
max_request_data_column_sidecars,
min_epochs_for_blob_sidecars_requests,
blob_sidecar_subnet_count,
data_column_sidecar_subnet_count,

min_per_epoch_churn_limit_electra,
max_per_epoch_activation_exit_churn_limit,
Expand Down Expand Up @@ -1795,7 +1783,6 @@ impl Config {
max_request_data_column_sidecars,
min_epochs_for_blob_sidecars_requests,
blob_sidecar_subnet_count,
data_column_sidecar_subnet_count,

min_per_epoch_churn_limit_electra,
max_per_epoch_activation_exit_churn_limit,
Expand Down
13 changes: 13 additions & 0 deletions consensus/types/src/data_column_subnet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,17 @@ mod test {
}
}
}

#[test]
fn test_columns_subnet_conversion() {
for subnet in 0..E::data_column_subnet_count() as u64 {
let subnet_id = DataColumnSubnetId::new(subnet);
for column_index in subnet_id.columns::<E>() {
assert_eq!(
subnet_id,
DataColumnSubnetId::from_column_index::<E>(column_index as usize)
);
}
}
}
}
32 changes: 4 additions & 28 deletions consensus/types/src/eth_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub trait EthSpec:
type KzgCommitmentsInclusionProofDepth: Unsigned + Clone + Sync + Send + Debug + PartialEq;
/*
* Config values in PeerDAS
* TODO(das) move to `ChainSpec`
*/
type CustodyRequirement: Unsigned + Clone + Sync + Send + Debug + PartialEq;
type DataColumnSidecarSubnetCount: Unsigned + Clone + Sync + Send + Debug + PartialEq;
Expand Down Expand Up @@ -152,11 +153,6 @@ pub trait EthSpec:
/// Must be set to `BytesPerFieldElement * FieldElementsPerCell`.
type BytesPerCell: Unsigned + Clone + Sync + Send + Debug + PartialEq;

/// Number of data columns per subnet.
///
/// Must be set to `NumberOfColumns / DataColumnSidecarSubnetCount`
type DataColumnsPerSubnet: Unsigned + Clone + Sync + Send + Debug + PartialEq;

/*
* New in Electra
*/
Expand Down Expand Up @@ -369,7 +365,9 @@ pub trait EthSpec:
}

fn data_columns_per_subnet() -> usize {
Self::DataColumnsPerSubnet::to_usize()
Self::number_of_columns()
.safe_div(Self::data_column_subnet_count())
.expect("Subnet count must be greater than 0")
}

fn custody_requirement() -> usize {
Expand Down Expand Up @@ -434,7 +432,6 @@ impl EthSpec for MainnetEthSpec {
type CustodyRequirement = U4;
type DataColumnSidecarSubnetCount = U64;
type NumberOfColumns = U128;
type DataColumnsPerSubnet = U2;
type KzgCommitmentsInclusionProofDepth = U4; // inclusion of the whole list of commitments
type SyncSubcommitteeSize = U128; // 512 committee size / 4 sync committee subnet count
type MaxPendingAttestations = U4096; // 128 max attestations * 32 slots per epoch
Expand Down Expand Up @@ -488,7 +485,6 @@ impl EthSpec for MinimalEthSpec {
type CustodyRequirement = U4;
type DataColumnSidecarSubnetCount = U64;
type NumberOfColumns = U128;
type DataColumnsPerSubnet = U2;
type KzgCommitmentsInclusionProofDepth = U4;

params_from_eth_spec!(MainnetEthSpec {
Expand Down Expand Up @@ -582,7 +578,6 @@ impl EthSpec for GnosisEthSpec {
type CustodyRequirement = U4;
type DataColumnSidecarSubnetCount = U64;
type NumberOfColumns = U128;
type DataColumnsPerSubnet = U2;
type KzgCommitmentsInclusionProofDepth = U4;

fn default_spec() -> ChainSpec {
Expand All @@ -593,22 +588,3 @@ impl EthSpec for GnosisEthSpec {
EthSpecId::Gnosis
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_peer_das_config_all_specs() {
test_peer_das_config::<MainnetEthSpec>();
test_peer_das_config::<GnosisEthSpec>();
test_peer_das_config::<MinimalEthSpec>();
}

fn test_peer_das_config<E: EthSpec>() {
assert_eq!(
E::data_columns_per_subnet(),
E::number_of_columns() / E::data_column_subnet_count()
);
}
}

0 comments on commit 4946e72

Please sign in to comment.