Skip to content

Commit 3297a96

Browse files
authored
Merge pull request #1172 from input-output-hk/network-perf-update
poldercast crate update and automatic topology reset
2 parents 0aa6b9a + 4f06fd2 commit 3297a96

File tree

8 files changed

+59
-9
lines changed

8 files changed

+59
-9
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/configuration/network.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ p2p:
4848
Every time a new propagation event is triggered, the node will select
4949
randomly a certain amount of unreachable nodes to connect to in addition
5050
to the one selected by other p2p topology layer `[default: 20]`
51-
51+
- `gossip_interval`: (optional) interval to start gossiping with new nodes,
52+
changing the value will affect the bandwidth. The more often the node will
53+
gossip the more bandwidth the node will need. The less often the node gossips
54+
the less good the resilience to node churn. `[default: 10]`
55+
- `topology_force_reset_interval`: (optional) If this value is set, it will
56+
trigger a force reset of the topology layers. The default is to not do
57+
force the reset. It is recommended to let the protocol handle it.
5258

5359
### The trusted peers
5460

jormungandr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ linked-hash-map = "0.5"
3939
native-tls = "0.2.2"
4040
network-core = { path = "../chain-deps/network-core" }
4141
network-grpc = { path = "../chain-deps/network-grpc" }
42-
poldercast = "0.9.7"
42+
poldercast = "0.9.9"
4343
rand = "0.6"
4444
serde = "1.0"
4545
serde_derive = "1.0"

jormungandr/src/network/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,20 @@ pub fn start(
255255
let handle_cmds = handle_network_input(input, global_state.clone(), channels.clone());
256256

257257
let gossip_err_logger = global_state.logger.clone();
258-
// TODO: get gossip propagation interval from configuration
259-
let gossip = Interval::new_interval(Duration::from_secs(10))
258+
let reset_err_logger = global_state.logger.clone();
259+
let tp2p = global_state.topology.clone();
260+
261+
if let Some(interval) = global_state.config.topology_force_reset_interval.clone() {
262+
global_state.spawn(
263+
Interval::new_interval(interval)
264+
.map_err(move |e| {
265+
error!(reset_err_logger, "interval timer error: {:?}", e);
266+
})
267+
.for_each(move |_| Ok(tp2p.force_reset_layers())),
268+
);
269+
}
270+
271+
let gossip = Interval::new_interval(global_state.config.gossip_interval.clone())
260272
.map_err(move |e| {
261273
error!(gossip_err_logger, "interval timer error: {:?}", e);
262274
})

jormungandr/src/network/p2p/topology.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use slog::Logger;
1414
use std::sync::{Arc, RwLock};
1515

1616
/// object holding the P2pTopology of the Node
17+
#[derive(Clone)]
1718
pub struct P2pTopology {
1819
lock: Arc<RwLock<Topology>>,
1920
logger: Logger,
@@ -96,6 +97,10 @@ impl P2pTopology {
9697
self.lock.read().unwrap().profile().clone()
9798
}
9899

100+
pub fn force_reset_layers(&self) {
101+
self.lock.write().unwrap().force_reset_layers()
102+
}
103+
99104
/// register a strike against the given node id
100105
///
101106
/// the function returns `None` if the node was not even in the

jormungandr/src/settings/start/config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ pub struct P2pConfig {
108108
/// to the one selected by other p2p topology layer.
109109
#[serde(default)]
110110
pub max_unreachable_nodes_to_connect_per_event: Option<usize>,
111+
112+
/// interval to start gossiping with new nodes, changing the value will
113+
/// affect the bandwidth. The more often the node will gossip the more
114+
/// bandwidth the node will need. The less often the node gossips the less
115+
/// good the resilience to node churn.
116+
///
117+
/// The default value is 10seconds.
118+
#[serde(default)]
119+
pub gossip_interval: Option<Duration>,
120+
121+
/// If this value is set, it will trigger a force reset of the topology
122+
/// layers. The default is to not do force the reset. It is recommended
123+
/// to let the protocol handle it.
124+
///
125+
#[serde(default)]
126+
pub topology_force_reset_interval: Option<Duration>,
111127
}
112128

113129
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -169,6 +185,8 @@ impl Default for P2pConfig {
169185
allow_private_addresses: false,
170186
policy: PolicyConfig::default(),
171187
max_unreachable_nodes_to_connect_per_event: None,
188+
gossip_interval: None,
189+
topology_force_reset_interval: None,
172190
}
173191
}
174192
}

jormungandr/src/settings/start/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ fn generate_network(
243243
timeout: std::time::Duration::from_secs(15),
244244
allow_private_addresses: p2p.allow_private_addresses,
245245
max_unreachable_nodes_to_connect_per_event: p2p.max_unreachable_nodes_to_connect_per_event,
246+
gossip_interval: p2p
247+
.gossip_interval
248+
.map(|d| d.into())
249+
.unwrap_or(std::time::Duration::from_secs(10)),
250+
topology_force_reset_interval: p2p.topology_force_reset_interval.map(|d| d.into()),
246251
};
247252

248253
Ok(network)

jormungandr/src/settings/start/network.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub struct Configuration {
6868
pub allow_private_addresses: bool,
6969

7070
pub max_unreachable_nodes_to_connect_per_event: Option<usize>,
71+
72+
pub gossip_interval: Duration,
73+
74+
pub topology_force_reset_interval: Option<Duration>,
7175
}
7276

7377
#[derive(Clone)]

0 commit comments

Comments
 (0)