mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Introduce a maximum code size and head data size (#835)
* add a maximum code size and head data size * get existing tests passing * add tests for slots logic * test registrar behavior * introduce maximums and bump versions * address review grumbles * work around publicizing derive * remove unneeded and wrong doc
This commit is contained in:
committed by
GitHub
parent
9b23f3f1f0
commit
295151338d
@@ -129,6 +129,14 @@ pub trait Trait: attestations::Trait {
|
||||
|
||||
/// The way that we are able to register parachains.
|
||||
type Registrar: Registrar<Self::AccountId>;
|
||||
|
||||
/// Maximum code size for parachains, in bytes. Note that this is not
|
||||
/// the entire storage burden of the parachain, as old code is stored for
|
||||
/// `SlashPeriod` blocks.
|
||||
type MaxCodeSize: Get<u32>;
|
||||
|
||||
/// Max head data size.
|
||||
type MaxHeadDataSize: Get<u32>;
|
||||
}
|
||||
|
||||
/// Origin for the parachains module.
|
||||
@@ -233,6 +241,8 @@ decl_error! {
|
||||
UntaggedVotes,
|
||||
/// Wrong parent head for parachain receipt.
|
||||
ParentMismatch,
|
||||
/// Head data was too large.
|
||||
HeadDataTooLarge,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,6 +788,8 @@ impl<T: Trait> Module<T> {
|
||||
let mut validator_groups = GroupedDutyIter::new(&sorted_validators[..]);
|
||||
|
||||
let mut para_block_hashes = Vec::new();
|
||||
|
||||
let max_head_data_size = T::MaxHeadDataSize::get();
|
||||
for candidate in attested_candidates {
|
||||
let para_id = candidate.parachain_index();
|
||||
let validator_group = validator_groups.group_for(para_id)
|
||||
@@ -801,6 +813,11 @@ impl<T: Trait> Module<T> {
|
||||
Error::<T>::VotesExceedsAuthorities,
|
||||
);
|
||||
|
||||
ensure!(
|
||||
max_head_data_size >= candidate.candidate().head_data.0.len() as _,
|
||||
Error::<T>::HeadDataTooLarge,
|
||||
);
|
||||
|
||||
let fees = candidate.candidate().fees;
|
||||
T::ParachainCurrency::deduct(para_id, fees)?;
|
||||
|
||||
@@ -1152,6 +1169,11 @@ mod tests {
|
||||
type MaxRetries = MaxRetries;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxHeadDataSize: u32 = 100;
|
||||
pub const MaxCodeSize: u32 = 100;
|
||||
}
|
||||
|
||||
impl Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
@@ -1159,6 +1181,8 @@ mod tests {
|
||||
type Randomness = RandomnessCollectiveFlip;
|
||||
type ActiveParachains = registrar::Module<Test>;
|
||||
type Registrar = registrar::Module<Test>;
|
||||
type MaxCodeSize = MaxCodeSize;
|
||||
type MaxHeadDataSize = MaxHeadDataSize;
|
||||
}
|
||||
|
||||
type Parachains = Module<Test>;
|
||||
|
||||
Reference in New Issue
Block a user