Skip to content

Commit 9f19338

Browse files
committed
Early Epoch End decision making (ConnectivityTracker) is now based on ANY Hbbft Message send by the Partner Node, and node just judging by sealing Messages.
In some cases the Nodes do not even send their Sealing Messages late, because the Block finalization is faster than their Sealing Message Communication. Probably due their geographical location. This also means we can reduce the grace periods again: Switched the treshhold_time from 60 minutes to 22 minutes, and reduced it from 10 blocks to 2 blocks. see: DMDcoin#87
1 parent b7db6e7 commit 9f19338

File tree

4 files changed

+62
-28
lines changed

4 files changed

+62
-28
lines changed

crates/ethcore/src/client/client.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,33 @@ struct ClientStatistics {
203203
sent_consensus_messages_bytes: AtomicU64,
204204
}
205205

206-
207206
impl PrometheusMetrics for ClientStatistics {
208-
209207
fn prometheus_metrics(&self, r: &mut PrometheusRegistry) {
210208
if self.logging_enabled {
211-
r.register_counter("consens_messages_sent", "count", self.sent_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64);
212-
r.register_counter("consens_messages_sent_bytes", "bytes", self.sent_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64);
213-
r.register_counter("consens_messages_broadcasted", "count", self.broadcasted_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64);
214-
r.register_counter("consens_messages_broadcasted_bytes", "bytes", self.broadcasted_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64);
209+
r.register_counter(
210+
"consens_messages_sent",
211+
"count",
212+
self.sent_consensus_messages
213+
.load(std::sync::atomic::Ordering::Relaxed) as i64,
214+
);
215+
r.register_counter(
216+
"consens_messages_sent_bytes",
217+
"bytes",
218+
self.sent_consensus_messages_bytes
219+
.load(std::sync::atomic::Ordering::Relaxed) as i64,
220+
);
221+
r.register_counter(
222+
"consens_messages_broadcasted",
223+
"count",
224+
self.broadcasted_consensus_messages
225+
.load(std::sync::atomic::Ordering::Relaxed) as i64,
226+
);
227+
r.register_counter(
228+
"consens_messages_broadcasted_bytes",
229+
"bytes",
230+
self.broadcasted_consensus_messages_bytes
231+
.load(std::sync::atomic::Ordering::Relaxed) as i64,
232+
);
215233
}
216234
}
217235
}
@@ -3637,16 +3655,14 @@ impl PrometheusMetrics for Client {
36373655

36383656
let lockd = Duration::from_millis(50);
36393657

3640-
self.state_db
3641-
.try_read_for(lockd)
3642-
.map(|state_db| {
3643-
let state_db_size = state_db.cache_size();
3644-
r.register_gauge(
3645-
"statedb_cache_size",
3646-
"State DB cache size",
3647-
state_db_size as i64,
3648-
);
3649-
});
3658+
self.state_db.try_read_for(lockd).map(|state_db| {
3659+
let state_db_size = state_db.cache_size();
3660+
r.register_gauge(
3661+
"statedb_cache_size",
3662+
"State DB cache size",
3663+
state_db_size as i64,
3664+
);
3665+
});
36503666

36513667
// blockchain cache
36523668
let blockchain_cache_info = self.blockchain_cache_info();

crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ impl HbbftEarlyEpochEndManager {
243243
client: &dyn EngineClient,
244244
other_validator_address: &Address,
245245
) -> bool {
246+
// todo: for performance improvements, we could apply caching here,
247+
// once we are up to date with the contract information and track the inclusion of our own reports.
246248
let result = is_connectivity_loss_reported(
247249
client,
248250
BlockId::Latest,
@@ -291,11 +293,11 @@ impl HbbftEarlyEpochEndManager {
291293
return;
292294
};
293295

294-
let treshold: u64 = 10;
296+
let treshold: u64 = 2;
295297
// todo: read this out from contracts: ConnectivityTrackerHbbft -> reportDisallowPeriod
296298
// requires us to update the Contracts ABIs:
297299
// https://github.com/DMDcoin/diamond-node/issues/115
298-
let treshold_time = Duration::from_secs(60 * 60);
300+
let treshold_time = Duration::from_secs(22 * 60); // 22 Minutes = 2 times the heartbeat + 2 minutes as grace period.
299301

300302
if self.start_time.elapsed() < treshold_time {
301303
debug!(target: "engine", "early-epoch-end: no decision: Treshold time not reached.");
@@ -324,9 +326,9 @@ impl HbbftEarlyEpochEndManager {
324326
};
325327

326328
if let Some(node_history) = epoch_history.get_history_for_node(validator) {
327-
let last_sealing_message_time = node_history.get_last_sealing_message_time();
328-
let last_sealing_message_lateness = last_sealing_message_time.elapsed();
329-
if last_sealing_message_lateness > treshold_time {
329+
let last_message_time = node_history.get_last_good_message_time();
330+
let last_message_time_lateness = last_message_time.elapsed();
331+
if last_message_time_lateness > treshold_time {
330332
// we do not have to send notification, if we already did so.
331333
if !self.is_reported(client, validator_address) {
332334
// this function will also add the validator to the list of flagged validators.

crates/ethcore/src/engines/hbbft/hbbft_message_memorium.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub(crate) struct NodeStakingEpochHistory {
6363
// messages.
6464
last_message_faulty: u64,
6565
last_message_good: u64,
66+
last_message_good_time: Instant,
6667

6768
num_faulty_messages: u64,
6869
num_good_messages: u64, // total_contributions_good: u64,
@@ -86,6 +87,7 @@ impl NodeStakingEpochHistory {
8687
sealing_blocks_bad: Vec::new(),
8788
last_message_faulty: 0,
8889
last_message_good: 0,
90+
last_message_good_time: now,
8991
num_faulty_messages: 0,
9092
num_good_messages: 0,
9193
}
@@ -215,6 +217,7 @@ impl NodeStakingEpochHistory {
215217
// warn!(target: "hbbft_message_memorium", "add_message_event_good: ! event.block_num {block_num} > last_message_good {last_message_good}");
216218
// }
217219
self.num_good_messages += 1;
220+
self.last_message_good_time = Instant::now();
218221
}
219222

220223
/// GETTERS
@@ -251,6 +254,10 @@ impl NodeStakingEpochHistory {
251254
)
252255
}
253256

257+
pub fn get_last_good_message_time(&self) -> Instant {
258+
self.last_message_good_time
259+
}
260+
254261
pub fn get_last_late_sealing_message(&self) -> u64 {
255262
self.last_late_sealing_message
256263
}

crates/net/network-devp2p/src/host.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,24 @@ impl NetworkingStatistics {
131131
}
132132
}
133133

134-
135134
impl PrometheusMetrics for NetworkingStatistics {
136-
137135
fn prometheus_metrics(&self, registry: &mut PrometheusRegistry) {
138-
registry.register_counter("p2p_bytes_sent","total", self.bytes_sent.load(std::sync::atomic::Ordering::Relaxed) as i64);
139-
registry.register_counter("p2p_packages_sent","count", self.packages_send.load(std::sync::atomic::Ordering::Relaxed) as i64);
140-
registry.register_counter("p2p_peer_losses","count", self.peer_losses.load(std::sync::atomic::Ordering::Relaxed) as i64);
136+
registry.register_counter(
137+
"p2p_bytes_sent",
138+
"total",
139+
self.bytes_sent.load(std::sync::atomic::Ordering::Relaxed) as i64,
140+
);
141+
registry.register_counter(
142+
"p2p_packages_sent",
143+
"count",
144+
self.packages_send
145+
.load(std::sync::atomic::Ordering::Relaxed) as i64,
146+
);
147+
registry.register_counter(
148+
"p2p_peer_losses",
149+
"count",
150+
self.peer_losses.load(std::sync::atomic::Ordering::Relaxed) as i64,
151+
);
141152
}
142153
}
143154

@@ -1545,7 +1556,6 @@ impl IoHandler<NetworkIoMessage> for Host {
15451556

15461557
impl PrometheusMetrics for Host {
15471558
fn prometheus_metrics(&self, r: &mut PrometheusRegistry) {
1548-
15491559
let lockdur = Duration::from_millis(20);
15501560

15511561
if let Some((handshakes, egress, ingress)) =
@@ -1565,7 +1575,6 @@ impl PrometheusMetrics for Host {
15651575
r.register_gauge("p2p_uselessnodes", "count", nodes.count_useless() as i64);
15661576
}
15671577

1568-
15691578
self.statistics.prometheus_metrics(r);
15701579
}
15711580

0 commit comments

Comments
 (0)