Subscribe blob topics (#4224)

This commit is contained in:
Pawan Dhananjay 2023-04-22 06:21:09 -07:00 committed by GitHub
parent b6c0e91c05
commit 7a36d004e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 9 deletions

View File

@ -564,7 +564,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
}
// Subscribe to core topics for the new fork
for kind in fork_core_topics(&new_fork) {
for kind in fork_core_topics::<TSpec>(&new_fork) {
let topic = GossipTopic::new(kind, GossipEncoding::default(), new_fork_digest);
self.subscribe(topic);
}

View File

@ -1,7 +1,7 @@
use libp2p::gossipsub::{IdentTopic as Topic, TopicHash};
use serde_derive::{Deserialize, Serialize};
use strum::AsRefStr;
use types::{ForkName, SubnetId, SyncSubnetId};
use types::{EthSpec, ForkName, SubnetId, SyncSubnetId};
use crate::Subnet;
@ -40,23 +40,34 @@ pub const LIGHT_CLIENT_GOSSIP_TOPICS: [GossipKind; 2] = [
GossipKind::LightClientOptimisticUpdate,
];
pub const DENEB_CORE_TOPICS: [GossipKind; 0] = [];
/// Returns the core topics associated with each fork that are new to the previous fork
pub fn fork_core_topics(fork_name: &ForkName) -> Vec<GossipKind> {
pub fn fork_core_topics<T: EthSpec>(fork_name: &ForkName) -> Vec<GossipKind> {
match fork_name {
ForkName::Base => BASE_CORE_TOPICS.to_vec(),
ForkName::Altair => ALTAIR_CORE_TOPICS.to_vec(),
ForkName::Merge => vec![],
ForkName::Capella => CAPELLA_CORE_TOPICS.to_vec(),
ForkName::Deneb => vec![], // TODO
ForkName::Deneb => {
// All of deneb blob topics are core topics
let mut deneb_blob_topics = Vec::new();
for i in 0..T::max_blobs_per_block() {
deneb_blob_topics.push(GossipKind::BlobSidecar(i as u64));
}
let mut deneb_topics = DENEB_CORE_TOPICS.to_vec();
deneb_topics.append(&mut deneb_blob_topics);
deneb_topics
}
}
}
/// Returns all the topics that we need to subscribe to for a given fork
/// including topics from older forks and new topics for the current fork.
pub fn core_topics_to_subscribe(mut current_fork: ForkName) -> Vec<GossipKind> {
let mut topics = fork_core_topics(&current_fork);
pub fn core_topics_to_subscribe<T: EthSpec>(mut current_fork: ForkName) -> Vec<GossipKind> {
let mut topics = fork_core_topics::<T>(&current_fork);
while let Some(previous_fork) = current_fork.previous_fork() {
let previous_fork_topics = fork_core_topics(&previous_fork);
let previous_fork_topics = fork_core_topics::<T>(&previous_fork);
topics.extend(previous_fork_topics);
current_fork = previous_fork;
}
@ -292,6 +303,8 @@ fn subnet_topic_index(topic: &str) -> Option<GossipKind> {
#[cfg(test)]
mod tests {
use types::MainnetEthSpec;
use super::GossipKind::*;
use super::*;
@ -420,12 +433,15 @@ mod tests {
#[test]
fn test_core_topics_to_subscribe() {
type E = MainnetEthSpec;
let mut all_topics = Vec::new();
let mut deneb_core_topics = fork_core_topics::<E>(&ForkName::Deneb);
all_topics.append(&mut deneb_core_topics);
all_topics.extend(CAPELLA_CORE_TOPICS);
all_topics.extend(ALTAIR_CORE_TOPICS);
all_topics.extend(BASE_CORE_TOPICS);
let latest_fork = *ForkName::list_all().last().unwrap();
assert_eq!(core_topics_to_subscribe(latest_fork), all_topics);
assert_eq!(core_topics_to_subscribe::<E>(latest_fork), all_topics);
}
}

View File

@ -690,7 +690,9 @@ impl<T: BeaconChainTypes> NetworkService<T> {
}
let mut subscribed_topics: Vec<GossipTopic> = vec![];
for topic_kind in core_topics_to_subscribe(self.fork_context.current_fork()) {
for topic_kind in
core_topics_to_subscribe::<T::EthSpec>(self.fork_context.current_fork())
{
for fork_digest in self.required_gossip_fork_digests() {
let topic = GossipTopic::new(
topic_kind.clone(),