Skip to content

Commit

Permalink
Merge pull request #1532 from EspressoSystems/jr/republish_keys
Browse files Browse the repository at this point in the history
Republish dht keys
  • Loading branch information
DieracDelta authored Aug 14, 2023
2 parents 15208ac + 61d5dbf commit f193182
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
18 changes: 13 additions & 5 deletions libp2p-networking/src/network/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl NetworkNode {
// at some point in the future.
match config.node_type {
NetworkNodeType::Bootstrap => MeshParams {
mesh_n_high: 50,
mesh_n_high: 1000, // make this super high in case we end up scaling to 1k
// nodes
mesh_n_low: 10,
mesh_outbound_min: 5,
mesh_n: 15,
Expand Down Expand Up @@ -225,7 +226,7 @@ impl NetworkNode {
)
.map_err(|s| GossipsubBuildSnafu { message: s }.build())?;

// - Build a identify network behavior needed for own
// Build a identify network behavior needed for own
// node connection information
// E.g. this will answer the question: how are other nodes
// seeing the peer from behind a NAT
Expand All @@ -235,9 +236,16 @@ impl NetworkNode {

// - Build DHT needed for peer discovery
let mut kconfig = KademliaConfig::default();
// FIXME do we need this?
// <https://github.com/EspressoSystems/HotShot/issues/344>
kconfig.set_parallelism(NonZeroUsize::new(1).unwrap());
// 8 hours by default
let record_republication_interval = config
.republication_interval
.unwrap_or(Duration::from_secs(28800));
let ttl = Some(config.ttl.unwrap_or(16 * record_republication_interval));
kconfig
.set_parallelism(NonZeroUsize::new(1).unwrap())
.set_provider_publication_interval(Some(record_republication_interval))
.set_publication_interval(Some(record_republication_interval))
.set_record_ttl(ttl);

if let Some(factor) = config.replication_factor {
kconfig.set_replication_factor(factor);
Expand Down
8 changes: 7 additions & 1 deletion libp2p-networking/src/network/node/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::network::NetworkNodeType;
use libp2p::{identity::Keypair, Multiaddr};
use libp2p_identity::PeerId;
use std::{collections::HashSet, num::NonZeroUsize};
use std::{collections::HashSet, num::NonZeroUsize, time::Duration};

/// replication factor for kademlia
pub const DEFAULT_REPLICATION_FACTOR: Option<NonZeroUsize> = NonZeroUsize::new(20);
Expand Down Expand Up @@ -30,6 +30,12 @@ pub struct NetworkNodeConfig {

/// list of addresses to connect to at initialization
pub to_connect_addrs: HashSet<(Option<PeerId>, Multiaddr)>,
/// republication interval in DHT, must be much less than `ttl`
#[builder(default)]
pub republication_interval: Option<Duration>,
/// expiratiry for records in DHT
#[builder(default)]
pub ttl: Option<Duration>,
}

/// NOTE: `mesh_outbound_min <= mesh_n_low <= mesh_n <= mesh_n_high`
Expand Down
4 changes: 3 additions & 1 deletion libp2p-networking/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ pub async fn spin_up_swarms<S: Debug + Default>(
.replication_factor(replication_factor)
.node_type(NetworkNodeType::Bootstrap)
.to_connect_addrs(HashSet::default())
.bound_addr(Some(addr));
.bound_addr(Some(addr))
.ttl(None)
.republication_interval(None);
let node = NetworkNodeHandle::new(
config
.build()
Expand Down
6 changes: 6 additions & 0 deletions src/traits/networking/libp2p_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ where
.node_type(NetworkNodeType::Bootstrap)
.bound_addr(Some(addr))
.to_connect_addrs(HashSet::default())
// setting to sane defaults
.ttl(None)
.republication_interval(None)
.build()
.unwrap()
} else {
Expand All @@ -207,6 +210,9 @@ where
.node_type(NetworkNodeType::Regular)
.bound_addr(Some(addr))
.to_connect_addrs(HashSet::default())
// setting to sane defaults
.ttl(None)
.republication_interval(None)
.build()
.unwrap()
};
Expand Down

0 comments on commit f193182

Please sign in to comment.