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

fix(p2p): make kademlia in forest work for lotus #4580

Merged
merged 2 commits into from
Jul 23, 2024
Merged
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
26 changes: 15 additions & 11 deletions src/libp2p/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,22 @@ impl<'a> DiscoveryConfig<'a> {

let mut peers = HashSet::new();

// Kademlia config
let store = MemoryStore::new(local_peer_id);
let kad_config = {
let mut cfg = kad::Config::default();
cfg.set_protocol_names(vec![StreamProtocol::try_from_owned(format!(
"/fil/kad/{network_name}/kad/1.0.0"
))?]);
cfg
};

let kademlia_opt = if enable_kademlia {
let mut kademlia = kad::Behaviour::with_config(local_peer_id, store, kad_config);
// This is a workaround for <https://github.com/ChainSafe/forest/issues/4576>
// `go-libp2p-kad-dht` sends the remote peer id as query key during bootstrap,
// however, `rust-libp2p` returns empty peer list when the key it receives
// matches the local one. It's fine to use a random peer id as a workaround
// since Kademlia not used as value providers in filecoin p2p network.
let kad_random_peer_id = PeerId::random();
let store = MemoryStore::new(kad_random_peer_id);
let kad_config = {
let mut cfg = kad::Config::default();
cfg.set_protocol_names(vec![StreamProtocol::try_from_owned(format!(
"/fil/kad/{network_name}/kad/1.0.0"
))?]);
cfg
};
let mut kademlia = kad::Behaviour::with_config(kad_random_peer_id, store, kad_config);
// `set_mode(Server)` fixes https://github.com/ChainSafe/forest/issues/3620
// but it should not be required as the behaviour should automatically switch to server mode
// according to the doc. It might be a bug in `libp2p`.
Expand Down
Loading