@@ -461,3 +461,51 @@ async fn wait_to_announce<Block: BlockT>(
461461 ) ;
462462 }
463463}
464+
465+ /// A [`BlockAnnounceValidator`] which accepts all block announcements, as it assumes
466+ /// sybil resistance is handled elsewhere.
467+ #[ derive( Debug , Clone ) ]
468+ pub struct AssumeSybilResistance ( bool ) ;
469+
470+ impl AssumeSybilResistance {
471+ /// Instantiate this block announcement validator while permissively allowing (but ignoring)
472+ /// announcements which come tagged with seconded messages.
473+ ///
474+ /// This is useful for backwards compatibility when upgrading nodes: old nodes will continue
475+ /// to broadcast announcements with seconded messages, so these announcements shouldn't be ignored
476+ /// and the peers not punished.
477+ pub fn allow_seconded_messages ( ) -> Self {
478+ AssumeSybilResistance ( true )
479+ }
480+
481+ /// Instantiate this block announcement validator while rejecting announcements that come with
482+ /// data.
483+ pub fn reject_seconded_messages ( ) -> Self {
484+ AssumeSybilResistance ( false )
485+ }
486+ }
487+
488+ impl < Block : BlockT > BlockAnnounceValidatorT < Block > for AssumeSybilResistance {
489+ fn validate (
490+ & mut self ,
491+ _header : & Block :: Header ,
492+ data : & [ u8 ] ,
493+ ) -> Pin < Box < dyn Future < Output = Result < Validation , BoxedError > > + Send > > {
494+ let allow_seconded_messages = self . 0 ;
495+ let data = data. to_vec ( ) ;
496+
497+ async move {
498+ Ok ( if data. is_empty ( ) {
499+ Validation :: Success { is_new_best : false }
500+ } else if !allow_seconded_messages {
501+ Validation :: Failure { disconnect : false }
502+ } else {
503+ match BlockAnnounceData :: decode_all ( & mut data. as_slice ( ) ) {
504+ Ok ( _) => Validation :: Success { is_new_best : false } ,
505+ Err ( _) => Validation :: Failure { disconnect : true } ,
506+ }
507+ } )
508+ }
509+ . boxed ( )
510+ }
511+ }
0 commit comments