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
+6 -24
View File
@@ -26,7 +26,7 @@ use polkadot_primitives::v1::{
Hash, CommittedCandidateReceipt, CandidateReceipt, CompactStatement,
EncodeAs, Signed, SigningContext, ValidatorIndex, ValidatorId,
UpwardMessage, Balance, ValidationCode, PersistedValidationData, ValidationData,
HeadData, PoV, CollatorPair, Id as ParaId,
HeadData, PoV, CollatorPair, Id as ParaId, ValidationOutputs,
};
use polkadot_statement_table::{
generic::{
@@ -114,26 +114,13 @@ pub struct FromTableMisbehavior {
pub key: ValidatorId,
}
/// Outputs of validating a candidate.
#[derive(Debug)]
pub struct ValidationOutputs {
/// The head-data produced by validation.
pub head_data: HeadData,
/// The persisted validation data.
pub validation_data: PersistedValidationData,
/// Upward messages to the relay chain.
pub upward_messages: Vec<UpwardMessage>,
/// Fees paid to the validators of the relay-chain.
pub fees: Balance,
/// The new validation code submitted by the execution, if any.
pub new_validation_code: Option<ValidationCode>,
}
/// Candidate invalidity details
#[derive(Debug)]
pub enum InvalidCandidate {
/// Failed to execute.`validate_block`. This includes function panicking.
ExecutionError(String),
/// Validation outputs check doesn't pass.
InvalidOutputs,
/// Execution timeout.
Timeout,
/// Validation input is over the limit.
@@ -148,19 +135,14 @@ pub enum InvalidCandidate {
HashMismatch,
/// Bad collator signature.
BadSignature,
/// Output code is too large
NewCodeTooLarge(u64),
/// Head-data is over the limit.
HeadDataTooLarge(u64),
/// Code upgrade triggered but not allowed.
CodeUpgradeNotAllowed,
}
/// Result of the validation of the candidate.
#[derive(Debug)]
pub enum ValidationResult {
/// Candidate is valid. The validation process yields these outputs.
Valid(ValidationOutputs),
/// Candidate is valid. The validation process yields these outputs and the persisted validation
/// data used to form inputs.
Valid(ValidationOutputs, PersistedValidationData),
/// Candidate is invalid.
Invalid(InvalidCandidate),
}