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

Optional subscribe FIND_CHUNKS topic #291

Merged
merged 2 commits into from
Dec 5, 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
4 changes: 4 additions & 0 deletions node/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ pub struct Config {
/// Whether to disable network identity in ENR.
/// This is for test purpose only.
pub disable_enr_network_id: bool,

/// Whether to allow find chunks from peers.
pub find_chunks_enabled: bool,
}

impl Default for Config {
Expand Down Expand Up @@ -214,6 +217,7 @@ impl Default for Config {
peer_db: Default::default(),
peer_manager: Default::default(),
disable_enr_network_id: false,
find_chunks_enabled: false,
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion node/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,18 @@ impl<AppReqId: ReqId> Service<AppReqId> {
// }
// }

for topic_kind in &crate::types::CORE_TOPICS {
let mut topics = vec![
GossipKind::NewFile,
GossipKind::FindFile,
GossipKind::AnnounceFile,
GossipKind::AnnounceShardConfig,
];
if config.find_chunks_enabled {
topics.push(GossipKind::FindChunks);
topics.push(GossipKind::AnnounceChunks);
}

for topic_kind in topics {
if swarm.behaviour_mut().subscribe_kind(topic_kind.clone()) {
subscribed_topics.push(topic_kind.clone());
} else {
Expand Down
2 changes: 1 addition & 1 deletion node/network/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub use pubsub::{
PubsubMessage, SignedAnnounceChunks, SignedAnnounceFile, SignedAnnounceShardConfig,
SignedMessage, SnappyTransform,
};
pub use topics::{GossipEncoding, GossipKind, GossipTopic, CORE_TOPICS};
pub use topics::{GossipEncoding, GossipKind, GossipTopic};
8 changes: 0 additions & 8 deletions node/network/src/types/topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ pub const ANNOUNCE_FILE_TOPIC: &str = "announce_file";
pub const ANNOUNCE_CHUNKS_TOPIC: &str = "announce_chunks";
pub const ANNOUNCE_SHARD_CONFIG_TOPIC: &str = "announce_shard_config";

pub const CORE_TOPICS: [GossipKind; 5] = [
GossipKind::NewFile,
GossipKind::FindFile,
GossipKind::FindChunks,
GossipKind::AnnounceFile,
GossipKind::AnnounceChunks,
];

/// A gossipsub topic which encapsulates the type of messages that should be sent and received over
/// the pubsub protocol and the way the messages should be encoded.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
Expand Down
1 change: 1 addition & 0 deletions node/src/config/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl ZgsConfig {
network_config.peer_db = self.network_peer_db;
network_config.peer_manager = self.network_peer_manager.clone();
network_config.disable_enr_network_id = self.discv5_disable_enr_network_id;
network_config.find_chunks_enabled = self.network_find_chunks_enabled;

Ok(network_config)
}
Expand Down
1 change: 1 addition & 0 deletions node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build_config! {
(network_libp2p_nodes, (Vec<String>), vec![])
(network_private, (bool), false)
(network_disable_discovery, (bool), false)
(network_find_chunks_enabled, (bool), false)

// discv5
(discv5_request_timeout_secs, (u64), 5)
Expand Down
6 changes: 6 additions & 0 deletions tests/sync_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class SyncTest(TestFramework):
def setup_params(self):
self.num_nodes = 2

# enable find chunks topic
for i in range(self.num_nodes):
self.zgs_node_configs[i] = {
"network_find_chunks_enabled": True
}

def run_test(self):
# By default, auto_sync_enabled and sync_file_on_announcement_enabled are both false,
# and file or chunks sync should be triggered by rpc.
Expand Down
Loading