mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
Strip out old XCMP primitives (#823)
* WIP * WIp * Mostly get tests to compile * Fix adder collator * Remove more stuff * Revert some changes to av store * Fix av store tests * Nitpicks * Restore some things * Small changes * Remvoe unused error variants
This commit is contained in:
@@ -24,8 +24,8 @@ use std::sync::Arc;
|
||||
use polkadot_primitives::{
|
||||
BlakeTwo256, Block, Hash, HashT, BlockId, Balance,
|
||||
parachain::{
|
||||
CollatorId, ConsolidatedIngress, StructuredUnroutedIngress, CandidateReceipt, CollationInfo,
|
||||
ParachainHost, Id as ParaId, Collation, OutgoingMessages, FeeSchedule, ErasureChunk,
|
||||
CollatorId, CandidateReceipt, CollationInfo,
|
||||
ParachainHost, Id as ParaId, Collation, FeeSchedule, ErasureChunk,
|
||||
HeadData, PoVBlock,
|
||||
},
|
||||
};
|
||||
@@ -71,7 +71,7 @@ pub async fn collation_fetch<C: Collators, P>(
|
||||
collators: C,
|
||||
client: Arc<P>,
|
||||
max_block_data_size: Option<u64>,
|
||||
) -> Result<(Collation, OutgoingMessages, HeadData, Balance),C::Error>
|
||||
) -> Result<(Collation, HeadData, Balance),C::Error>
|
||||
where
|
||||
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
|
||||
C: Collators + Unpin,
|
||||
@@ -92,8 +92,8 @@ pub async fn collation_fetch<C: Collators, P>(
|
||||
);
|
||||
|
||||
match res {
|
||||
Ok((messages, parent_head, fees)) => {
|
||||
return Ok((collation, messages, parent_head, fees))
|
||||
Ok((parent_head, fees)) => {
|
||||
return Ok((collation, parent_head, fees))
|
||||
}
|
||||
Err(e) => {
|
||||
debug!("Failed to validate parachain due to API error: {}", e);
|
||||
@@ -199,59 +199,6 @@ pub fn egress_roots(outgoing: &mut [TargetedMessage]) -> Vec<(ParaId, Hash)> {
|
||||
egress_roots
|
||||
}
|
||||
|
||||
fn check_egress(
|
||||
mut outgoing: Vec<TargetedMessage>,
|
||||
expected_egress_roots: &[(ParaId, Hash)],
|
||||
) -> Result<OutgoingMessages, Error> {
|
||||
// stable sort messages by parachain ID.
|
||||
outgoing.sort_by_key(|msg| ParaId::from(msg.target));
|
||||
|
||||
{
|
||||
let mut messages_iter = outgoing.iter().peekable();
|
||||
let mut expected_egress_roots = expected_egress_roots.iter();
|
||||
while let Some(batch_target) = messages_iter.peek().map(|o| o.target) {
|
||||
let expected_root = match expected_egress_roots.next() {
|
||||
None => return Err(Error::MissingEgressRoot {
|
||||
expected: Some(batch_target),
|
||||
got: None
|
||||
}),
|
||||
Some(&(id, ref root)) => if id == batch_target {
|
||||
root
|
||||
} else {
|
||||
return Err(Error::MissingEgressRoot{
|
||||
expected: Some(batch_target),
|
||||
got: Some(id)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// we borrow the iterator mutably to ensure it advances so the
|
||||
// next iteration of the loop starts with `messages_iter` pointing to
|
||||
// the next batch.
|
||||
let messages_to = messages_iter
|
||||
.clone()
|
||||
.take_while(|o| o.target == batch_target)
|
||||
.map(|o| { let _ = messages_iter.next(); &o.data[..] });
|
||||
|
||||
let computed_root = message_queue_root(messages_to);
|
||||
if &computed_root != expected_root {
|
||||
return Err(Error::EgressRootMismatch {
|
||||
id: batch_target,
|
||||
expected: expected_root.clone(),
|
||||
got: computed_root,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// also check that there are no more additional expected roots.
|
||||
if let Some((next_target, _)) = expected_egress_roots.next() {
|
||||
return Err(Error::MissingEgressRoot { expected: None, got: Some(*next_target) });
|
||||
}
|
||||
}
|
||||
|
||||
Ok(OutgoingMessages { outgoing_messages: outgoing })
|
||||
}
|
||||
|
||||
struct ExternalitiesInner {
|
||||
parachain_index: ParaId,
|
||||
outgoing: Vec<TargetedMessage>,
|
||||
@@ -309,9 +256,8 @@ impl ExternalitiesInner {
|
||||
fn final_checks(
|
||||
&mut self,
|
||||
upward_messages: &[UpwardMessage],
|
||||
egress_queue_roots: &[(ParaId, Hash)],
|
||||
fees_charged: Option<Balance>,
|
||||
) -> Result<(OutgoingMessages, Balance), Error> {
|
||||
) -> Result<Balance, Error> {
|
||||
if self.upward != upward_messages {
|
||||
return Err(Error::UpwardMessagesInvalid {
|
||||
expected: upward_messages.to_vec(),
|
||||
@@ -328,12 +274,8 @@ impl ExternalitiesInner {
|
||||
}
|
||||
}
|
||||
|
||||
let messages = check_egress(
|
||||
std::mem::replace(&mut self.outgoing, Vec::new()),
|
||||
&egress_queue_roots[..],
|
||||
)?;
|
||||
|
||||
Ok((messages, self.fees_charged))
|
||||
Ok(self.fees_charged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,40 +318,6 @@ pub fn validate_chunk(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validate incoming messages against expected roots.
|
||||
pub fn validate_incoming(
|
||||
roots: &StructuredUnroutedIngress,
|
||||
ingress: &ConsolidatedIngress,
|
||||
) -> Result<(), Error> {
|
||||
if roots.len() != ingress.0.len() {
|
||||
return Err(Error::IngressCanonicalityMismatch {
|
||||
expected: roots.0.len(),
|
||||
got: ingress.0.len()
|
||||
});
|
||||
}
|
||||
|
||||
let all_iter = roots.iter().zip(&ingress.0);
|
||||
for ((_, expected_from, root), (got_id, messages)) in all_iter {
|
||||
if expected_from != got_id {
|
||||
return Err(Error::IngressChainMismatch {
|
||||
expected: *expected_from,
|
||||
got: *got_id
|
||||
});
|
||||
}
|
||||
|
||||
let got_root = message_queue_root(messages.iter().map(|msg| &msg.0[..]));
|
||||
if &got_root != root {
|
||||
return Err(Error::IngressRootMismatch{
|
||||
id: *expected_from,
|
||||
expected: *root,
|
||||
got: got_root
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// A utility function that implements most of the collation validation logic.
|
||||
//
|
||||
// Reused by `validate_collation` and `validate_receipt`.
|
||||
@@ -422,13 +330,12 @@ fn do_validation<P>(
|
||||
max_block_data_size: Option<u64>,
|
||||
fees_charged: Option<Balance>,
|
||||
head_data: &HeadData,
|
||||
queue_roots: &Vec<(ParaId, Hash)>,
|
||||
upward_messages: &Vec<UpwardMessage>,
|
||||
) -> Result<(OutgoingMessages, HeadData, Balance), Error> where
|
||||
) -> Result<(HeadData, Balance), Error> where
|
||||
P: ProvideRuntimeApi<Block>,
|
||||
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
|
||||
{
|
||||
use parachain::{IncomingMessage, ValidationParams};
|
||||
use parachain::ValidationParams;
|
||||
|
||||
if let Some(max_size) = max_block_data_size {
|
||||
let block_data_size = pov_block.block_data.0.len() as u64;
|
||||
@@ -444,22 +351,10 @@ fn do_validation<P>(
|
||||
let chain_status = api.parachain_status(relay_parent, para_id)?
|
||||
.ok_or_else(|| Error::InactiveParachain(para_id))?;
|
||||
|
||||
let roots = api.ingress(relay_parent, para_id, None)?
|
||||
.ok_or_else(|| Error::InactiveParachain(para_id))?;
|
||||
|
||||
validate_incoming(&roots, &pov_block.ingress)?;
|
||||
|
||||
let params = ValidationParams {
|
||||
parent_head: chain_status.head_data.0.clone(),
|
||||
block_data: pov_block.block_data.0.clone(),
|
||||
ingress: pov_block.ingress.0.iter()
|
||||
.flat_map(|&(source, ref messages)| {
|
||||
messages.iter().map(move |msg| IncomingMessage {
|
||||
source,
|
||||
data: msg.0.clone(),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
|
||||
let ext = Externalities::new(para_id.clone(), chain_status.balance, chain_status.fee_schedule);
|
||||
@@ -472,13 +367,12 @@ fn do_validation<P>(
|
||||
) {
|
||||
Ok(result) => {
|
||||
if result.head_data == head_data.0 {
|
||||
let (messages, fees) = ext.0.lock().final_checks(
|
||||
let fees = ext.0.lock().final_checks(
|
||||
upward_messages,
|
||||
queue_roots,
|
||||
fees_charged
|
||||
)?;
|
||||
|
||||
Ok((messages, chain_status.head_data, fees))
|
||||
Ok((chain_status.head_data, fees))
|
||||
} else {
|
||||
Err(Error::WrongHeadData {
|
||||
expected: head_data.0.clone(),
|
||||
@@ -500,7 +394,6 @@ pub fn produce_receipt_and_chunks(
|
||||
n_validators: usize,
|
||||
parent_head: HeadData,
|
||||
pov: &PoVBlock,
|
||||
messages: &OutgoingMessages,
|
||||
fees: Balance,
|
||||
info: &CollationInfo,
|
||||
) -> Result<(CandidateReceipt, Vec<ErasureChunk>), Error>
|
||||
@@ -508,7 +401,6 @@ pub fn produce_receipt_and_chunks(
|
||||
let erasure_chunks = erasure::obtain_chunks(
|
||||
n_validators,
|
||||
&pov.block_data,
|
||||
Some(&messages.clone().into())
|
||||
)?;
|
||||
|
||||
let branches = erasure::branches(erasure_chunks.as_ref());
|
||||
@@ -532,7 +424,6 @@ pub fn produce_receipt_and_chunks(
|
||||
signature: info.signature.clone(),
|
||||
head_data: info.head_data.clone(),
|
||||
parent_head,
|
||||
egress_queue_roots: info.egress_queue_roots.clone(),
|
||||
fees,
|
||||
block_data_hash: info.block_data_hash.clone(),
|
||||
upward_messages: info.upward_messages.clone(),
|
||||
@@ -552,11 +443,11 @@ pub fn validate_receipt<P>(
|
||||
pov_block: &PoVBlock,
|
||||
receipt: &CandidateReceipt,
|
||||
max_block_data_size: Option<u64>,
|
||||
) -> Result<(OutgoingMessages, Vec<ErasureChunk>), Error> where
|
||||
) -> Result<Vec<ErasureChunk>, Error> where
|
||||
P: ProvideRuntimeApi<Block>,
|
||||
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
|
||||
{
|
||||
let (messages, parent_head, _fees) = do_validation(
|
||||
let (parent_head, _fees) = do_validation(
|
||||
client,
|
||||
relay_parent,
|
||||
pov_block,
|
||||
@@ -564,7 +455,6 @@ pub fn validate_receipt<P>(
|
||||
max_block_data_size,
|
||||
Some(receipt.fees),
|
||||
&receipt.head_data,
|
||||
&receipt.egress_queue_roots,
|
||||
&receipt.upward_messages,
|
||||
)?;
|
||||
|
||||
@@ -583,7 +473,6 @@ pub fn validate_receipt<P>(
|
||||
n_validators,
|
||||
parent_head,
|
||||
pov_block,
|
||||
&messages,
|
||||
receipt.fees,
|
||||
&receipt.clone().into(),
|
||||
)?;
|
||||
@@ -595,7 +484,7 @@ pub fn validate_receipt<P>(
|
||||
});
|
||||
}
|
||||
|
||||
Ok((messages, chunks))
|
||||
Ok(chunks)
|
||||
}
|
||||
|
||||
/// Check whether a given collation is valid. Returns `Ok` on success, error otherwise.
|
||||
@@ -608,7 +497,7 @@ pub fn validate_collation<P>(
|
||||
relay_parent: &BlockId,
|
||||
collation: &Collation,
|
||||
max_block_data_size: Option<u64>,
|
||||
) -> Result<(OutgoingMessages, HeadData, Balance), Error> where
|
||||
) -> Result<(HeadData, Balance), Error> where
|
||||
P: ProvideRuntimeApi<Block>,
|
||||
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
|
||||
{
|
||||
@@ -624,7 +513,6 @@ pub fn validate_collation<P>(
|
||||
max_block_data_size,
|
||||
None,
|
||||
&collation.info.head_data,
|
||||
&collation.info.egress_queue_roots,
|
||||
&collation.info.upward_messages,
|
||||
)
|
||||
}
|
||||
@@ -636,50 +524,6 @@ mod tests {
|
||||
use parachain::ParachainDispatchOrigin;
|
||||
use polkadot_primitives::parachain::{CandidateReceipt, HeadData};
|
||||
|
||||
#[test]
|
||||
fn compute_and_check_egress() {
|
||||
let messages = vec![
|
||||
TargetedMessage { target: 3.into(), data: vec![1, 1, 1] },
|
||||
TargetedMessage { target: 1.into(), data: vec![1, 2, 3] },
|
||||
TargetedMessage { target: 2.into(), data: vec![4, 5, 6] },
|
||||
TargetedMessage { target: 1.into(), data: vec![7, 8, 9] },
|
||||
];
|
||||
|
||||
let root_1 = message_queue_root(&[vec![1, 2, 3], vec![7, 8, 9]]);
|
||||
let root_2 = message_queue_root(&[vec![4, 5, 6]]);
|
||||
let root_3 = message_queue_root(&[vec![1, 1, 1]]);
|
||||
|
||||
assert!(check_egress(
|
||||
messages.clone(),
|
||||
&[(1.into(), root_1), (2.into(), root_2), (3.into(), root_3)],
|
||||
).is_ok());
|
||||
|
||||
let egress_roots = egress_roots(&mut messages.clone()[..]);
|
||||
|
||||
assert!(check_egress(
|
||||
messages.clone(),
|
||||
&egress_roots[..],
|
||||
).is_ok());
|
||||
|
||||
// missing root.
|
||||
assert!(check_egress(
|
||||
messages.clone(),
|
||||
&[(1.into(), root_1), (3.into(), root_3)],
|
||||
).is_err());
|
||||
|
||||
// extra root.
|
||||
assert!(check_egress(
|
||||
messages.clone(),
|
||||
&[(1.into(), root_1), (2.into(), root_2), (3.into(), root_3), (4.into(), Default::default())],
|
||||
).is_err());
|
||||
|
||||
// root mismatch.
|
||||
assert!(check_egress(
|
||||
messages.clone(),
|
||||
&[(1.into(), root_2), (2.into(), root_1), (3.into(), root_3)],
|
||||
).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_rejects_local_message() {
|
||||
let mut ext = ExternalitiesInner {
|
||||
@@ -719,7 +563,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(Vec::new()),
|
||||
parent_head: HeadData(Vec::new()),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 0,
|
||||
block_data_hash: Default::default(),
|
||||
upward_messages: vec![
|
||||
@@ -730,7 +573,6 @@ mod tests {
|
||||
};
|
||||
assert!(ext().final_checks(
|
||||
&receipt.upward_messages,
|
||||
&receipt.egress_queue_roots,
|
||||
Some(receipt.fees),
|
||||
).is_err());
|
||||
let receipt = CandidateReceipt {
|
||||
@@ -739,7 +581,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(Vec::new()),
|
||||
parent_head: HeadData(Vec::new()),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 0,
|
||||
block_data_hash: Default::default(),
|
||||
upward_messages: vec![
|
||||
@@ -749,7 +590,6 @@ mod tests {
|
||||
};
|
||||
assert!(ext().final_checks(
|
||||
&receipt.upward_messages,
|
||||
&receipt.egress_queue_roots,
|
||||
Some(receipt.fees),
|
||||
).is_err());
|
||||
let receipt = CandidateReceipt {
|
||||
@@ -758,7 +598,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(Vec::new()),
|
||||
parent_head: HeadData(Vec::new()),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 0,
|
||||
block_data_hash: Default::default(),
|
||||
upward_messages: vec![
|
||||
@@ -768,7 +607,6 @@ mod tests {
|
||||
};
|
||||
assert!(ext().final_checks(
|
||||
&receipt.upward_messages,
|
||||
&receipt.egress_queue_roots,
|
||||
Some(receipt.fees),
|
||||
).is_err());
|
||||
let receipt = CandidateReceipt {
|
||||
@@ -777,7 +615,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(Vec::new()),
|
||||
parent_head: HeadData(Vec::new()),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 0,
|
||||
block_data_hash: Default::default(),
|
||||
upward_messages: vec![
|
||||
@@ -787,7 +624,6 @@ mod tests {
|
||||
};
|
||||
assert!(ext().final_checks(
|
||||
&receipt.upward_messages,
|
||||
&receipt.egress_queue_roots,
|
||||
Some(receipt.fees),
|
||||
).is_ok());
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ use codec::Encode;
|
||||
use polkadot_primitives::Hash;
|
||||
use polkadot_primitives::parachain::{
|
||||
Id as ParaId, Chain, DutyRoster, CandidateReceipt,
|
||||
Statement as PrimitiveStatement, Message, OutgoingMessages,
|
||||
Statement as PrimitiveStatement,
|
||||
Collation, PoVBlock, ErasureChunk, ValidatorSignature, ValidatorIndex,
|
||||
ValidatorPair, ValidatorId,
|
||||
};
|
||||
@@ -48,7 +48,7 @@ use futures::prelude::*;
|
||||
|
||||
pub use self::block_production::ProposerFactory;
|
||||
pub use self::collation::{
|
||||
validate_collation, validate_incoming, message_queue_root, egress_roots, Collators,
|
||||
validate_collation, message_queue_root, egress_roots, Collators,
|
||||
produce_receipt_and_chunks,
|
||||
};
|
||||
pub use self::error::Error;
|
||||
@@ -70,9 +70,6 @@ pub mod collation;
|
||||
pub mod validation_service;
|
||||
pub mod block_production;
|
||||
|
||||
/// Incoming messages; a series of sorted (ParaId, Message) pairs.
|
||||
pub type Incoming = Vec<(ParaId, Vec<Message>)>;
|
||||
|
||||
/// A handle to a statement table router.
|
||||
///
|
||||
/// This is expected to be a lightweight, shared type like an `Arc`.
|
||||
@@ -92,7 +89,6 @@ pub trait TableRouter: Clone {
|
||||
&self,
|
||||
collation: Collation,
|
||||
receipt: CandidateReceipt,
|
||||
outgoing: OutgoingMessages,
|
||||
chunks: (ValidatorIndex, &[ErasureChunk]),
|
||||
) -> Self::SendLocalCollation;
|
||||
|
||||
@@ -218,18 +214,6 @@ pub fn make_group_info(
|
||||
|
||||
}
|
||||
|
||||
/// Compute the (target, root, messages) of all outgoing queues.
|
||||
pub fn outgoing_queues(outgoing_targeted: &'_ OutgoingMessages)
|
||||
-> impl Iterator<Item=(ParaId, Hash, Vec<Message>)> + '_
|
||||
{
|
||||
outgoing_targeted.message_queues().filter_map(|queue| {
|
||||
let target = queue.get(0)?.target;
|
||||
let queue_root = message_queue_root(queue);
|
||||
let queue_data = queue.iter().map(|msg| msg.clone().into()).collect();
|
||||
Some((target, queue_root, queue_data))
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -24,7 +24,7 @@ use availability_store::{Store as AvailabilityStore};
|
||||
use table::{self, Table, Context as TableContextTrait};
|
||||
use polkadot_primitives::{Block, BlockId, Hash};
|
||||
use polkadot_primitives::parachain::{
|
||||
Id as ParaId, OutgoingMessages, CandidateReceipt, ValidatorPair, ValidatorId,
|
||||
Id as ParaId, CandidateReceipt, ValidatorPair, ValidatorId,
|
||||
AttestedCandidate, ParachainHost, PoVBlock, ValidatorIndex, ErasureChunk,
|
||||
};
|
||||
|
||||
@@ -91,7 +91,7 @@ impl TableContext {
|
||||
}
|
||||
|
||||
pub(crate) enum Validation {
|
||||
Valid(PoVBlock, OutgoingMessages),
|
||||
Valid(PoVBlock),
|
||||
Invalid(PoVBlock), // should take proof.
|
||||
}
|
||||
|
||||
@@ -222,10 +222,10 @@ impl Validated {
|
||||
|
||||
/// Note that we've validated a candidate with given hash and it is good.
|
||||
/// outgoing message required.
|
||||
pub fn known_good(hash: Hash, collation: PoVBlock, outgoing: OutgoingMessages) -> Self {
|
||||
pub fn known_good(hash: Hash, collation: PoVBlock) -> Self {
|
||||
Validated {
|
||||
statement: GenericStatement::Valid(hash),
|
||||
result: Validation::Valid(collation, outgoing),
|
||||
result: Validation::Valid(collation),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,26 +234,17 @@ impl Validated {
|
||||
pub fn collated_local(
|
||||
receipt: CandidateReceipt,
|
||||
collation: PoVBlock,
|
||||
outgoing: OutgoingMessages,
|
||||
) -> Self {
|
||||
Validated {
|
||||
statement: GenericStatement::Candidate(receipt),
|
||||
result: Validation::Valid(collation, outgoing),
|
||||
result: Validation::Valid(collation),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a reference to the proof-of-validation block.
|
||||
pub fn pov_block(&self) -> &PoVBlock {
|
||||
match self.result {
|
||||
Validation::Valid(ref b, _) | Validation::Invalid(ref b) => b,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a reference to the outgoing messages data, if any.
|
||||
pub fn outgoing_messages(&self) -> Option<&OutgoingMessages> {
|
||||
match self.result {
|
||||
Validation::Valid(_, ref ex) => Some(ex),
|
||||
Validation::Invalid(_) => None,
|
||||
Validation::Valid(ref b) | Validation::Invalid(ref b) => b,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +264,7 @@ impl<Fetch: Future + Unpin> ParachainWork<Fetch> {
|
||||
pub fn prime<P: ProvideRuntimeApi<Block>>(self, api: Arc<P>)
|
||||
-> PrimedParachainWork<
|
||||
Fetch,
|
||||
impl Send + FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<(OutgoingMessages, ErasureChunk), ()> + Unpin,
|
||||
impl Send + FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<ErasureChunk, ()> + Unpin,
|
||||
>
|
||||
where
|
||||
P: Send + Sync + 'static,
|
||||
@@ -292,8 +283,8 @@ impl<Fetch: Future + Unpin> ParachainWork<Fetch> {
|
||||
);
|
||||
|
||||
match res {
|
||||
Ok((messages, mut chunks)) => {
|
||||
Ok((messages, chunks.swap_remove(local_index)))
|
||||
Ok(mut chunks) => {
|
||||
Ok(chunks.swap_remove(local_index))
|
||||
}
|
||||
Err(e) => {
|
||||
debug!(target: "validation", "Encountered bad collation: {}", e);
|
||||
@@ -307,7 +298,7 @@ impl<Fetch: Future + Unpin> ParachainWork<Fetch> {
|
||||
|
||||
/// Prime the parachain work with a custom validation function.
|
||||
pub fn prime_with<F>(self, validate: F) -> PrimedParachainWork<Fetch, F>
|
||||
where F: FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<(OutgoingMessages, ErasureChunk), ()>
|
||||
where F: FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<ErasureChunk, ()>
|
||||
{
|
||||
PrimedParachainWork { inner: self, validate }
|
||||
}
|
||||
@@ -327,7 +318,7 @@ pub struct PrimedParachainWork<Fetch, F> {
|
||||
impl<Fetch, F, Err> PrimedParachainWork<Fetch, F>
|
||||
where
|
||||
Fetch: Future<Output=Result<PoVBlock,Err>> + Unpin,
|
||||
F: FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<(OutgoingMessages, ErasureChunk), ()> + Unpin,
|
||||
F: FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<ErasureChunk, ()> + Unpin,
|
||||
Err: From<::std::io::Error>,
|
||||
{
|
||||
pub async fn validate(mut self) -> Result<(Validated, Option<ErasureChunk>), Err> {
|
||||
@@ -353,7 +344,7 @@ impl<Fetch, F, Err> PrimedParachainWork<Fetch, F>
|
||||
},
|
||||
None,
|
||||
)),
|
||||
Ok((outgoing_targeted, our_chunk)) => {
|
||||
Ok(our_chunk) => {
|
||||
self.inner.availability_store.add_erasure_chunk(
|
||||
self.inner.relay_parent,
|
||||
candidate.clone(),
|
||||
@@ -363,7 +354,7 @@ impl<Fetch, F, Err> PrimedParachainWork<Fetch, F>
|
||||
Ok((
|
||||
Validated {
|
||||
statement: GenericStatement::Valid(candidate_hash),
|
||||
result: Validation::Valid(pov_block, outgoing_targeted),
|
||||
result: Validation::Valid(pov_block),
|
||||
},
|
||||
Some(our_chunk),
|
||||
))
|
||||
@@ -580,9 +571,7 @@ mod tests {
|
||||
use super::*;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use primitives::crypto::UncheckedInto;
|
||||
use polkadot_primitives::parachain::{
|
||||
AvailableMessages, BlockData, ConsolidatedIngress, Collation, HeadData,
|
||||
};
|
||||
use polkadot_primitives::parachain::{BlockData, Collation, HeadData};
|
||||
use polkadot_erasure_coding::{self as erasure};
|
||||
use availability_store::ProvideGossipMessages;
|
||||
use futures::future;
|
||||
@@ -592,7 +581,6 @@ mod tests {
|
||||
fn pov_block_with_data(data: Vec<u8>) -> PoVBlock {
|
||||
PoVBlock {
|
||||
block_data: BlockData(data),
|
||||
ingress: ConsolidatedIngress(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,7 +615,6 @@ mod tests {
|
||||
&self,
|
||||
_collation: Collation,
|
||||
_candidate: CandidateReceipt,
|
||||
_outgoing: OutgoingMessages,
|
||||
_chunks: (ValidatorIndex, &[ErasureChunk])
|
||||
) -> Self::SendLocalCollation { future::ready(Ok(())) }
|
||||
|
||||
@@ -671,7 +658,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(vec![1, 2, 3, 4]),
|
||||
parent_head: HeadData(vec![]),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 1_000_000,
|
||||
block_data_hash: [2; 32].into(),
|
||||
upward_messages: Vec::new(),
|
||||
@@ -728,7 +714,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(vec![1, 2, 3, 4]),
|
||||
parent_head: HeadData(vec![]),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 1_000_000,
|
||||
block_data_hash: [2; 32].into(),
|
||||
upward_messages: Vec::new(),
|
||||
@@ -766,7 +751,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(vec![1, 2, 3, 4]),
|
||||
parent_head: HeadData(vec![]),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 1_000_000,
|
||||
block_data_hash,
|
||||
upward_messages: Vec::new(),
|
||||
@@ -792,24 +776,17 @@ mod tests {
|
||||
max_block_data_size: None,
|
||||
};
|
||||
|
||||
let validated = block_on(producer.prime_with(|_, _, _| Ok((
|
||||
OutgoingMessages { outgoing_messages: Vec::new() },
|
||||
ErasureChunk {
|
||||
chunk: vec![1, 2, 3],
|
||||
index: local_index as u32,
|
||||
proof: vec![],
|
||||
},
|
||||
))).validate()).unwrap();
|
||||
let validated = block_on(producer.prime_with(|_, _, _| Ok(
|
||||
ErasureChunk {
|
||||
chunk: vec![1, 2, 3],
|
||||
index: local_index as u32,
|
||||
proof: vec![],
|
||||
}
|
||||
)).validate()).unwrap();
|
||||
|
||||
assert_eq!(validated.0.pov_block(), &pov_block);
|
||||
assert_eq!(validated.0.statement, GenericStatement::Valid(hash));
|
||||
|
||||
if let Some(messages) = validated.0.outgoing_messages() {
|
||||
let available_messages: AvailableMessages = messages.clone().into();
|
||||
for (root, queue) in available_messages.0 {
|
||||
assert_eq!(store.queue_by_root(&root), Some(queue));
|
||||
}
|
||||
}
|
||||
assert!(store.get_erasure_chunk(&relay_parent, block_data_hash, local_index).is_some());
|
||||
assert!(store.get_erasure_chunk(&relay_parent, block_data_hash, local_index + 1).is_none());
|
||||
}
|
||||
@@ -823,7 +800,6 @@ mod tests {
|
||||
let block_data_hash = pov_block.block_data.hash();
|
||||
let local_index = 0;
|
||||
let n_validators = 2;
|
||||
let ex = Some(AvailableMessages(Vec::new()));
|
||||
|
||||
let candidate = CandidateReceipt {
|
||||
parachain_index: para_id,
|
||||
@@ -831,14 +807,13 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(vec![1, 2, 3, 4]),
|
||||
parent_head: HeadData(vec![]),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 1_000_000,
|
||||
block_data_hash: [2; 32].into(),
|
||||
upward_messages: Vec::new(),
|
||||
erasure_root: [1u8; 32].into(),
|
||||
};
|
||||
|
||||
let chunks = erasure::obtain_chunks(n_validators, &pov_block.block_data, ex.as_ref()).unwrap();
|
||||
let chunks = erasure::obtain_chunks(n_validators, &pov_block.block_data).unwrap();
|
||||
|
||||
store.add_validator_index_and_n_validators(
|
||||
&relay_parent,
|
||||
@@ -857,23 +832,16 @@ mod tests {
|
||||
max_block_data_size: None,
|
||||
};
|
||||
|
||||
let validated = block_on(producer.prime_with(|_, _, _| Ok((
|
||||
OutgoingMessages { outgoing_messages: Vec::new() },
|
||||
let validated = block_on(producer.prime_with(|_, _, _| Ok(
|
||||
ErasureChunk {
|
||||
chunk: chunks[local_index].clone(),
|
||||
index: local_index as u32,
|
||||
proof: vec![],
|
||||
},
|
||||
))).validate()).unwrap();
|
||||
)).validate()).unwrap();
|
||||
|
||||
assert_eq!(validated.0.pov_block(), &pov_block);
|
||||
|
||||
if let Some(messages) = validated.0.outgoing_messages() {
|
||||
let available_messages: AvailableMessages = messages.clone().into();
|
||||
for (root, queue) in available_messages.0 {
|
||||
assert_eq!(store.queue_by_root(&root), Some(queue));
|
||||
}
|
||||
}
|
||||
// This works since there are only two validators and one erasure chunk should be
|
||||
// enough to reconstruct the block data.
|
||||
assert_eq!(store.block_data(relay_parent, block_data_hash).unwrap(), pov_block.block_data);
|
||||
@@ -915,7 +883,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(vec![1, 2, 3, 4]),
|
||||
parent_head: HeadData(vec![]),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 1_000_000,
|
||||
block_data_hash: [2; 32].into(),
|
||||
upward_messages: Vec::new(),
|
||||
@@ -953,7 +920,6 @@ mod tests {
|
||||
|
||||
let para_id = ParaId::from(1);
|
||||
let pov_block = pov_block_with_data(vec![1, 2, 3]);
|
||||
let outgoing_messages = OutgoingMessages { outgoing_messages: Vec::new() };
|
||||
let parent_hash = Default::default();
|
||||
|
||||
let local_key = Sr25519Keyring::Alice.pair();
|
||||
@@ -983,7 +949,6 @@ mod tests {
|
||||
signature: Default::default(),
|
||||
head_data: HeadData(vec![1, 2, 3, 4]),
|
||||
parent_head: HeadData(vec![]),
|
||||
egress_queue_roots: Vec::new(),
|
||||
fees: 1_000_000,
|
||||
block_data_hash: [2; 32].into(),
|
||||
upward_messages: Vec::new(),
|
||||
@@ -994,7 +959,6 @@ mod tests {
|
||||
let signed_statement = shared_table.import_validated(Validated::collated_local(
|
||||
candidate,
|
||||
pov_block,
|
||||
outgoing_messages,
|
||||
)).unwrap();
|
||||
|
||||
assert!(shared_table.inner.lock().validated.get(&hash).expect("validation has started").is_done());
|
||||
|
||||
@@ -391,12 +391,11 @@ impl<C, N, P, SP> ParachainValidationInstances<C, N, P, SP> where
|
||||
);
|
||||
|
||||
collation_work.then(move |result| match result {
|
||||
Ok((collation, outgoing_targeted, parent_head, fees_charged)) => {
|
||||
Ok((collation, parent_head, fees_charged)) => {
|
||||
match crate::collation::produce_receipt_and_chunks(
|
||||
authorities_num,
|
||||
parent_head,
|
||||
&collation.pov,
|
||||
&outgoing_targeted,
|
||||
fees_charged,
|
||||
&collation.info,
|
||||
) {
|
||||
@@ -421,7 +420,6 @@ impl<C, N, P, SP> ParachainValidationInstances<C, N, P, SP> where
|
||||
router.local_collation(
|
||||
collation,
|
||||
receipt,
|
||||
outgoing_targeted,
|
||||
(local_id, &chunks),
|
||||
).map_err(|e| warn!(target: "validation", "Failed to send local collation: {:?}", e))
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user