@@ -136,70 +136,78 @@ impl<T> NonFinalizedTree<T> {
136136 & self . finalized_block_header
137137 } ;
138138
139- let header_verify_result = {
140- let consensus_config = match ( & self . finalized_consensus , & parent_consensus) {
141- (
142- FinalizedConsensus :: Aura { slot_duration, .. } ,
143- Some ( BlockConsensus :: Aura { authorities_list } ) ,
144- ) => verify:: header_only:: ConfigConsensus :: Aura {
145- current_authorities : header:: AuraAuthoritiesIter :: from_slice ( authorities_list) ,
146- now_from_unix_epoch,
147- slot_duration : * slot_duration,
148- } ,
149- (
150- FinalizedConsensus :: Babe {
151- slots_per_epoch, ..
139+ let ( best_score_num_primary_slots, best_score_num_secondary_slots, consensus_update) = {
140+ let header_verify_result = {
141+ let consensus_config = match ( & self . finalized_consensus , & parent_consensus) {
142+ (
143+ FinalizedConsensus :: Aura { slot_duration, .. } ,
144+ Some ( BlockConsensus :: Aura { authorities_list } ) ,
145+ ) => verify:: header_only:: ConfigConsensus :: Aura {
146+ current_authorities : header:: AuraAuthoritiesIter :: from_slice (
147+ authorities_list,
148+ ) ,
149+ now_from_unix_epoch,
150+ slot_duration : * slot_duration,
151+ // Parachains with async backing can produce multiple blocks per
152+ // Aura slot. Outsourced finality indicates a parachain.
153+ allow_equal_slot_number : matches ! ( self . finality, Finality :: Outsourced ) ,
152154 } ,
153- Some ( BlockConsensus :: Babe {
154- current_epoch,
155- next_epoch,
156- } ) ,
157- ) => verify:: header_only:: ConfigConsensus :: Babe {
158- parent_block_epoch : current_epoch. as_ref ( ) . map ( |v| ( & * * v) . into ( ) ) ,
159- parent_block_next_epoch : ( & * * next_epoch) . into ( ) ,
160- slots_per_epoch : * slots_per_epoch,
161- now_from_unix_epoch,
162- } ,
163- ( FinalizedConsensus :: Unknown , None ) => {
164- return Err ( HeaderVerifyError :: UnknownConsensusEngine ) ;
165- }
166- _ => {
167- return Err ( HeaderVerifyError :: ConsensusMismatch ) ;
168- }
169- } ;
155+ (
156+ FinalizedConsensus :: Babe {
157+ slots_per_epoch, ..
158+ } ,
159+ Some ( BlockConsensus :: Babe {
160+ current_epoch,
161+ next_epoch,
162+ } ) ,
163+ ) => verify:: header_only:: ConfigConsensus :: Babe {
164+ parent_block_epoch : current_epoch. as_ref ( ) . map ( |v| ( & * * v) . into ( ) ) ,
165+ parent_block_next_epoch : ( & * * next_epoch) . into ( ) ,
166+ slots_per_epoch : * slots_per_epoch,
167+ now_from_unix_epoch,
168+ } ,
169+ ( FinalizedConsensus :: Unknown , None ) => {
170+ return Err ( HeaderVerifyError :: UnknownConsensusEngine ) ;
171+ }
172+ _ => {
173+ return Err ( HeaderVerifyError :: ConsensusMismatch ) ;
174+ }
175+ } ;
170176
171- match verify:: header_only:: verify ( verify:: header_only:: Config {
172- consensus : consensus_config,
173- finality : match & parent_finality {
174- BlockFinality :: Outsourced => verify:: header_only:: ConfigFinality :: Outsourced ,
175- BlockFinality :: Grandpa { .. } => verify:: header_only:: ConfigFinality :: Grandpa ,
176- } ,
177- allow_unknown_consensus_engines : self . allow_unknown_consensus_engines ,
178- block_header : decoded_header. clone ( ) ,
179- block_number_bytes : self . block_number_bytes ,
180- parent_block_header : {
181- // All headers inserted in `self` are necessarily valid, and thus this
182- // `unwrap()` can't panic.
183- header:: decode ( parent_block_header, self . block_number_bytes )
184- . unwrap_or_else ( |_| unreachable ! ( ) )
185- } ,
186- } ) {
187- Ok ( s) => s,
188- Err ( err) => {
189- // The code in this module is meant to ensure that the chain is in an
190- // appropriate state, therefore `is_invalid_chain_configuration` being `true`
191- // would indicate a bug in the code somewhere.
192- // We use a `debug_assert` rather than `assert` in order to avoid crashing,
193- // as treating the header as invalid is an appropriate way to handle a bug
194- // here.
195- debug_assert ! ( !err. is_invalid_chain_configuration( ) ) ;
196- return Err ( HeaderVerifyError :: VerificationFailed ( err) ) ;
177+ match verify:: header_only:: verify ( verify:: header_only:: Config {
178+ consensus : consensus_config,
179+ finality : match & parent_finality {
180+ BlockFinality :: Outsourced => {
181+ verify:: header_only:: ConfigFinality :: Outsourced
182+ }
183+ BlockFinality :: Grandpa { .. } => {
184+ verify:: header_only:: ConfigFinality :: Grandpa
185+ }
186+ } ,
187+ allow_unknown_consensus_engines : self . allow_unknown_consensus_engines ,
188+ block_header : decoded_header. clone ( ) ,
189+ block_number_bytes : self . block_number_bytes ,
190+ parent_block_header : {
191+ // All headers inserted in `self` are necessarily valid, and thus this
192+ // `unwrap()` can't panic.
193+ header:: decode ( parent_block_header, self . block_number_bytes )
194+ . unwrap_or_else ( |_| unreachable ! ( ) )
195+ } ,
196+ } ) {
197+ Ok ( s) => s,
198+ Err ( err) => {
199+ // The code in this module is meant to ensure that the chain is in an
200+ // appropriate state, therefore `is_invalid_chain_configuration` being `true`
201+ // would indicate a bug in the code somewhere.
202+ // We use a `debug_assert` rather than `assert` in order to avoid crashing,
203+ // as treating the header as invalid is an appropriate way to handle a bug
204+ // here.
205+ debug_assert ! ( !err. is_invalid_chain_configuration( ) ) ;
206+ return Err ( HeaderVerifyError :: VerificationFailed ( err) ) ;
207+ }
197208 }
198- }
199- } ;
209+ } ;
200210
201- // Updated consensus information for the block being verified.
202- let ( best_score_num_primary_slots, best_score_num_secondary_slots, consensus_update) =
203211 match (
204212 header_verify_result,
205213 & parent_consensus,
@@ -358,10 +366,11 @@ impl<T> NonFinalizedTree<T> {
358366 )
359367 }
360368
361- // Any mismatch between consensus algorithms should have been detected by the
362- // block verification.
369+ // Any mismatch between consensus algorithms should have been detected by
370+ // the block verification.
363371 _ => unreachable ! ( ) ,
364- } ;
372+ }
373+ } ;
365374
366375 // Updated finality information for the block being verified.
367376 let finality_update = match & parent_finality {
0 commit comments