Subscribe blob topics (#4224)
This commit is contained in:
parent
b6c0e91c05
commit
7a36d004e4
@ -564,7 +564,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe to core topics for the new fork
|
// 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);
|
let topic = GossipTopic::new(kind, GossipEncoding::default(), new_fork_digest);
|
||||||
self.subscribe(topic);
|
self.subscribe(topic);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use libp2p::gossipsub::{IdentTopic as Topic, TopicHash};
|
use libp2p::gossipsub::{IdentTopic as Topic, TopicHash};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use strum::AsRefStr;
|
use strum::AsRefStr;
|
||||||
use types::{ForkName, SubnetId, SyncSubnetId};
|
use types::{EthSpec, ForkName, SubnetId, SyncSubnetId};
|
||||||
|
|
||||||
use crate::Subnet;
|
use crate::Subnet;
|
||||||
|
|
||||||
@ -40,23 +40,34 @@ pub const LIGHT_CLIENT_GOSSIP_TOPICS: [GossipKind; 2] = [
|
|||||||
GossipKind::LightClientOptimisticUpdate,
|
GossipKind::LightClientOptimisticUpdate,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub const DENEB_CORE_TOPICS: [GossipKind; 0] = [];
|
||||||
|
|
||||||
/// Returns the core topics associated with each fork that are new to the previous fork
|
/// 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 {
|
match fork_name {
|
||||||
ForkName::Base => BASE_CORE_TOPICS.to_vec(),
|
ForkName::Base => BASE_CORE_TOPICS.to_vec(),
|
||||||
ForkName::Altair => ALTAIR_CORE_TOPICS.to_vec(),
|
ForkName::Altair => ALTAIR_CORE_TOPICS.to_vec(),
|
||||||
ForkName::Merge => vec![],
|
ForkName::Merge => vec![],
|
||||||
ForkName::Capella => CAPELLA_CORE_TOPICS.to_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
|
/// 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.
|
/// including topics from older forks and new topics for the current fork.
|
||||||
pub fn core_topics_to_subscribe(mut current_fork: ForkName) -> Vec<GossipKind> {
|
pub fn core_topics_to_subscribe<T: EthSpec>(mut current_fork: ForkName) -> Vec<GossipKind> {
|
||||||
let mut topics = fork_core_topics(¤t_fork);
|
let mut topics = fork_core_topics::<T>(¤t_fork);
|
||||||
while let Some(previous_fork) = current_fork.previous_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);
|
topics.extend(previous_fork_topics);
|
||||||
current_fork = previous_fork;
|
current_fork = previous_fork;
|
||||||
}
|
}
|
||||||
@ -292,6 +303,8 @@ fn subnet_topic_index(topic: &str) -> Option<GossipKind> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use types::MainnetEthSpec;
|
||||||
|
|
||||||
use super::GossipKind::*;
|
use super::GossipKind::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -420,12 +433,15 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_core_topics_to_subscribe() {
|
fn test_core_topics_to_subscribe() {
|
||||||
|
type E = MainnetEthSpec;
|
||||||
let mut all_topics = Vec::new();
|
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(CAPELLA_CORE_TOPICS);
|
||||||
all_topics.extend(ALTAIR_CORE_TOPICS);
|
all_topics.extend(ALTAIR_CORE_TOPICS);
|
||||||
all_topics.extend(BASE_CORE_TOPICS);
|
all_topics.extend(BASE_CORE_TOPICS);
|
||||||
|
|
||||||
let latest_fork = *ForkName::list_all().last().unwrap();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -690,7 +690,9 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut subscribed_topics: Vec<GossipTopic> = vec![];
|
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() {
|
for fork_digest in self.required_gossip_fork_digests() {
|
||||||
let topic = GossipTopic::new(
|
let topic = GossipTopic::new(
|
||||||
topic_kind.clone(),
|
topic_kind.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user