Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
03e9dde
import rococo into chain-spec
coriolinus Aug 24, 2020
71bffb8
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
coriolinus Aug 24, 2020
4b8e65c
make a few stabs at moving forward
coriolinus Aug 25, 2020
141a5eb
wip: rococo readme
coriolinus Aug 26, 2020
420e67b
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
coriolinus Sep 8, 2020
948efd6
remove /service crate
coriolinus Sep 8, 2020
b32ed40
wip: chase down some build errors in polkadot-cli
coriolinus Sep 8, 2020
61b584f
make more progress getting polkadot-cli to build
coriolinus Sep 9, 2020
a94a4f6
don't ignore polkadot.json within the res directory
coriolinus Sep 9, 2020
84de271
don't recreate pathbufs
coriolinus Sep 9, 2020
fe36c55
Prepare Polkadot to be used by Cumulus
bkchr Sep 10, 2020
b8b958f
Remove old test
bkchr Sep 10, 2020
bf58a14
Merge remote-tracking branch 'origin/bkchr-start-cumulus' into prgn-r…
coriolinus Sep 10, 2020
2e8fdab
Merge remote-tracking branch 'origin/bkchr-start-cumulus' into prgn-r…
coriolinus Sep 10, 2020
24e2e29
migrate new_chain_ops fix from /service
coriolinus Sep 10, 2020
7b8f9ba
partially remove node/test-service
coriolinus Sep 10, 2020
bb177a9
Reset some changes
bkchr Sep 10, 2020
a148e7d
Revert "partially remove node/test-service"
coriolinus Sep 11, 2020
39e140e
Merge remote-tracking branch 'origin/bkchr-start-cumulus' into prgn-r…
coriolinus Sep 11, 2020
2e69812
WIP: replace v0 ParachainHost impl with v1 for test runtime
coriolinus Sep 11, 2020
68fccb5
fix test runtime build
coriolinus Sep 11, 2020
93f8d4f
bump westend spec version
coriolinus Sep 11, 2020
2ae8cee
use service-new as service within cli
coriolinus Sep 11, 2020
68d2f38
to revert: demo that forwarding the test runtime to the real impl blo…
coriolinus Sep 11, 2020
04cb1cb
Revert "to revert: demo that forwarding the test runtime to the real …
coriolinus Sep 11, 2020
32fc3ab
Revert "Revert "to revert: demo that forwarding the test runtime to t…
coriolinus Sep 11, 2020
cfef23f
More reverts
bkchr Sep 11, 2020
5192634
MOARE
bkchr Sep 11, 2020
4b3b066
Merge remote-tracking branch 'origin/master' into bkchr-start-cumulus
bkchr Sep 11, 2020
4acd607
Merge remote-tracking branch 'origin/bkchr-start-cumulus' into prgn-r…
coriolinus Sep 11, 2020
fe6449e
plug in the runtime as the generic instantiation
coriolinus Sep 14, 2020
5a7918a
implement necessary traits to get the test runtime compiling
coriolinus Sep 15, 2020
73ded05
add inclusion::Event as variant into Event enum
coriolinus Sep 15, 2020
db56494
implement unimplemented bits in kusama
coriolinus Sep 15, 2020
1fa4a80
implement unimplemented bits in polkadot runtime
coriolinus Sep 15, 2020
3b4cc15
implement unimplemented bits in westend runtime
coriolinus Sep 15, 2020
5856a2b
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
coriolinus Sep 15, 2020
0386374
migrate client upgrades from master
coriolinus Sep 15, 2020
00887ea
update test service with new node changes
coriolinus Sep 15, 2020
38c2a42
package metadata--that wasn't intended to be removed
coriolinus Sep 16, 2020
06e960d
add parachains v1 modules to each runtime
coriolinus Sep 16, 2020
c0e9e43
enable cli to opt out of full node features
coriolinus Sep 16, 2020
34e51e5
adjust rococo chainspec per example
coriolinus Sep 16, 2020
3060842
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
coriolinus Sep 16, 2020
cf2062a
try to fix Cargo.lock
Sep 16, 2020
563555d
Merge branch 'master' into prgn-run-rococo
Sep 16, 2020
df7a758
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
coriolinus Sep 17, 2020
731ebf4
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
coriolinus Sep 17, 2020
65c388b
Merge remote-tracking branch 'origin/master' into prgn-run-rococo
coriolinus Sep 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 63 additions & 15 deletions node/core/candidate-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ async fn spawn_validate_from_chain_state(
ctx,
validation_pool,
validation_data.persisted,
validation_data.transient,
Some(validation_data.transient),
validation_code,
descriptor,
pov,
Expand All @@ -311,7 +311,7 @@ async fn spawn_validate_from_chain_state(
ctx,
validation_pool,
validation_data.persisted,
validation_data.transient,
Some(validation_data.transient),
validation_code,
descriptor,
pov,
Expand All @@ -332,7 +332,7 @@ async fn spawn_validate_exhaustive(
ctx: &mut impl SubsystemContext<Message = CandidateValidationMessage>,
validation_pool: Option<ValidationPool>,
persisted_validation_data: PersistedValidationData,
transient_validation_data: TransientValidationData,
transient_validation_data: Option<TransientValidationData>,
validation_code: ValidationCode,
descriptor: CandidateDescriptor,
pov: Arc<PoV>,
Expand Down Expand Up @@ -449,7 +449,7 @@ impl ValidationBackend for RealValidationBackend {
fn validate_candidate_exhaustive<B: ValidationBackend, S: SpawnNamed + 'static>(
backend_arg: B::Arg,
persisted_validation_data: PersistedValidationData,
transient_validation_data: TransientValidationData,
transient_validation_data: Option<TransientValidationData>,
validation_code: ValidationCode,
descriptor: CandidateDescriptor,
pov: Arc<PoV>,
Expand All @@ -460,11 +460,10 @@ fn validate_candidate_exhaustive<B: ValidationBackend, S: SpawnNamed + 'static>(
}

let params = ValidationParams {
parent_head: persisted_validation_data.parent_head.clone(),
block_data: pov.block_data.clone(),
validation_data: ValidationData {
persisted: persisted_validation_data.clone(),
transient: transient_validation_data.clone(),
}
relay_chain_height: persisted_validation_data.block_number,
hrmp_mqc_heads: persisted_validation_data.hrmp_mqc_heads.clone(),
};

match B::validate(backend_arg, &validation_code, params, spawn) {
Expand All @@ -482,10 +481,14 @@ fn validate_candidate_exhaustive<B: ValidationBackend, S: SpawnNamed + 'static>(
Ok(ValidationResult::Invalid(InvalidCandidate::ExecutionError(e.to_string()))),
Err(ValidationError::Internal(e)) => Err(ValidationFailed(e.to_string())),
Ok(res) => {
let post_check_result = check_wasm_result_against_constraints(
&transient_validation_data,
&res,
);
let post_check_result = if let Some(transient) = transient_validation_data {
check_wasm_result_against_constraints(
&transient,
&res,
)
} else {
Ok(())
};

Ok(match post_check_result {
Ok(()) => ValidationResult::Valid(ValidationOutputs {
Expand Down Expand Up @@ -831,7 +834,7 @@ mod tests {
let v = validate_candidate_exhaustive::<MockValidationBackend, _>(
MockValidationArg { result: Ok(validation_result) },
validation_data.persisted.clone(),
validation_data.transient,
Some(validation_data.transient),
vec![1, 2, 3].into(),
descriptor,
Arc::new(pov),
Expand Down Expand Up @@ -882,7 +885,7 @@ mod tests {
))
},
validation_data.persisted,
validation_data.transient,
Some(validation_data.transient),
vec![1, 2, 3].into(),
descriptor,
Arc::new(pov),
Expand Down Expand Up @@ -928,7 +931,7 @@ mod tests {
))
},
validation_data.persisted,
validation_data.transient,
Some(validation_data.transient),
vec![1, 2, 3].into(),
descriptor,
Arc::new(pov),
Expand All @@ -937,4 +940,49 @@ mod tests {

assert_matches!(v, Ok(ValidationResult::Invalid(InvalidCandidate::Timeout)));
}

#[test]
fn candidate_validation_ok_does_not_validate_outputs_if_no_transient() {
let mut validation_data: ValidationData = Default::default();
validation_data.transient.max_head_data_size = 1;
validation_data.transient.max_code_size = 1;

let pov = PoV { block_data: BlockData(vec![1; 32]) };

let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);

assert!(perform_basic_checks(&descriptor, Some(1024), &pov).is_ok());

let validation_result = WasmValidationResult {
head_data: HeadData(vec![1, 1, 1]),
new_validation_code: Some(vec![2, 2, 2].into()),
upward_messages: Vec::new(),
processed_downward_messages: 0,
};

assert!(check_wasm_result_against_constraints(
&validation_data.transient,
&validation_result,
).is_err());

let v = validate_candidate_exhaustive::<MockValidationBackend, _>(
MockValidationArg { result: Ok(validation_result) },
validation_data.persisted.clone(),
None,
vec![1, 2, 3].into(),
descriptor,
Arc::new(pov),
TaskExecutor::new(),
).unwrap();

assert_matches!(v, ValidationResult::Valid(outputs) => {
assert_eq!(outputs.head_data, HeadData(vec![1, 1, 1]));
assert_eq!(outputs.validation_data, validation_data.persisted);
assert_eq!(outputs.upward_messages, Vec::new());
assert_eq!(outputs.fees, 0);
assert_eq!(outputs.new_validation_code, Some(vec![2, 2, 2].into()));
});
}
}
7 changes: 4 additions & 3 deletions node/subsystem/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ pub enum CandidateValidationMessage {
),
/// Validate a candidate with provided, exhaustive parameters for validation.
///
/// Explicitly provide the `PersistedValidationData`, `TransientValidationData` and `ValidationCode`
/// so this can do full validation without needing to access the state of the relay-chain.
/// Explicitly provide the `PersistedValidationData` and `ValidationCode` so this can do full
/// validation without needing to access the state of the relay-chain. Optionally provide the
/// `TransientValidationData` for further checks on the outputs.
ValidateFromExhaustive(
PersistedValidationData,
TransientValidationData,
Option<TransientValidationData>,
ValidationCode,
CandidateDescriptor,
Arc<PoV>,
Expand Down
98 changes: 8 additions & 90 deletions parachain/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use sp_std::vec::Vec;

use codec::{Encode, Decode, CompactAs};
use sp_core::{RuntimeDebug, TypeId};
use sp_runtime::traits::{Hash as _, BlakeTwo256};

#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
Expand Down Expand Up @@ -226,102 +225,21 @@ pub struct UpwardMessage {
pub data: Vec<u8>,
}

/// The validation data provide information about how to validate both the inputs and
/// outputs of a candidate.
///
/// There are two types of validation data: persisted and transient.
/// Their respective sections of the guide elaborate on their functionality in more detail.
///
/// This information is derived from the chain state and will vary from para to para,
/// although some of the fields may be the same for every para.
///
/// Persisted validation data are generally derived from some relay-chain state to form inputs
/// to the validation function, and as such need to be persisted by the availability system to
/// avoid dependence on availability of the relay-chain state. The backing phase of the
/// inclusion pipeline ensures that everything that is included in a valid fork of the
/// relay-chain already adheres to the transient constraints.
///
/// The validation data also serve the purpose of giving collators a means of ensuring that
/// their produced candidate and the commitments submitted to the relay-chain alongside it
/// will pass the checks done by the relay-chain when backing, and give validators
/// the same understanding when determining whether to second or attest to a candidate.
///
/// Since the commitments of the validation function are checked by the
/// relay-chain, secondary checkers can rely on the invariant that the relay-chain
/// only includes para-blocks for which these checks have already been done. As such,
/// there is no need for the validation data used to inform validators and collators about
/// the checks the relay-chain will perform to be persisted by the availability system.
/// Nevertheless, we expose it so the backing validators can validate the outputs of a
/// candidate before voting to submit it to the relay-chain and so collators can
/// collate candidates that satisfy the criteria implied these transient validation data.
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Default))]
pub struct ValidationData<N = RelayChainBlockNumber> {
/// The persisted validation data.
pub persisted: PersistedValidationData<N>,
/// The transient validation data.
pub transient: TransientValidationData<N>,
}

/// Validation data that needs to be persisted for secondary checkers.
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Default))]
pub struct PersistedValidationData<N = RelayChainBlockNumber> {
/// The parent head-data.
pub parent_head: HeadData,
/// The relay-chain block number this is in the context of.
pub block_number: N,
/// The list of MQC heads for the inbound channels paired with the sender para ids. This
/// vector is sorted ascending by the para id and doesn't contain multiple entries with the same
/// sender.
pub hrmp_mqc_heads: Vec<(Id, Hash)>,
}

impl<N: Encode> PersistedValidationData<N> {
/// Compute the blake2-256 hash of the persisted validation data.
pub fn hash(&self) -> Hash {
BlakeTwo256::hash_of(self)
}
}

/// Validation data for checking outputs of the validation-function.
/// As such, they also inform the collator about how to construct the candidate.
///
/// These are transient because they are not necessary beyond the point where the
/// candidate is backed.
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Default))]
pub struct TransientValidationData<N = RelayChainBlockNumber> {
/// The maximum code size permitted, in bytes.
pub max_code_size: u32,
/// The maximum head-data size permitted, in bytes.
pub max_head_data_size: u32,
/// The balance of the parachain at the moment of validation.
pub balance: polkadot_core_primitives::Balance,
/// Whether the parachain is allowed to upgrade its validation code.
///
/// This is `Some` if so, and contains the number of the minimum relay-chain
/// height at which the upgrade will be applied, if an upgrade is signaled
/// now.
///
/// A parachain should enact its side of the upgrade at the end of the first
/// parablock executing in the context of a relay-chain block with at least this
/// height. This may be equal to the current perceived relay-chain block height, in
/// which case the code upgrade should be applied at the end of the signaling
/// block.
pub code_upgrade_allowed: Option<N>,
}

/// Validation parameters for evaluating the parachain validity function.
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
#[derive(PartialEq, Eq, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Encode))]
pub struct ValidationParams {
/// Previous head-data.
pub parent_head: HeadData,
/// The collation body.
pub block_data: BlockData,
/// The validation data that was also available to the collator when
/// building the PoVBlock.
pub validation_data: ValidationData,
/// The current relay-chain block number.
pub relay_chain_height: RelayChainBlockNumber,
/// The list of MQC heads for the inbound HRMP channels paired with the sender para ids. This
/// vector is sorted ascending by the para id and doesn't contain multiple entries with the same
/// sender.
pub hrmp_mqc_heads: Vec<(Id, Hash)>,
}

/// The result of parachain validation.
Expand Down
4 changes: 2 additions & 2 deletions parachain/test-parachains/adder/src/wasm_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ use codec::{Encode, Decode};
#[no_mangle]
pub extern fn validate_block(params: *const u8, len: usize) -> u64 {
let params = unsafe { parachain::load_params(params, len) };
let parent_head = HeadData::decode(&mut &params.validation_data.persisted.parent_head.0[..])
let parent_head = HeadData::decode(&mut &params.parent_head.0[..])
.expect("invalid parent head format.");

let block_data = BlockData::decode(&mut &params.block_data.0[..])
.expect("invalid block data format.");

let parent_hash = tiny_keccak::keccak256(&params.validation_data.persisted.parent_head.0[..]);
let parent_hash = tiny_keccak::keccak256(&params.parent_head.0[..]);

match crate::execute(parent_hash, parent_head, &block_data) {
Ok(new_head) => parachain::write_result(
Expand Down
39 changes: 13 additions & 26 deletions parachain/test-parachains/tests/adder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ const WORKER_ARGS_TEST: &[&'static str] = &["--nocapture", "validation_worker"];

use parachain::{
primitives::{
BlockData as GenericBlockData, HeadData as GenericHeadData,
ValidationParams, ValidationData, PersistedValidationData,
RelayChainBlockNumber,
BlockData as GenericBlockData,
HeadData as GenericHeadData,
ValidationParams,
},
wasm_executor::{ValidationPool, ValidationExecutionMode}
};
Expand Down Expand Up @@ -92,15 +94,10 @@ fn execute_good_on_parent(pool: ValidationPool) {
let ret = parachain::wasm_executor::validate_candidate(
adder::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
validation_data: ValidationData {
persisted: PersistedValidationData {
parent_head: GenericHeadData(parent_head.encode()),
block_number: 1,
..Default::default()
},
transient: Default::default(),
},
relay_chain_height: 1,
hrmp_mqc_heads: Vec::new(),
},
parachain::wasm_executor::ExecutionMode::Remote(&pool),
sp_core::testing::TaskExecutor::new(),
Expand Down Expand Up @@ -135,15 +132,10 @@ fn execute_good_chain_on_parent() {
let ret = parachain::wasm_executor::validate_candidate(
adder::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
validation_data: ValidationData {
persisted: PersistedValidationData {
parent_head: GenericHeadData(parent_head.encode()),
block_number: (number + 1) as _,
..Default::default()
},
transient: Default::default(),
},
relay_chain_height: number as RelayChainBlockNumber + 1,
hrmp_mqc_heads: Vec::new(),
},
parachain::wasm_executor::ExecutionMode::Remote(&pool),
sp_core::testing::TaskExecutor::new(),
Expand Down Expand Up @@ -179,15 +171,10 @@ fn execute_bad_on_parent() {
let _ret = parachain::wasm_executor::validate_candidate(
adder::wasm_binary_unwrap(),
ValidationParams {
parent_head: GenericHeadData(parent_head.encode()),
block_data: GenericBlockData(block_data.encode()),
validation_data: ValidationData {
persisted: PersistedValidationData {
parent_head: GenericHeadData(parent_head.encode()),
block_number: 1,
..Default::default()
},
transient: Default::default(),
},
relay_chain_height: 1,
hrmp_mqc_heads: Vec::new(),
},
parachain::wasm_executor::ExecutionMode::Remote(&pool),
sp_core::testing::TaskExecutor::new(),
Expand Down
Loading