@@ -105,6 +105,34 @@ mod benefit {
105105 pub ( super ) const PER_EQUIVOCATION : i32 = 10 ;
106106}
107107
108+ /// A type that ties together our local authority id and a keystore where it is
109+ /// available for signing.
110+ pub struct LocalIdKeystore ( ( AuthorityId , BareCryptoStorePtr ) ) ;
111+
112+ impl LocalIdKeystore {
113+ /// Returns a reference to our local authority id.
114+ fn local_id ( & self ) -> & AuthorityId {
115+ & ( self . 0 ) . 0
116+ }
117+
118+ /// Returns a reference to the keystore.
119+ fn keystore ( & self ) -> & BareCryptoStorePtr {
120+ & ( self . 0 ) . 1
121+ }
122+ }
123+
124+ impl AsRef < BareCryptoStorePtr > for LocalIdKeystore {
125+ fn as_ref ( & self ) -> & BareCryptoStorePtr {
126+ self . keystore ( )
127+ }
128+ }
129+
130+ impl From < ( AuthorityId , BareCryptoStorePtr ) > for LocalIdKeystore {
131+ fn from ( inner : ( AuthorityId , BareCryptoStorePtr ) ) -> LocalIdKeystore {
132+ LocalIdKeystore ( inner)
133+ }
134+ }
135+
108136/// If the voter set is larger than this value some telemetry events are not
109137/// sent to avoid increasing usage resource on the node and flooding the
110138/// telemetry server (e.g. received votes, received commits.)
@@ -272,11 +300,10 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
272300 /// network all within the current set.
273301 pub ( crate ) fn round_communication (
274302 & self ,
275- keystore : Option < BareCryptoStorePtr > ,
303+ keystore : Option < LocalIdKeystore > ,
276304 round : Round ,
277305 set_id : SetId ,
278306 voters : Arc < VoterSet < AuthorityId > > ,
279- local_key : Option < AuthorityId > ,
280307 has_voted : HasVoted < B > ,
281308 ) -> (
282309 impl Stream < Item = SignedMessage < B > > + Unpin ,
@@ -288,9 +315,10 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
288315 & * voters,
289316 ) ;
290317
291- let local_id = local_key. and_then ( |id| {
292- if voters. contains ( & id) {
293- Some ( id)
318+ let keystore = keystore. and_then ( |ks| {
319+ let id = ks. local_id ( ) ;
320+ if voters. contains ( id) {
321+ Some ( ks)
294322 } else {
295323 None
296324 }
@@ -350,11 +378,10 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
350378
351379 let ( tx, out_rx) = mpsc:: channel ( 0 ) ;
352380 let outgoing = OutgoingMessages :: < B > {
353- keystore : keystore . clone ( ) ,
381+ keystore,
354382 round : round. 0 ,
355383 set_id : set_id. 0 ,
356384 network : self . gossip_engine . clone ( ) ,
357- local_id,
358385 sender : tx,
359386 has_voted,
360387 } ;
@@ -629,11 +656,10 @@ pub struct SetId(pub SetIdNumber);
629656 pub( crate ) struct OutgoingMessages <Block : BlockT > {
630657 round : RoundNumber ,
631658 set_id : SetIdNumber ,
632- local_id : Option < AuthorityId > ,
659+ keystore : Option < LocalIdKeystore > ,
633660 sender: mpsc:: Sender < SignedMessage < Block > > ,
634661 network: Arc < Mutex < GossipEngine < Block > > > ,
635662 has_voted: HasVoted < Block > ,
636- keystore: Option < BareCryptoStorePtr > ,
637663}
638664
639665impl<B : BlockT > Unpin for OutgoingMessages < B > { }
@@ -667,19 +693,12 @@ impl<Block: BlockT> Sink<Message<Block>> for OutgoingMessages<Block>
667693 }
668694
669695 // when locals exist, sign messages on import
670- if let Some ( ref public) = self . local_id {
671- let keystore = match & self . keystore {
672- Some ( keystore) => keystore. clone( ) ,
673- None => {
674- return Err ( Error :: Signing ( "Cannot sign without a keystore" . to_string( ) ) )
675- }
676- } ;
677-
696+ if let Some ( ref keystore) = self . keystore {
678697 let target_hash = * ( msg. target( ) . 0 ) ;
679698 let signed = sp_finality_grandpa:: sign_message(
680- keystore,
699+ keystore. as_ref ( ) ,
681700 msg,
682- public . clone( ) ,
701+ keystore . local_id ( ) . clone( ) ,
683702 self . round,
684703 self . set_id,
685704 ) . ok_or(
@@ -774,7 +793,7 @@ fn check_compact_commit<Block: BlockT>(
774793 use crate:: communication:: gossip:: Misbehavior ;
775794 use finality_grandpa:: Message as GrandpaMessage ;
776795
777- if let Err ( ( ) ) = sp_finality_grandpa:: check_message_signature_with_buffer (
796+ if ! sp_finality_grandpa:: check_message_signature_with_buffer (
778797 & GrandpaMessage :: Precommit ( precommit . clone( ) ) ,
779798 id ,
780799 sig ,
@@ -862,7 +881,7 @@ fn check_catch_up<Block: BlockT>(
862881 for ( msg, id, sig) in messages {
863882 signatures_checked += 1 ;
864883
865- if let Err ( ( ) ) = sp_finality_grandpa:: check_message_signature_with_buffer(
884+ if ! sp_finality_grandpa:: check_message_signature_with_buffer(
866885 & msg,
867886 id,
868887 sig,
0 commit comments