@@ -39,7 +39,7 @@ use sp_runtime::generic::BlockId;
39
39
use sp_runtime:: traits:: {
40
40
Block as BlockT , Header as HeaderT , NumberFor , One , Zero ,
41
41
} ;
42
- use sc_telemetry:: { telemetry, CONSENSUS_INFO } ;
42
+ use sc_telemetry:: { telemetry, CONSENSUS_DEBUG , CONSENSUS_INFO } ;
43
43
44
44
use crate :: {
45
45
CommandOrError , Commit , Config , Error , Precommit , Prevote ,
@@ -59,7 +59,7 @@ use sp_finality_grandpa::{
59
59
AuthorityId , AuthoritySignature , Equivocation , EquivocationProof ,
60
60
GrandpaApi , RoundNumber , SetId ,
61
61
} ;
62
- use prometheus_endpoint:: { Gauge , U64 , register , PrometheusError } ;
62
+ use prometheus_endpoint:: { register , Counter , Gauge , PrometheusError , U64 } ;
63
63
64
64
type HistoricalVotes < Block > = finality_grandpa:: HistoricalVotes <
65
65
<Block as BlockT >:: Hash ,
@@ -378,14 +378,32 @@ impl<Block: BlockT> SharedVoterSetState<Block> {
378
378
#[ derive( Clone ) ]
379
379
pub ( crate ) struct Metrics {
380
380
finality_grandpa_round : Gauge < U64 > ,
381
+ finality_grandpa_prevotes : Counter < U64 > ,
382
+ finality_grandpa_precommits : Counter < U64 > ,
381
383
}
382
384
383
385
impl Metrics {
384
- pub ( crate ) fn register ( registry : & prometheus_endpoint:: Registry ) -> Result < Self , PrometheusError > {
386
+ pub ( crate ) fn register (
387
+ registry : & prometheus_endpoint:: Registry ,
388
+ ) -> Result < Self , PrometheusError > {
385
389
Ok ( Self {
386
390
finality_grandpa_round : register (
387
391
Gauge :: new ( "finality_grandpa_round" , "Highest completed GRANDPA round." ) ?,
388
- registry
392
+ registry,
393
+ ) ?,
394
+ finality_grandpa_prevotes : register (
395
+ Counter :: new (
396
+ "finality_grandpa_prevotes_total" ,
397
+ "Total number of GRANDPA prevotes cast locally." ,
398
+ ) ?,
399
+ registry,
400
+ ) ?,
401
+ finality_grandpa_precommits : register (
402
+ Counter :: new (
403
+ "finality_grandpa_precommits_total" ,
404
+ "Total number of GRANDPA precommits cast locally." ,
405
+ ) ?,
406
+ registry,
389
407
) ?,
390
408
} )
391
409
}
@@ -804,9 +822,22 @@ where
804
822
None => return Ok ( ( ) ) ,
805
823
} ;
806
824
825
+ let report_prevote_metrics = |prevote : & Prevote < Block > | {
826
+ telemetry ! ( CONSENSUS_DEBUG ; "afg.prevote_issued" ;
827
+ "round" => round,
828
+ "target_number" => ?prevote. target_number,
829
+ "target_hash" => ?prevote. target_hash,
830
+ ) ;
831
+
832
+ if let Some ( metrics) = self . metrics . as_ref ( ) {
833
+ metrics. finality_grandpa_prevotes . inc ( ) ;
834
+ }
835
+ } ;
836
+
807
837
self . update_voter_set_state ( |voter_set_state| {
808
838
let ( completed_rounds, current_rounds) = voter_set_state. with_current_round ( round) ?;
809
- let current_round = current_rounds. get ( & round)
839
+ let current_round = current_rounds
840
+ . get ( & round)
810
841
. expect ( "checked in with_current_round that key exists; qed." ) ;
811
842
812
843
if !current_round. can_prevote ( ) {
@@ -816,6 +847,9 @@ where
816
847
return Ok ( None ) ;
817
848
}
818
849
850
+ // report to telemetry and prometheus
851
+ report_prevote_metrics ( & prevote) ;
852
+
819
853
let propose = current_round. propose ( ) ;
820
854
821
855
let mut current_rounds = current_rounds. clone ( ) ;
@@ -837,17 +871,34 @@ where
837
871
Ok ( ( ) )
838
872
}
839
873
840
- fn precommitted ( & self , round : RoundNumber , precommit : Precommit < Block > ) -> Result < ( ) , Self :: Error > {
874
+ fn precommitted (
875
+ & self ,
876
+ round : RoundNumber ,
877
+ precommit : Precommit < Block > ,
878
+ ) -> Result < ( ) , Self :: Error > {
841
879
let local_id = crate :: is_voter ( & self . voters , self . config . keystore . as_ref ( ) ) ;
842
880
843
881
let local_id = match local_id {
844
882
Some ( id) => id,
845
883
None => return Ok ( ( ) ) ,
846
884
} ;
847
885
886
+ let report_precommit_metrics = |precommit : & Precommit < Block > | {
887
+ telemetry ! ( CONSENSUS_DEBUG ; "afg.precommit_issued" ;
888
+ "round" => round,
889
+ "target_number" => ?precommit. target_number,
890
+ "target_hash" => ?precommit. target_hash,
891
+ ) ;
892
+
893
+ if let Some ( metrics) = self . metrics . as_ref ( ) {
894
+ metrics. finality_grandpa_precommits . inc ( ) ;
895
+ }
896
+ } ;
897
+
848
898
self . update_voter_set_state ( |voter_set_state| {
849
899
let ( completed_rounds, current_rounds) = voter_set_state. with_current_round ( round) ?;
850
- let current_round = current_rounds. get ( & round)
900
+ let current_round = current_rounds
901
+ . get ( & round)
851
902
. expect ( "checked in with_current_round that key exists; qed." ) ;
852
903
853
904
if !current_round. can_precommit ( ) {
@@ -857,13 +908,16 @@ where
857
908
return Ok ( None ) ;
858
909
}
859
910
911
+ // report to telemetry and prometheus
912
+ report_precommit_metrics ( & precommit) ;
913
+
860
914
let propose = current_round. propose ( ) ;
861
915
let prevote = match current_round {
862
916
HasVoted :: Yes ( _, Vote :: Prevote ( _, prevote) ) => prevote,
863
917
_ => {
864
918
let msg = "Voter precommitting before prevoting." ;
865
919
return Err ( Error :: Safety ( msg. to_string ( ) ) ) ;
866
- } ,
920
+ }
867
921
} ;
868
922
869
923
let mut current_rounds = current_rounds. clone ( ) ;
0 commit comments