2424
2525use codec:: { Decode , Encode } ;
2626use cumulus_client_collator:: service:: ServiceInterface as CollatorServiceInterface ;
27- use cumulus_client_consensus_common:: { ParachainBlockImportMarker , ParachainCandidate } ;
27+ use cumulus_client_consensus_common:: { ParachainBlockImportMarker , ParachainCandidate , ParentSearchParams } ;
2828use cumulus_client_consensus_proposer:: ProposerInterface ;
2929use cumulus_primitives_core:: {
3030 relay_chain:: Hash as PHash , CollectCollationInfo , PersistedValidationData ,
@@ -103,8 +103,7 @@ pub async fn run_async_backing_driven<Block, P, BI, CIDP, Client, RClient, SO, P
103103 P :: Public : AppPublic + Hash + Member + Encode + Decode ,
104104 P :: Signature : TryFrom < Vec < u8 > > + Hash + Member + Encode + Decode ,
105105{
106- let mut proposer = params. proposer ;
107- let mut block_import = params. block_import ;
106+ let mut params = params;
108107
109108 let mut import_notifications = match params. relay_client . import_notification_stream ( ) . await {
110109 Ok ( s) => s,
@@ -121,9 +120,72 @@ pub async fn run_async_backing_driven<Block, P, BI, CIDP, Client, RClient, SO, P
121120
122121 while let Some ( relay_parent_header) = import_notifications. next ( ) . await {
123122 let relay_parent = relay_parent_header. hash ( ) ;
123+
124+ // TODO [now]: get asynchronous backing parameters from the relay-chain
125+ // runtime.
126+
127+ let parent_search_params = ParentSearchParams {
128+ relay_parent,
129+ para_id : params. para_id ,
130+ ancestry_lookback : unimplemented ! ( ) ,
131+ max_depth : unimplemented ! ( ) , // max unincluded segment len
132+ ignore_alternative_branches : true ,
133+ } ;
134+
135+ // TODO [now]: remove this in favor of one passed in as a parameter.
136+ let fake_hack: sc_client_api:: in_mem:: Blockchain :: < Block > = unimplemented!( ) ;
137+
138+ let potential_parents = cumulus_client_consensus_common:: find_potential_parents :: < Block > (
139+ parent_search_params,
140+ & fake_hack, // sp_blockchain::Backend
141+ & params. relay_client ,
142+ ) . await ;
143+
144+ let mut potential_parents = match potential_parents {
145+ Err ( e) => {
146+ tracing:: error!(
147+ target: crate :: LOG_TARGET ,
148+ ?relay_parent,
149+ err = ?e,
150+ "Could not fetch potential parents to build upon"
151+ ) ;
152+
153+ continue ;
154+ }
155+ Ok ( x) => x,
156+ } ;
157+
158+ // Sort by depth, descending, to choose the longest chain, and lazily filter
159+ // by those with space.
160+ potential_parents. sort_by ( |a, b| b. depth . cmp ( & a. depth ) ) ;
161+ let potential_parents = potential_parents
162+ . into_iter ( )
163+ . filter ( |p| can_build_upon ( p. hash , & * params. para_client ) ) ;
164+
165+ if let Some ( parent) = potential_parents. next ( ) {
166+ // TODO [now]: build and announce collations recursively until
167+ // `can_build_upon` fails.
168+ unimplemented ! ( )
169+ }
124170 }
125171}
126172
173+ fn can_build_upon < Block : BlockT , Client > (
174+ block_hash : Block :: Hash ,
175+ client : & Client ,
176+ ) -> bool where
177+ Client : ProvideRuntimeApi < Block >
178+ {
179+ // TODO [now]: claim slot, maybe with an authorities cache to avoid
180+ // all validators doing this every new relay-chain block.
181+ // Actually, as long as sessions are based on slot number then they should
182+ // be the same for all...
183+ //
184+ // TODO [now]: new runtime API,
185+ // AuraUnincludedSegmentApi::has_space(slot) or something like it.
186+ unimplemented ! ( )
187+ }
188+
127189/// Run bare Aura consensus as a relay-chain-driven collator.
128190pub async fn run_bare_relay_driven < Block , P , BI , CIDP , Client , RClient , SO , Proposer , CS > (
129191 params : Params < BI , CIDP , Client , RClient , SO , Proposer , CS > ,
@@ -149,8 +211,7 @@ pub async fn run_bare_relay_driven<Block, P, BI, CIDP, Client, RClient, SO, Prop
149211 P :: Public : AppPublic + Hash + Member + Encode + Decode ,
150212 P :: Signature : TryFrom < Vec < u8 > > + Hash + Member + Encode + Decode ,
151213{
152- let mut proposer = params. proposer ;
153- let mut block_import = params. block_import ;
214+ let mut params = params;
154215
155216 let mut collation_requests = cumulus_client_collator:: relay_chain_driven:: init (
156217 params. key ,
@@ -223,7 +284,7 @@ pub async fn run_bare_relay_driven<Block, P, BI, CIDP, Client, RClient, SO, Prop
223284 ) ;
224285
225286 let proposal = try_request ! (
226- proposer
287+ params . proposer
227288 . propose(
228289 & parent_header,
229290 & parachain_inherent_data,
@@ -259,7 +320,7 @@ pub async fn run_bare_relay_driven<Block, P, BI, CIDP, Client, RClient, SO, Prop
259320 . clone ( ) ,
260321 ) ;
261322
262- try_request ! ( block_import. import_block( sealed_importable) . await ) ;
323+ try_request ! ( params . block_import. import_block( sealed_importable) . await ) ;
263324
264325 let response = if let Some ( ( collation, b) ) = params. collator_service . build_collation (
265326 & parent_header,
0 commit comments