@@ -33,7 +33,7 @@ use sp_core::traits::SpawnNamed;
3333use sp_inherents:: { InherentData , InherentDataProviders } ;
3434use sp_runtime:: {
3535 generic:: BlockId ,
36- traits:: { BlakeTwo256 , Block as BlockT , Header as HeaderT } ,
36+ traits:: { BlakeTwo256 , Block as BlockT , Header as HeaderT , Zero } ,
3737} ;
3838use sp_state_machine:: InspectState ;
3939
@@ -59,6 +59,9 @@ use parking_lot::Mutex;
5959type TransactionFor < E , Block > =
6060 <<E as Environment < Block > >:: Proposer as Proposer < Block > >:: Transaction ;
6161
62+ /// The logging target.
63+ const LOG_TARGET : & str = "cumulus-collator" ;
64+
6265/// The implementation of the Cumulus `Collator`.
6366pub struct Collator < Block : BlockT , PF , BI , BS , Backend , PBackend , PClient , PBackend2 > {
6467 para_id : ParaId ,
@@ -162,7 +165,7 @@ where
162165 )
163166 . map_err ( |e| {
164167 error ! (
165- target: "cumulus-collator" ,
168+ target: LOG_TARGET ,
166169 "An error occured during requesting the downward messages for {}: {:?}" ,
167170 relay_parent, e,
168171 ) ;
@@ -187,7 +190,7 @@ where
187190 )
188191 . map_err ( |e| {
189192 error ! (
190- target: "cumulus-collator" ,
193+ target: LOG_TARGET ,
191194 "An error occured during requesting the inbound HRMP messages for {}: {:?}" ,
192195 relay_parent, e,
193196 ) ;
@@ -208,7 +211,7 @@ where
208211 . state_at ( BlockId :: Hash ( relay_parent) )
209212 . map_err ( |e| {
210213 error ! (
211- target: "cumulus-collator" ,
214+ target: LOG_TARGET ,
212215 "Cannot obtain the state of the relay chain at `{:?}`: {:?}" ,
213216 relay_parent,
214217 e,
@@ -222,7 +225,7 @@ where
222225 ) )
223226 . map_err ( |e| {
224227 error ! (
225- target: "cumulus-collator" ,
228+ target: LOG_TARGET ,
226229 "Cannot obtain the hrmp egress channel index: {:?}" ,
227230 e,
228231 )
@@ -233,7 +236,7 @@ where
233236 . transpose ( )
234237 . map_err ( |e| {
235238 error ! (
236- target: "cumulus-collator" ,
239+ target: LOG_TARGET ,
237240 "Cannot decode the hrmp egress channel index: {:?}" ,
238241 e,
239242 )
@@ -259,7 +262,7 @@ where
259262 sp_state_machine:: prove_read ( relay_parent_state_backend, relevant_keys)
260263 . map_err ( |e| {
261264 error ! (
262- target: "cumulus-collator" ,
265+ target: LOG_TARGET ,
263266 "Failed to collect required relay chain state storage proof at `{:?}`: {:?}" ,
264267 relay_parent,
265268 e,
@@ -279,7 +282,7 @@ where
279282 . create_inherent_data ( )
280283 . map_err ( |e| {
281284 error ! (
282- target: "cumulus-collator" ,
285+ target: LOG_TARGET ,
283286 "Failed to create inherent data: {:?}" ,
284287 e,
285288 )
@@ -307,7 +310,7 @@ where
307310 )
308311 . map_err ( |e| {
309312 error ! (
310- target: "cumulus-collator" ,
313+ target: LOG_TARGET ,
311314 "Failed to put the system inherent into inherent data: {:?}" ,
312315 e,
313316 )
@@ -320,39 +323,56 @@ where
320323 /// Checks the status of the given block hash in the Parachain.
321324 ///
322325 /// Returns `true` if the block could be found and is good to be build on.
323- fn check_block_status ( & self , hash : Block :: Hash ) -> bool {
326+ fn check_block_status ( & self , hash : Block :: Hash , header : & Block :: Header ) -> bool {
324327 match self . block_status . block_status ( & BlockId :: Hash ( hash) ) {
325328 Ok ( BlockStatus :: Queued ) => {
326329 debug ! (
327- target: "cumulus-collator" ,
328- "Skipping candidate production, because block `{:?}` is still queued for import." , hash,
330+ target: LOG_TARGET ,
331+ "Skipping candidate production, because block `{:?}` is still queued for import." ,
332+ hash,
329333 ) ;
330334 false
331335 }
332336 Ok ( BlockStatus :: InChainWithState ) => true ,
333337 Ok ( BlockStatus :: InChainPruned ) => {
334338 error ! (
335- target: "cumulus-collator" ,
336- "Skipping candidate production, because block `{:?}` is already pruned!" , hash,
339+ target: LOG_TARGET ,
340+ "Skipping candidate production, because block `{:?}` is already pruned!" ,
341+ hash,
337342 ) ;
338343 false
339344 }
340345 Ok ( BlockStatus :: KnownBad ) => {
341346 error ! (
342- target: "cumulus-collator" ,
343- "Block `{}` is tagged as known bad and is included in the relay chain! Skipping candidate production!" , hash,
347+ target: LOG_TARGET ,
348+ "Block `{}` is tagged as known bad and is included in the relay chain! Skipping candidate production!" ,
349+ hash,
344350 ) ;
345351 false
346352 }
347353 Ok ( BlockStatus :: Unknown ) => {
348- debug ! (
349- target: "cumulus-collator" ,
350- "Skipping candidate production, because block `{:?}` is unknown." , hash,
351- ) ;
354+ if header. number ( ) . is_zero ( ) {
355+ error ! (
356+ target: LOG_TARGET ,
357+ "Could not find the header `{:?}` of the genesis block in the database!" ,
358+ hash,
359+ ) ;
360+ } else {
361+ debug ! (
362+ target: LOG_TARGET ,
363+ "Skipping candidate production, because block `{:?}` is unknown." ,
364+ hash,
365+ ) ;
366+ }
352367 false
353368 }
354369 Err ( e) => {
355- error ! ( target: "cumulus-collator" , "Failed to get block status of `{:?}`: {:?}" , hash, e) ;
370+ error ! (
371+ target: LOG_TARGET ,
372+ "Failed to get block status of `{:?}`: {:?}" ,
373+ hash,
374+ e,
375+ ) ;
356376 false
357377 }
358378 }
@@ -371,7 +391,7 @@ where
371391 let state = match self . backend . state_at ( BlockId :: Hash ( block_hash) ) {
372392 Ok ( state) => state,
373393 Err ( e) => {
374- error ! ( target: "cumulus-collator" , "Failed to get state of the freshly built block: {:?}" , e) ;
394+ error ! ( target: LOG_TARGET , "Failed to get state of the freshly built block: {:?}" , e) ;
375395 return None ;
376396 }
377397 } ;
@@ -381,7 +401,7 @@ where
381401 let upward_messages = match upward_messages. map ( |v| Vec :: < UpwardMessage > :: decode ( & mut & v[ ..] ) ) {
382402 Some ( Ok ( msgs) ) => msgs,
383403 Some ( Err ( e) ) => {
384- error ! ( target: "cumulus-collator" , "Failed to decode upward messages from the build block: {:?}" , e) ;
404+ error ! ( target: LOG_TARGET , "Failed to decode upward messages from the build block: {:?}" , e) ;
385405 return None
386406 } ,
387407 None => Vec :: new ( ) ,
@@ -396,7 +416,7 @@ where
396416 Some ( Ok ( processed_cnt) ) => processed_cnt,
397417 Some ( Err ( e) ) => {
398418 error ! (
399- target: "cumulus-collator" ,
419+ target: LOG_TARGET ,
400420 "Failed to decode the count of processed downward messages: {:?}" ,
401421 e
402422 ) ;
@@ -412,7 +432,7 @@ where
412432 Some ( Ok ( horizontal_messages) ) => horizontal_messages,
413433 Some ( Err ( e) ) => {
414434 error ! (
415- target: "cumulus-collator" ,
435+ target: LOG_TARGET ,
416436 "Failed to decode the horizontal messages: {:?}" ,
417437 e
418438 ) ;
@@ -426,7 +446,7 @@ where
426446 Some ( Ok ( hrmp_watermark) ) => hrmp_watermark,
427447 Some ( Err ( e) ) => {
428448 error ! (
429- target: "cumulus-collator" ,
449+ target: LOG_TARGET ,
430450 "Failed to decode the HRMP watermark: {:?}" ,
431451 e
432452 ) ;
@@ -458,24 +478,24 @@ where
458478 relay_parent : PHash ,
459479 validation_data : PersistedValidationData ,
460480 ) -> Option < Collation > {
461- trace ! ( target: "cumulus-collator" , "Producing candidate" ) ;
481+ trace ! ( target: LOG_TARGET , "Producing candidate" ) ;
462482
463483 let last_head =
464484 match Block :: Header :: decode ( & mut & validation_data. parent_head . 0 [ ..] ) {
465485 Ok ( x) => x,
466486 Err ( e) => {
467- error ! ( target: "cumulus-collator" , "Could not decode the head data: {:?}" , e) ;
487+ error ! ( target: LOG_TARGET , "Could not decode the head data: {:?}" , e) ;
468488 return None ;
469489 }
470490 } ;
471491
472492 let last_head_hash = last_head. hash ( ) ;
473- if !self . check_block_status ( last_head_hash) {
493+ if !self . check_block_status ( last_head_hash, & last_head ) {
474494 return None ;
475495 }
476496
477497 info ! (
478- target: "cumulus-collator" ,
498+ target: LOG_TARGET ,
479499 "Starting collation for relay parent {:?} on parent {:?}." ,
480500 relay_parent,
481501 last_head_hash,
@@ -487,7 +507,7 @@ where
487507 . await
488508 . map_err ( |e| {
489509 error ! (
490- target: "cumulus-collator" ,
510+ target: LOG_TARGET ,
491511 "Could not create proposer: {:?}" ,
492512 e,
493513 )
@@ -511,7 +531,7 @@ where
511531 . await
512532 . map_err ( |e| {
513533 error ! (
514- target: "cumulus-collator" ,
534+ target: LOG_TARGET ,
515535 "Proposing failed: {:?}" ,
516536 e,
517537 )
@@ -522,7 +542,7 @@ where
522542 Some ( proof) => proof,
523543 None => {
524544 error ! (
525- target: "cumulus-collator" ,
545+ target: LOG_TARGET ,
526546 "Proposer did not return the requested proof." ,
527547 ) ;
528548
@@ -548,7 +568,7 @@ where
548568 . import_block ( block_import_params, Default :: default ( ) )
549569 {
550570 error ! (
551- target: "cumulus-collator" ,
571+ target: LOG_TARGET ,
552572 "Error importing build block (at {:?}): {:?}" ,
553573 b. header( ) . parent_hash( ) ,
554574 err,
@@ -558,7 +578,7 @@ where
558578 }
559579
560580 trace ! (
561- target: "cumulus-collator" ,
581+ target: LOG_TARGET ,
562582 "PoV size {{ header: {}kb, extrinsics: {}kb, storage_proof: {}kb }}" ,
563583 b. header( ) . encode( ) . len( ) as f64 / 1024f64 ,
564584 b. extrinsics( ) . encode( ) . len( ) as f64 / 1024f64 ,
@@ -574,7 +594,7 @@ where
574594 . wait_to_announce ( block_hash, pov_hash) ;
575595
576596 info ! (
577- target: "cumulus-collator" ,
597+ target: LOG_TARGET ,
578598 "Produced proof-of-validity candidate {:?} from block {:?}." ,
579599 pov_hash,
580600 block_hash,
0 commit comments