@@ -50,7 +50,7 @@ use std::sync::Arc;
5050use std:: time:: Duration ;
5151use std:: pin:: Pin ;
5252
53- use futures:: { future, Future , Stream , FutureExt , TryFutureExt , StreamExt , task:: Spawn } ;
53+ use futures:: { future, Future , Stream , FutureExt , StreamExt , task:: Spawn } ;
5454use log:: warn;
5555use sc_client_api:: { StateBackend , BlockchainEvents } ;
5656use sp_blockchain:: HeaderBackend ;
@@ -100,24 +100,17 @@ impl Network for polkadot_network::protocol::Service {
100100 }
101101}
102102
103- /// Error to return when the head data was invalid.
104- #[ derive( Clone , Copy , Debug ) ]
105- pub struct InvalidHead ;
106-
107103/// Collation errors.
108104#[ derive( Debug ) ]
109105pub enum Error {
110106 /// Error on the relay-chain side of things.
111107 Polkadot ( String ) ,
112- /// Error on the collator side of things.
113- Collator ( InvalidHead ) ,
114108}
115109
116110impl fmt:: Display for Error {
117111 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
118112 match * self {
119113 Error :: Polkadot ( ref err) => write ! ( f, "Polkadot node error: {}" , err) ,
120- Error :: Collator ( _) => write ! ( f, "Collator node error: Invalid head data" ) ,
121114 }
122115 }
123116}
@@ -147,7 +140,7 @@ pub trait BuildParachainContext {
147140/// This can be implemented through an externally attached service or a stub.
148141/// This is expected to be a lightweight, shared type like an Arc.
149142pub trait ParachainContext : Clone {
150- type ProduceCandidate : Future < Output = Result < ( BlockData , HeadData ) , InvalidHead > > ;
143+ type ProduceCandidate : Future < Output = Option < ( BlockData , HeadData ) > > ;
151144
152145 /// Produce a candidate, given the relay parent hash, the latest ingress queue information
153146 /// and the last parachain head.
@@ -167,8 +160,7 @@ pub async fn collate<P>(
167160 local_validation_data : LocalValidationData ,
168161 mut para_context : P ,
169162 key : Arc < CollatorPair > ,
170- )
171- -> Result < parachain:: Collation , Error >
163+ ) -> Option < parachain:: Collation >
172164 where
173165 P : ParachainContext ,
174166 P :: ProduceCandidate : Send ,
@@ -177,7 +169,7 @@ pub async fn collate<P>(
177169 relay_parent,
178170 global_validation,
179171 local_validation_data,
180- ) . map_err ( Error :: Collator ) . await ?;
172+ ) . await ?;
181173
182174 let pov_block = PoVBlock {
183175 block_data,
@@ -204,7 +196,7 @@ pub async fn collate<P>(
204196 pov : pov_block,
205197 } ;
206198
207- Ok ( collation)
199+ Some ( collation)
208200}
209201
210202#[ cfg( feature = "service-rewr" ) ]
@@ -341,8 +333,13 @@ fn build_collator_service<SP, P, C, R, Extrinsic>(
341333 local_validation,
342334 parachain_context,
343335 key,
344- ) . map_ok ( move |collation| {
345- network. distribute_collation ( targets, collation)
336+ ) . map ( move |collation| {
337+ match collation {
338+ Some ( collation) => network. distribute_collation ( targets, collation) ,
339+ None => log:: trace!( "Skipping collation as `collate` returned `None`" ) ,
340+ }
341+
342+ Ok ( ( ) )
346343 } ) ;
347344
348345 future:: Either :: Right ( collation_work)
@@ -376,7 +373,6 @@ pub async fn start_collator<P>(
376373 para_id : ParaId ,
377374 key : Arc < CollatorPair > ,
378375 config : Configuration ,
379- informant_prefix : Option < String > ,
380376) -> Result < ( ) , polkadot_service:: Error >
381377where
382378 P : ' static + BuildParachainContext ,
@@ -397,7 +393,6 @@ where
397393 false ,
398394 6000 ,
399395 None ,
400- informant_prefix,
401396 ) ?;
402397 let spawn_handle = service. spawn_task_handle ( ) ;
403398 build_collator_service (
@@ -416,7 +411,6 @@ where
416411 false ,
417412 6000 ,
418413 None ,
419- informant_prefix,
420414 ) ?;
421415 let spawn_handle = service. spawn_task_handle ( ) ;
422416 build_collator_service (
@@ -435,7 +429,6 @@ where
435429 false ,
436430 6000 ,
437431 None ,
438- informant_prefix,
439432 ) ?;
440433 let spawn_handle = service. spawn_task_handle ( ) ;
441434 build_collator_service (
@@ -470,7 +463,7 @@ mod tests {
470463 struct DummyParachainContext ;
471464
472465 impl ParachainContext for DummyParachainContext {
473- type ProduceCandidate = future:: Ready < Result < ( BlockData , HeadData ) , InvalidHead > > ;
466+ type ProduceCandidate = future:: Ready < Option < ( BlockData , HeadData ) > > ;
474467
475468 fn produce_candidate (
476469 & mut self ,
@@ -479,10 +472,10 @@ mod tests {
479472 _local_validation : LocalValidationData ,
480473 ) -> Self :: ProduceCandidate {
481474 // send messages right back.
482- future:: ok ( (
475+ future:: ready ( Some ( (
483476 BlockData ( vec ! [ 1 , 2 , 3 , 4 , 5 , ] ) ,
484477 HeadData ( vec ! [ 9 , 9 , 9 ] ) ,
485- ) )
478+ ) ) )
486479 }
487480 }
488481
@@ -501,21 +494,20 @@ mod tests {
501494 }
502495 }
503496
504- // Make sure that the future returned by `start_collator` implementes `Send`.
497+ // Make sure that the future returned by `start_collator` implements `Send`.
505498 #[ test]
506499 fn start_collator_is_send ( ) {
507500 fn check_send < T : Send > ( _: T ) { }
508501
509502 let cli = Cli :: from_iter ( & [ "-dev" ] ) ;
510- let task_executor = Arc :: new ( |_, _| unimplemented ! ( ) ) ;
511- let config = cli. create_configuration ( & cli. run . base , task_executor) . unwrap ( ) ;
503+ let task_executor = |_, _| unimplemented ! ( ) ;
504+ let config = cli. create_configuration ( & cli. run . base , task_executor. into ( ) ) . unwrap ( ) ;
512505
513506 check_send ( start_collator (
514507 BuildDummyParachainContext ,
515508 0 . into ( ) ,
516509 Arc :: new ( CollatorPair :: generate ( ) . 0 ) ,
517510 config,
518- None ,
519511 ) ) ;
520512 }
521513}
0 commit comments