Skip to content

Commit

Permalink
Pass relay_parent hash to produce_candidate (paritytech#300)
Browse files Browse the repository at this point in the history
* Pass `relay_parent` hash to `produce_candidate`

* Fixes compilation
  • Loading branch information
bkchr authored and rphmeier committed Jun 25, 2019
1 parent 40f1065 commit d6fa479
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ impl<R: fmt::Display> fmt::Display for Error<R> {
pub trait ParachainContext: Clone {
type ProduceCandidate: IntoFuture<Item=(BlockData, HeadData, Extrinsic), Error=InvalidHead>;

/// Produce a candidate, given the latest ingress queue information and the last parachain head.
/// Produce a candidate, given the relay parent hash, the latest ingress queue information
/// and the last parachain head.
fn produce_candidate<I: IntoIterator<Item=(ParaId, Message)>>(
&self,
relay_parent: Hash,
last_head: HeadData,
ingress: I,
) -> Self::ProduceCandidate;
Expand All @@ -124,6 +126,7 @@ pub trait RelayChainContext {

/// Produce a candidate for the parachain, with given contexts, parent head, and signing key.
pub fn collate<'a, R, P>(
relay_parent: Hash,
local_id: ParaId,
last_head: HeadData,
relay_context: R,
Expand All @@ -142,6 +145,7 @@ pub fn collate<'a, R, P>(
ingress
.and_then(move |ingress| {
para_context.produce_candidate(
relay_parent,
last_head,
ingress.0.iter().flat_map(|&(id, ref msgs)| msgs.iter().cloned().map(move |msg| (id, msg)))
)
Expand Down Expand Up @@ -327,6 +331,7 @@ impl<P, E> Worker for CollationNode<P, E> where
};

let collation_work = collate(
relay_parent,
para_id,
HeadData(last_head),
context,
Expand Down Expand Up @@ -427,6 +432,7 @@ mod tests {

fn produce_candidate<I: IntoIterator<Item=(ParaId, Message)>>(
&self,
_relay_parent: Hash,
_last_head: HeadData,
ingress: I,
) -> Result<(BlockData, HeadData, Extrinsic), InvalidHead> {
Expand Down Expand Up @@ -476,6 +482,7 @@ mod tests {
]));

let collation = collate(
Default::default(),
id,
HeadData(vec![5]),
context.clone(),
Expand Down
3 changes: 2 additions & 1 deletion test-parachains/adder/collator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::sync::Arc;
use adder::{HeadData as AdderHead, BlockData as AdderBody};
use substrate_primitives::Pair;
use parachain::codec::{Encode, Decode};
use primitives::parachain::{HeadData, BlockData, Id as ParaId, Message, Extrinsic};
use primitives::{Hash, parachain::{HeadData, BlockData, Id as ParaId, Message, Extrinsic}};
use collator::{InvalidHead, ParachainContext, VersionInfo};
use parking_lot::Mutex;

Expand All @@ -49,6 +49,7 @@ impl ParachainContext for AdderContext {

fn produce_candidate<I: IntoIterator<Item=(ParaId, Message)>>(
&self,
_relay_parent: Hash,
last_head: HeadData,
ingress: I,
) -> Result<(BlockData, HeadData, Extrinsic), InvalidHead>
Expand Down

0 comments on commit d6fa479

Please sign in to comment.