@@ -98,12 +98,14 @@ impl<R: fmt::Display> fmt::Display for Error<R> {
98
98
/// This can be implemented through an externally attached service or a stub.
99
99
/// This is expected to be a lightweight, shared type like an Arc.
100
100
pub trait ParachainContext : Clone {
101
+ type ProduceCandidate : IntoFuture < Item =( BlockData , HeadData , Extrinsic ) , Error =InvalidHead > ;
102
+
101
103
/// Produce a candidate, given the latest ingress queue information and the last parachain head.
102
104
fn produce_candidate < I : IntoIterator < Item =( ParaId , Message ) > > (
103
105
& self ,
104
106
last_head : HeadData ,
105
107
ingress : I ,
106
- ) -> Result < ( BlockData , HeadData , Extrinsic ) , InvalidHead > ;
108
+ ) -> Self :: ProduceCandidate ;
107
109
}
108
110
109
111
/// Relay chain context needed to collate.
@@ -134,38 +136,44 @@ pub fn collate<'a, R, P>(
134
136
R :: Error : ' a ,
135
137
R :: FutureEgress : ' a ,
136
138
P : ParachainContext + ' a ,
139
+ <P :: ProduceCandidate as IntoFuture >:: Future : Send ,
137
140
{
138
141
let ingress = relay_context. unrouted_egress ( local_id) . into_future ( ) . map_err ( Error :: Polkadot ) ;
139
- ingress. and_then ( move |ingress| {
140
- let ( block_data, head_data, mut extrinsic) = para_context. produce_candidate (
141
- last_head,
142
- ingress. 0 . iter ( ) . flat_map ( |& ( id, ref msgs) | msgs. iter ( ) . cloned ( ) . map ( move |msg| ( id, msg) ) )
143
- ) . map_err ( Error :: Collator ) ?;
144
-
145
- let block_data_hash = block_data. hash ( ) ;
146
- let signature = key. sign ( block_data_hash. as_ref ( ) ) . into ( ) ;
147
- let egress_queue_roots =
148
- :: polkadot_validation:: egress_roots ( & mut extrinsic. outgoing_messages ) ;
149
-
150
- let receipt = parachain:: CandidateReceipt {
151
- parachain_index : local_id,
152
- collator : key. public ( ) ,
153
- signature,
154
- head_data,
155
- egress_queue_roots,
156
- fees : 0 ,
157
- block_data_hash,
158
- upward_messages : Vec :: new ( ) ,
159
- } ;
160
-
161
- Ok ( parachain:: Collation {
162
- receipt,
163
- pov : PoVBlock {
164
- block_data,
165
- ingress,
166
- } ,
142
+ ingress
143
+ . and_then ( move |ingress| {
144
+ para_context. produce_candidate (
145
+ last_head,
146
+ ingress. 0 . iter ( ) . flat_map ( |& ( id, ref msgs) | msgs. iter ( ) . cloned ( ) . map ( move |msg| ( id, msg) ) )
147
+ )
148
+ . into_future ( )
149
+ . map ( move |x| ( ingress, x) )
150
+ . map_err ( Error :: Collator )
151
+ } )
152
+ . and_then ( move |( ingress, ( block_data, head_data, mut extrinsic) ) | {
153
+ let block_data_hash = block_data. hash ( ) ;
154
+ let signature = key. sign ( block_data_hash. as_ref ( ) ) . into ( ) ;
155
+ let egress_queue_roots =
156
+ polkadot_validation:: egress_roots ( & mut extrinsic. outgoing_messages ) ;
157
+
158
+ let receipt = parachain:: CandidateReceipt {
159
+ parachain_index : local_id,
160
+ collator : key. public ( ) ,
161
+ signature,
162
+ head_data,
163
+ egress_queue_roots,
164
+ fees : 0 ,
165
+ block_data_hash,
166
+ upward_messages : Vec :: new ( ) ,
167
+ } ;
168
+
169
+ Ok ( parachain:: Collation {
170
+ receipt,
171
+ pov : PoVBlock {
172
+ block_data,
173
+ ingress,
174
+ } ,
175
+ } )
167
176
} )
168
- } )
169
177
}
170
178
171
179
/// Polkadot-api context.
@@ -216,7 +224,8 @@ impl<P, E> IntoExit for CollationNode<P, E> where
216
224
217
225
impl < P , E > Worker for CollationNode < P , E > where
218
226
P : ParachainContext + Send + ' static ,
219
- E : Future < Item =( ) , Error =( ) > + Clone + Send + Sync + ' static
227
+ E : Future < Item =( ) , Error =( ) > + Clone + Send + Sync + ' static ,
228
+ <P :: ProduceCandidate as IntoFuture >:: Future : Send + ' static ,
220
229
{
221
230
type Work = Box < Future < Item =( ) , Error =( ) > + Send > ;
222
231
@@ -376,6 +385,7 @@ pub fn run_collator<P, E, I, ArgT>(
376
385
version : VersionInfo ,
377
386
) -> polkadot_cli:: error:: Result < ( ) > where
378
387
P : ParachainContext + Send + ' static ,
388
+ <P :: ProduceCandidate as IntoFuture >:: Future : Send + ' static ,
379
389
E : IntoFuture < Item =( ) , Error =( ) > ,
380
390
E :: Future : Send + Clone + Sync + ' static ,
381
391
I : IntoIterator < Item =ArgT > ,
@@ -413,6 +423,8 @@ mod tests {
413
423
struct DummyParachainContext ;
414
424
415
425
impl ParachainContext for DummyParachainContext {
426
+ type ProduceCandidate = Result < ( BlockData , HeadData , Extrinsic ) , InvalidHead > ;
427
+
416
428
fn produce_candidate < I : IntoIterator < Item =( ParaId , Message ) > > (
417
429
& self ,
418
430
_last_head : HeadData ,
0 commit comments