@@ -104,7 +104,7 @@ pub use voting_rule::{
104104} ;
105105
106106use aux_schema:: PersistentData ;
107- use environment:: { Environment , VoterSetState } ;
107+ use environment:: { Environment , VoterSetState , Metrics } ;
108108use import:: GrandpaBlockImport ;
109109use until_imported:: UntilGlobalMessageBlocksImported ;
110110use communication:: { NetworkBridge , Network as NetworkT } ;
@@ -551,6 +551,8 @@ pub struct GrandpaParams<Block: BlockT, C, N, SC, VR, X> {
551551 pub telemetry_on_connect : Option < futures:: channel:: mpsc:: UnboundedReceiver < ( ) > > ,
552552 /// A voting rule used to potentially restrict target votes.
553553 pub voting_rule : VR ,
554+ /// The prometheus metrics registry.
555+ pub prometheus_registry : Option < prometheus_endpoint:: Registry > ,
554556}
555557
556558/// Run a GRANDPA voter as a task. Provide configuration and a link to a
@@ -576,6 +578,7 @@ pub fn run_grandpa_voter<Block: BlockT, BE: 'static, C, N, SC, VR, X>(
576578 on_exit,
577579 telemetry_on_connect,
578580 voting_rule,
581+ prometheus_registry,
579582 } = grandpa_params;
580583
581584 // NOTE: we have recently removed `run_grandpa_observer` from the public
@@ -634,6 +637,7 @@ pub fn run_grandpa_voter<Block: BlockT, BE: 'static, C, N, SC, VR, X>(
634637 voting_rule,
635638 persistent_data,
636639 voter_commands_rx,
640+ prometheus_registry,
637641 ) ;
638642
639643 let voter_work = voter_work
@@ -673,6 +677,7 @@ where
673677 voting_rule : VR ,
674678 persistent_data : PersistentData < Block > ,
675679 voter_commands_rx : mpsc:: UnboundedReceiver < VoterCommand < Block :: Hash , NumberFor < Block > > > ,
680+ prometheus_registry : Option < prometheus_endpoint:: Registry > ,
676681 ) -> Self {
677682
678683 let voters = persistent_data. authority_set . current_authorities ( ) ;
@@ -687,6 +692,10 @@ where
687692 authority_set : persistent_data. authority_set . clone ( ) ,
688693 consensus_changes : persistent_data. consensus_changes . clone ( ) ,
689694 voter_set_state : persistent_data. set_state . clone ( ) ,
695+ metrics : prometheus_registry. map ( |registry| {
696+ Metrics :: register ( & registry)
697+ . expect ( "Other metrics would have failed to register before these; qed" )
698+ } ) ,
690699 _phantom : PhantomData ,
691700 } ) ;
692701
@@ -807,6 +816,7 @@ where
807816 consensus_changes : self . env . consensus_changes . clone ( ) ,
808817 network : self . env . network . clone ( ) ,
809818 voting_rule : self . env . voting_rule . clone ( ) ,
819+ metrics : self . env . metrics . clone ( ) ,
810820 _phantom : PhantomData ,
811821 } ) ;
812822
0 commit comments