mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 04:17:57 +00:00
add max_pov_size to runtime config and PersistedValidationData (#1984)
* add max_pov_size to runtime config and PersistedValidationData Closes #1572. * set default genesis max_pov_size * apply suggestions from code review * add default max_pov_size to polkadot_testnet_genesis
This commit is contained in:
committed by
GitHub
parent
5ac497d431
commit
d13a335df6
@@ -73,6 +73,7 @@ impl Default for TestState {
|
||||
block_number: 5,
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
dmq_mqc_head: Default::default(),
|
||||
max_pov_size: 1024,
|
||||
};
|
||||
|
||||
let pruning_config = PruningConfig {
|
||||
|
||||
@@ -1031,6 +1031,7 @@ mod tests {
|
||||
block_number: Default::default(),
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
dmq_mqc_head: Default::default(),
|
||||
max_pov_size: 1024,
|
||||
},
|
||||
transient: TransientValidationData {
|
||||
max_code_size: 1000,
|
||||
|
||||
@@ -347,16 +347,14 @@ async fn spawn_validate_exhaustive(
|
||||
/// are passed, `Err` otherwise.
|
||||
fn perform_basic_checks(
|
||||
candidate: &CandidateDescriptor,
|
||||
max_block_data_size: Option<u64>,
|
||||
max_pov_size: u32,
|
||||
pov: &PoV,
|
||||
) -> Result<(), InvalidCandidate> {
|
||||
let encoded_pov = pov.encode();
|
||||
let hash = pov.hash();
|
||||
|
||||
if let Some(max_size) = max_block_data_size {
|
||||
if encoded_pov.len() as u64 > max_size {
|
||||
return Err(InvalidCandidate::ParamsTooLarge(encoded_pov.len() as u64));
|
||||
}
|
||||
if encoded_pov.len() > max_pov_size as usize {
|
||||
return Err(InvalidCandidate::ParamsTooLarge(encoded_pov.len() as u64));
|
||||
}
|
||||
|
||||
if hash != candidate.pov_hash {
|
||||
@@ -412,7 +410,7 @@ fn validate_candidate_exhaustive<B: ValidationBackend, S: SpawnNamed + 'static>(
|
||||
pov: Arc<PoV>,
|
||||
spawn: S,
|
||||
) -> Result<ValidationResult, ValidationFailed> {
|
||||
if let Err(e) = perform_basic_checks(&descriptor, None, &*pov) {
|
||||
if let Err(e) = perform_basic_checks(&descriptor, persisted_validation_data.max_pov_size, &*pov) {
|
||||
return Ok(ValidationResult::Invalid(e))
|
||||
}
|
||||
|
||||
@@ -819,7 +817,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn candidate_validation_ok_is_ok() {
|
||||
let validation_data: PersistedValidationData = Default::default();
|
||||
let validation_data = PersistedValidationData { max_pov_size: 1024, ..Default::default() };
|
||||
|
||||
let pov = PoV { block_data: BlockData(vec![1; 32]) };
|
||||
|
||||
@@ -827,7 +825,7 @@ mod tests {
|
||||
descriptor.pov_hash = pov.hash();
|
||||
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
|
||||
|
||||
assert!(perform_basic_checks(&descriptor, Some(1024), &pov).is_ok());
|
||||
assert!(perform_basic_checks(&descriptor, validation_data.max_pov_size, &pov).is_ok());
|
||||
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data: HeadData(vec![1, 1, 1]),
|
||||
@@ -859,7 +857,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn candidate_validation_bad_return_is_invalid() {
|
||||
let validation_data: PersistedValidationData = Default::default();
|
||||
let validation_data = PersistedValidationData { max_pov_size: 1024, ..Default::default() };
|
||||
|
||||
let pov = PoV { block_data: BlockData(vec![1; 32]) };
|
||||
|
||||
@@ -867,7 +865,7 @@ mod tests {
|
||||
descriptor.pov_hash = pov.hash();
|
||||
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
|
||||
|
||||
assert!(perform_basic_checks(&descriptor, Some(1024), &pov).is_ok());
|
||||
assert!(perform_basic_checks(&descriptor, validation_data.max_pov_size, &pov).is_ok());
|
||||
|
||||
let v = validate_candidate_exhaustive::<MockValidationBackend, _>(
|
||||
MockValidationArg {
|
||||
@@ -887,7 +885,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn candidate_validation_timeout_is_internal_error() {
|
||||
let validation_data: PersistedValidationData = Default::default();
|
||||
let validation_data = PersistedValidationData { max_pov_size: 1024, ..Default::default() };
|
||||
|
||||
let pov = PoV { block_data: BlockData(vec![1; 32]) };
|
||||
|
||||
@@ -895,7 +893,7 @@ mod tests {
|
||||
descriptor.pov_hash = pov.hash();
|
||||
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
|
||||
|
||||
assert!(perform_basic_checks(&descriptor, Some(1024), &pov).is_ok());
|
||||
assert!(perform_basic_checks(&descriptor, validation_data.max_pov_size, &pov).is_ok());
|
||||
|
||||
let v = validate_candidate_exhaustive::<MockValidationBackend, _>(
|
||||
MockValidationArg {
|
||||
|
||||
@@ -218,6 +218,7 @@ impl Default for TestState {
|
||||
block_number: Default::default(),
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
dmq_mqc_head: Default::default(),
|
||||
max_pov_size: 1024,
|
||||
};
|
||||
|
||||
let validator_index = Some((validators.len() - 1) as ValidatorIndex);
|
||||
|
||||
@@ -777,6 +777,7 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
|
||||
validation_upgrade_delay: 300,
|
||||
acceptance_period: 1200,
|
||||
max_code_size: 5 * 1024 * 1024,
|
||||
max_pov_size: 50 * 1024 * 1024,
|
||||
max_head_data_size: 32 * 1024,
|
||||
group_rotation_frequency: 10,
|
||||
..Default::default()
|
||||
@@ -1229,6 +1230,7 @@ pub fn rococo_testnet_genesis(
|
||||
validation_upgrade_delay: 300,
|
||||
acceptance_period: 1200,
|
||||
max_code_size: 5 * 1024 * 1024,
|
||||
max_pov_size: 50 * 1024 * 1024,
|
||||
max_head_data_size: 32 * 1024,
|
||||
group_rotation_frequency: 10,
|
||||
..Default::default()
|
||||
|
||||
@@ -167,6 +167,7 @@ fn polkadot_testnet_genesis(
|
||||
validation_upgrade_delay: 5,
|
||||
acceptance_period: 1200,
|
||||
max_code_size: 5 * 1024 * 1024,
|
||||
max_pov_size: 50 * 1024 * 1024,
|
||||
max_head_data_size: 32 * 1024,
|
||||
group_rotation_frequency: 10,
|
||||
..Default::default()
|
||||
|
||||
@@ -271,6 +271,8 @@ pub struct PersistedValidationData<N = BlockNumber> {
|
||||
/// The DMQ MQC head will be used by the validation function to authorize the downward messages
|
||||
/// passed by the collator.
|
||||
pub dmq_mqc_head: Hash,
|
||||
/// The maximum legal size of a POV block, in bytes.
|
||||
pub max_pov_size: u32,
|
||||
}
|
||||
|
||||
impl<N: Encode> PersistedValidationData<N> {
|
||||
|
||||
@@ -43,6 +43,8 @@ pub struct HostConfiguration<BlockNumber> {
|
||||
pub max_code_size: u32,
|
||||
/// The maximum head-data size, in bytes.
|
||||
pub max_head_data_size: u32,
|
||||
/// THe maximum POV block size, in bytes.
|
||||
pub max_pov_size: u32,
|
||||
/// The amount of execution cores to dedicate to parathread execution.
|
||||
pub parathread_cores: u32,
|
||||
/// The number of retries that a parathread author has to submit their block.
|
||||
@@ -172,6 +174,16 @@ decl_module! {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the max POV block size for incoming upgrades.
|
||||
#[weight = (1_000, DispatchClass::Operational)]
|
||||
pub fn set_max_pov_size(origin, new: u32) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::update_config_member(|config| {
|
||||
sp_std::mem::replace(&mut config.max_pov_size, new) != new
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the max head data size for paras.
|
||||
#[weight = (1_000, DispatchClass::Operational)]
|
||||
pub fn set_max_head_data_size(origin, new: u32) -> DispatchResult {
|
||||
@@ -484,6 +496,7 @@ mod tests {
|
||||
validation_upgrade_delay: 10,
|
||||
acceptance_period: 5,
|
||||
max_code_size: 100_000,
|
||||
max_pov_size: 1024,
|
||||
max_head_data_size: 1_000,
|
||||
parathread_cores: 2,
|
||||
parathread_retries: 5,
|
||||
@@ -524,6 +537,9 @@ mod tests {
|
||||
Configuration::set_max_code_size(
|
||||
Origin::root(), new_config.max_code_size,
|
||||
).unwrap();
|
||||
Configuration::set_max_pov_size(
|
||||
Origin::root(), new_config.max_pov_size,
|
||||
).unwrap();
|
||||
Configuration::set_max_head_data_size(
|
||||
Origin::root(), new_config.max_head_data_size,
|
||||
).unwrap();
|
||||
|
||||
@@ -28,6 +28,7 @@ use crate::{configuration, paras, dmp, hrmp};
|
||||
pub fn make_persisted_validation_data<T: paras::Trait + hrmp::Trait>(
|
||||
para_id: ParaId,
|
||||
) -> Option<PersistedValidationData<T::BlockNumber>> {
|
||||
let config = <configuration::Module<T>>::config();
|
||||
let relay_parent_number = <frame_system::Module<T>>::block_number() - One::one();
|
||||
|
||||
Some(PersistedValidationData {
|
||||
@@ -35,6 +36,7 @@ pub fn make_persisted_validation_data<T: paras::Trait + hrmp::Trait>(
|
||||
block_number: relay_parent_number,
|
||||
hrmp_mqc_heads: <hrmp::Module<T>>::hrmp_mqc_heads(para_id),
|
||||
dmq_mqc_head: <dmp::Module<T>>::dmq_mqc_head(para_id),
|
||||
max_pov_size: config.max_pov_size,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user