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 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ed713ad
initial stab at candidate_context
rphmeier Jan 27, 2022
300cc3a
fmt
rphmeier Jan 27, 2022
90816b0
docs & more TODOs
rphmeier Jan 28, 2022
cc47e9c
some cleanups
rphmeier Feb 2, 2022
62b6226
reframe as inclusion_emulator
rphmeier Feb 2, 2022
b9f4d40
documentations yes
rphmeier Feb 3, 2022
7169066
update types
rphmeier Feb 3, 2022
2642148
add constraint modifications
rphmeier Feb 4, 2022
b123217
watermark
rphmeier Feb 4, 2022
2b43d0b
produce modifications
rphmeier Feb 4, 2022
8c0c3a3
v2 primitives: re-export all v1 for consistency
rphmeier Feb 8, 2022
cf8c17c
vstaging primitives
rphmeier Feb 8, 2022
51cdc50
emulator constraints: handle code upgrades
rphmeier Feb 8, 2022
acadae5
produce outbound HRMP modifications
rphmeier Feb 8, 2022
754619e
stack.
rphmeier Feb 8, 2022
5229f6b
method for applying modifications
rphmeier Feb 9, 2022
edd2c46
method just for sanity-checking modifications
rphmeier Feb 9, 2022
ce5c54f
fragments produce modifications, not prospectives
rphmeier Feb 9, 2022
170fe93
make linear
rphmeier Feb 9, 2022
6e16542
add some TODOs
rphmeier Feb 9, 2022
f47a6e7
remove stacking; handle code upgrades
rphmeier Feb 9, 2022
5dfe2bc
take `fragment` private
rphmeier Feb 9, 2022
305ee7d
reintroduce stacking.
rphmeier Feb 9, 2022
ecf0287
fragment constructor
rphmeier Feb 9, 2022
27d380b
add TODO
rphmeier Feb 9, 2022
a5be2eb
allow validating fragments against future constraints
rphmeier Feb 10, 2022
9c31cc0
docs
rphmeier Feb 10, 2022
6cc8fe4
Merge branch 'master' into rh-async-backing-contexts
rphmeier Feb 10, 2022
9f8adc9
relay-parent number and min code size checks
rphmeier Feb 10, 2022
6fe064c
check code upgrade restriction
rphmeier Feb 10, 2022
7367e65
check max hrmp per candidate
rphmeier Feb 10, 2022
9dd5cb2
fmt
rphmeier Feb 10, 2022
a7d4347
remove GoAhead logic because it wasn't helpful
rphmeier Feb 10, 2022
87fd692
docs on code upgrade failure
rphmeier Feb 10, 2022
85170dd
test stacking
rphmeier Feb 11, 2022
a283a14
test modifications against constraints
rphmeier Feb 11, 2022
4ea280b
fmt
rphmeier Feb 11, 2022
22251e4
test fragments
rphmeier Feb 11, 2022
e974afa
descending or duplicate test
rphmeier Feb 11, 2022
d6d6a65
fmt
rphmeier Feb 11, 2022
4853960
remove unused imports in vstaging
rphmeier Feb 11, 2022
36906fa
wrong primitives
rphmeier Feb 11, 2022
3b403ed
spellcheck
rphmeier Feb 12, 2022
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
Prev Previous commit
Next Next commit
test fragments
  • Loading branch information
rphmeier committed Feb 11, 2022
commit 22251e4731b2ad5f37a3806fef03f38a1bf302a7
1 change: 0 additions & 1 deletion node/subsystem-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ log = "0.4.13"
polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" }
lazy_static = "1.4.0"
polkadot-primitives-test-helpers = { path = "../../primitives/test-helpers" }

191 changes: 190 additions & 1 deletion node/subsystem-util/src/inclusion_emulator/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ impl Fragment {
/// This fails if the fragment isn't in line with the operating
/// constraints. That is, either its inputs or its outputs fail
/// checks against the constraints.
///
/// This doesn't check that the collator signature is valid or
/// whether the PoV is large enough or whether the hrmp messages
/// are in ascending order and non-duplicate
// TODO [now]: maybe it should.
pub fn new(
relay_parent: RelayChainBlockInfo,
operating_constraints: Constraints,
Expand Down Expand Up @@ -674,7 +679,8 @@ fn validate_against_constraints(
#[cfg(test)]
mod tests {
use super::*;
use polkadot_primitives::vstaging::ValidationCode;
use polkadot_primitives::vstaging::{CollatorPair, ValidationCode, OutboundHrmpMessage};
use sp_application_crypto::Pair;

#[test]
fn stack_modifications() {
Expand Down Expand Up @@ -1004,6 +1010,189 @@ mod tests {
);
}

fn make_candidate(
constraints: &Constraints,
relay_parent: &RelayChainBlockInfo,
) -> ProspectiveCandidate {
let collator_pair = CollatorPair::generate().0;
let collator = collator_pair.public();

let sig = collator_pair.sign(b"blabla".as_slice());

ProspectiveCandidate {
commitments: CandidateCommitments {
upward_messages: Vec::new(),
horizontal_messages: Vec::new(),
new_validation_code: None,
head_data: HeadData::from(vec![1, 2, 3, 4, 5]),
processed_downward_messages: 0,
hrmp_watermark: relay_parent.number,
},
collator,
collator_signature: sig,
persisted_validation_data: PersistedValidationData {
parent_head: constraints.required_parent.clone(),
relay_parent_number: relay_parent.number,
relay_parent_storage_root: relay_parent.storage_root,
max_pov_size: constraints.max_pov_size as u32,
},
pov_hash: Hash::repeat_byte(1),
validation_code_hash: constraints.validation_code_hash,
}
}

#[test]
fn fragment_validation_code_mismatch() {
let relay_parent = RelayChainBlockInfo {
number: 6,
hash: Hash::repeat_byte(0x0a),
storage_root: Hash::repeat_byte(0xff),
};

let constraints = make_constraints();
let mut candidate = make_candidate(&constraints, &relay_parent);

let expected_code = constraints.validation_code_hash.clone();
let got_code = ValidationCode(vec![9, 9 , 9]).hash();

candidate.validation_code_hash = got_code;

assert_eq!(
Fragment::new(relay_parent, constraints, candidate),
Err(FragmentValidityError::ValidationCodeMismatch(
expected_code,
got_code,
)),
)
}

#[test]
fn fragment_pvd_mismatch() {
let relay_parent = RelayChainBlockInfo {
number: 6,
hash: Hash::repeat_byte(0x0a),
storage_root: Hash::repeat_byte(0xff),
};

let relay_parent_b = RelayChainBlockInfo {
number: 6,
hash: Hash::repeat_byte(0x0b),
storage_root: Hash::repeat_byte(0xee),
};

let constraints = make_constraints();
let candidate = make_candidate(&constraints, &relay_parent);

let expected_pvd = PersistedValidationData {
parent_head: constraints.required_parent.clone(),
relay_parent_number: relay_parent_b.number,
relay_parent_storage_root: relay_parent_b.storage_root,
max_pov_size: constraints.max_pov_size as u32,
};

let got_pvd = candidate.persisted_validation_data.clone();

assert_eq!(
Fragment::new(relay_parent_b, constraints, candidate),
Err(FragmentValidityError::PersistedValidationDataMismatch(
expected_pvd,
got_pvd,
)),
);
}

#[test]
fn fragment_code_size_too_large() {
let relay_parent = RelayChainBlockInfo {
number: 6,
hash: Hash::repeat_byte(0x0a),
storage_root: Hash::repeat_byte(0xff),
};

let constraints = make_constraints();
let mut candidate = make_candidate(&constraints, &relay_parent);

let max_code_size = constraints.max_code_size;
candidate.commitments.new_validation_code = Some(vec![0; max_code_size + 1].into());

assert_eq!(
Fragment::new(relay_parent, constraints, candidate),
Err(FragmentValidityError::CodeSizeTooLarge(
max_code_size,
max_code_size + 1,
)),
);
}

#[test]
fn fragment_relay_parent_too_old() {
let relay_parent = RelayChainBlockInfo {
number: 3,
hash: Hash::repeat_byte(0x0a),
storage_root: Hash::repeat_byte(0xff),
};

let constraints = make_constraints();
let candidate = make_candidate(&constraints, &relay_parent);

assert_eq!(
Fragment::new(relay_parent, constraints, candidate),
Err(FragmentValidityError::RelayParentTooOld(
5,
3,
)),
);
}

#[test]
fn fragment_hrmp_messages_overflow() {
let relay_parent = RelayChainBlockInfo {
number: 6,
hash: Hash::repeat_byte(0x0a),
storage_root: Hash::repeat_byte(0xff),
};

let constraints = make_constraints();
let mut candidate = make_candidate(&constraints, &relay_parent);

let max_hrmp = constraints.max_hrmp_num_per_candidate;

candidate.commitments.horizontal_messages.extend(
(0..max_hrmp + 1).map(|i| OutboundHrmpMessage {
recipient: ParaId::from(i as u32),
data: vec![1, 2, 3],
})
);

assert_eq!(
Fragment::new(relay_parent, constraints, candidate),
Err(FragmentValidityError::HrmpMessagesPerCandidateOverflow {
messages_allowed: max_hrmp,
messages_submitted: max_hrmp + 1,
}),
);
}

#[test]
fn fragment_code_upgrade_restricted() {
let relay_parent = RelayChainBlockInfo {
number: 6,
hash: Hash::repeat_byte(0x0a),
storage_root: Hash::repeat_byte(0xff),
};

let mut constraints = make_constraints();
let mut candidate = make_candidate(&constraints, &relay_parent);

constraints.upgrade_restriction = Some(UpgradeRestriction::Present);
candidate.commitments.new_validation_code = Some(ValidationCode(vec![1, 2, 3]));

assert_eq!(
Fragment::new(relay_parent, constraints, candidate),
Err(FragmentValidityError::CodeUpgradeRestricted),
);
}

// TODO [now] checking outputs against constraints.

// TODO [now] checking fragments against constraints.
Expand Down