-
Notifications
You must be signed in to change notification settings - Fork 173
[consensus/simplex] Add Voting Metrics #2708
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
Changes from all commits
1ca9845
e07ac9d
4e53964
8fbc958
cf2cc46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ use crate::{ | |
| simplex::{ | ||
| actors::voter, | ||
| interesting, | ||
| metrics::Inbound, | ||
| metrics::{Inbound, Peer}, | ||
| scheme::Scheme, | ||
| types::{Activity, Certificate, Vote}, | ||
| }, | ||
|
|
@@ -15,12 +15,17 @@ use commonware_macros::select; | |
| use commonware_p2p::{utils::codec::WrappedReceiver, Blocker, Receiver}; | ||
| use commonware_runtime::{ | ||
| spawn_cell, | ||
| telemetry::metrics::histogram::{self, Buckets}, | ||
| telemetry::metrics::{ | ||
| histogram::{self, Buckets}, | ||
| status::GaugeExt, | ||
| }, | ||
| Clock, ContextCell, Handle, Metrics, Spawner, | ||
| }; | ||
| use commonware_utils::ordered::{Quorum, Set}; | ||
| use futures::{channel::mpsc, StreamExt}; | ||
| use prometheus_client::metrics::{counter::Counter, family::Family, histogram::Histogram}; | ||
| use prometheus_client::metrics::{ | ||
| counter::Counter, family::Family, gauge::Gauge, histogram::Histogram, | ||
| }; | ||
| use rand_core::CryptoRngCore; | ||
| use std::{collections::BTreeMap, sync::Arc}; | ||
| use tracing::{debug, trace, warn}; | ||
|
|
@@ -49,6 +54,7 @@ pub struct Actor< | |
| added: Counter, | ||
| verified: Counter, | ||
| inbound_messages: Family<Inbound, Counter>, | ||
| latest_vote: Family<Peer, Gauge>, | ||
| batch_size: Histogram, | ||
| verify_latency: histogram::Timed<E>, | ||
| recover_latency: histogram::Timed<E>, | ||
|
|
@@ -79,6 +85,15 @@ impl< | |
| "number of inbound messages", | ||
| inbound_messages.clone(), | ||
| ); | ||
| let latest_vote = Family::<Peer, Gauge>::default(); | ||
| context.register( | ||
| "latest_vote", | ||
| "view of latest vote received per peer", | ||
| latest_vote.clone(), | ||
| ); | ||
| for participant in cfg.scheme.participants().iter() { | ||
| latest_vote.get_or_create(&Peer::new(participant)).set(0); | ||
| } | ||
| context.register( | ||
| "batch_size", | ||
| "number of messages in a signature verification batch", | ||
|
|
@@ -99,12 +114,11 @@ impl< | |
| // TODO(#1833): Metrics should use the post-start context | ||
| let clock = Arc::new(context.clone()); | ||
| let (sender, receiver) = mpsc::channel(cfg.mailbox_size); | ||
| let participants = cfg.scheme.participants().clone(); | ||
| ( | ||
| Self { | ||
| context: ContextCell::new(context), | ||
|
|
||
| participants, | ||
| participants: cfg.scheme.participants().clone(), | ||
| scheme: cfg.scheme, | ||
|
|
||
| blocker: cfg.blocker, | ||
|
|
@@ -119,6 +133,7 @@ impl< | |
| added, | ||
| verified, | ||
| inbound_messages, | ||
| latest_vote, | ||
| batch_size, | ||
| verify_latency: histogram::Timed::new(verify_latency, clock.clone()), | ||
| recover_latency: histogram::Timed::new(recover_latency, clock), | ||
|
|
@@ -397,12 +412,19 @@ impl< | |
| } | ||
|
|
||
| // Add the vote to the verifier | ||
| let peer = Peer::new(&sender); | ||
| if work | ||
| .entry(view) | ||
| .or_insert_with(|| self.new_round()) | ||
| .add_network(sender, message) | ||
| .await { | ||
| self.added.inc(); | ||
|
|
||
| // Update per-peer latest vote metric (only if higher than current) | ||
| let _ = self | ||
| .latest_vote | ||
| .get_or_create(&peer) | ||
| .try_set_max(view.get()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opted to move into post-network validation to avoid duplicating its checks (to ensure a peer, for example is in participants -> thank you based bugbot).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't happen with our current p2p but we should be defensive. |
||
| } | ||
| updated_view = view; | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be annoying to work with in practice in something like
resharebecause we namespace metrics by epoch (so you'd have to constantly be updating your dashboard I think?)But that should be considered in a follow-up.