Runtime API for checking validation outputs (#1842)

* annoying whitespaces

* update guide

Add `CheckValidationOutputs` runtime api and also change the
candidate-validation stuff

* promote ValidationOutputs to global primitives

i.e. move it from node specific primitives to global v1 primitives. This
will be needed when we share it later in the runtime inclusion module

* refactor acceptance checks in the inclusion module

factor out the common code to share it during the block inclusion and
for the forthcoming CheckValidationOutputs runtime api.

Also note that the acceptance criteria was updated to incorporate checks
that exist now in candidate-validation

* plumb the runtime api outside

* extract validation_data from ValidationOutputs

* use runtime-api to check validation outputs

apart from that refactor, update docs and tidy a bit

* Update the maxium code size

This is to fix a test that performs an upgrade.
This commit is contained in:
Sergei Shulepov
2020-10-24 08:48:36 +02:00
committed by GitHub
parent ec49d81307
commit abb282dfd0
16 changed files with 435 additions and 316 deletions
@@ -343,7 +343,10 @@ async fn candidate_is_valid_inner(
CandidateValidationMessage::ValidateFromChainState(candidate_descriptor, pov, tx),
))
.await?;
Ok(std::matches!(rx.await, Ok(Ok(ValidationResult::Valid(_)))))
Ok(std::matches!(
rx.await,
Ok(Ok(ValidationResult::Valid(_, _)))
))
}
async fn second_candidate(
@@ -445,8 +448,7 @@ delegated_subsystem!(CandidateSelectionJob((), Metrics) <- ToJob as CandidateSel
mod tests {
use super::*;
use futures::lock::Mutex;
use polkadot_node_primitives::ValidationOutputs;
use polkadot_primitives::v1::{BlockData, HeadData, PersistedValidationData};
use polkadot_primitives::v1::{BlockData, HeadData, PersistedValidationData, ValidationOutputs};
use sp_core::crypto::Public;
fn test_harness<Preconditions, TestBuilder, Test, Postconditions>(
@@ -478,7 +480,7 @@ mod tests {
postconditions(job, job_result);
}
fn default_validation_outputs() -> ValidationOutputs {
fn default_validation_outputs_and_data() -> (ValidationOutputs, polkadot_primitives::v1::PersistedValidationData) {
let head_data: Vec<u8> = (0..32).rev().cycle().take(256).collect();
let parent_head_data = head_data
.iter()
@@ -486,17 +488,19 @@ mod tests {
.map(|x| x.saturating_sub(1))
.collect();
ValidationOutputs {
head_data: HeadData(head_data),
validation_data: PersistedValidationData {
(
ValidationOutputs {
head_data: HeadData(head_data),
upward_messages: Vec::new(),
fees: 0,
new_validation_code: None,
},
PersistedValidationData {
parent_head: HeadData(parent_head_data),
block_number: 123,
hrmp_mqc_heads: Vec::new(),
},
upward_messages: Vec::new(),
fees: 0,
new_validation_code: None,
}
)
}
/// when nothing is seconded so far, the collation is fetched and seconded
@@ -556,8 +560,9 @@ mod tests {
assert_eq!(got_candidate_descriptor, candidate_receipt.descriptor);
assert_eq!(got_pov.as_ref(), &pov);
let (outputs, data) = default_validation_outputs_and_data();
return_sender
.send(Ok(ValidationResult::Valid(default_validation_outputs())))
.send(Ok(ValidationResult::Valid(outputs, data)))
.unwrap();
}
FromJob::Backing(CandidateBackingMessage::Second(