@@ -40,6 +40,7 @@ use cumulus_client_consensus_proposer::ProposerInterface;
4040use cumulus_primitives_core:: {
4141 relay_chain:: Hash as PHash , CollectCollationInfo , PersistedValidationData ,
4242} ;
43+ use cumulus_primitives_aura:: AuraUnincludedSegmentApi ;
4344use cumulus_relay_chain_interface:: RelayChainInterface ;
4445
4546use polkadot_overseer:: Handle as OverseerHandle ;
@@ -95,7 +96,7 @@ pub async fn run<Block, P, BI, CIDP, Client, Backend, RClient, SO, Proposer, CS>
9596 + Send
9697 + Sync
9798 + ' static ,
98- Client :: Api : AuraApi < Block , P :: Public > + CollectCollationInfo < Block > ,
99+ Client :: Api : AuraApi < Block , P :: Public > + CollectCollationInfo < Block > + AuraUnincludedSegmentApi < Block > ,
99100 Backend : sp_blockchain:: Backend < Block > ,
100101 RClient : RelayChainInterface ,
101102 CIDP : CreateInherentDataProviders < Block , ( ) > + ' static ,
@@ -307,24 +308,28 @@ pub async fn run<Block, P, BI, CIDP, Client, Backend, RClient, SO, Proposer, CS>
307308async fn can_build_upon < Block : BlockT , Client , P > (
308309 slot : Slot ,
309310 timestamp : Timestamp ,
310- block_hash : Block :: Hash ,
311+ parent_hash : Block :: Hash ,
311312 included_block : Block :: Hash ,
312313 client : & Client ,
313314 keystore : & KeystorePtr ,
314315) -> Option < SlotClaim < P :: Public > >
315316where
316317 Client : ProvideRuntimeApi < Block > ,
317- Client :: Api : AuraApi < Block , P :: Public > ,
318+ Client :: Api : AuraApi < Block , P :: Public > + AuraUnincludedSegmentApi < Block > ,
318319 P : Pair ,
319320 P :: Public : Encode + Decode ,
320321 P :: Signature : Encode + Decode ,
321322{
322- let authorities = client. runtime_api ( ) . authorities ( block_hash) . ok ( ) ?;
323+ let runtime_api = client. runtime_api ( ) ;
324+ let authorities = runtime_api. authorities ( parent_hash) . ok ( ) ?;
323325 let author_pub = aura_internal:: claim_slot :: < P > ( slot, & authorities, keystore) . await ?;
324326
325- // TODO [now]: new runtime API,
326- // AuraUnincludedSegmentApi::has_space(included_block, slot) or something like it.
327- unimplemented ! ( ) ;
327+ // Here we lean on the property that building on an empty unincluded segment must always
328+ // be legal. Skipping the runtime API query here allows us to seamlessly run this
329+ // collator against chains which have not yet upgraded their runtime.
330+ if parent_hash != included_block {
331+ runtime_api. can_build_upon ( parent_hash, included_block, slot) . ok ( ) ?;
332+ }
328333
329334 Some ( SlotClaim :: unchecked :: < P > ( author_pub, slot, timestamp) )
330335}
0 commit comments