mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 16:55:43 +00:00
committed by
GitHub
parent
e67f31cc49
commit
251b6ca7bf
@@ -259,12 +259,7 @@ fn test_genesis_head(size: usize) -> HeadData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_validation_code(size: usize) -> ValidationCode {
|
fn test_validation_code(size: usize) -> ValidationCode {
|
||||||
let mut validation_code = vec![0u8; size as usize];
|
let validation_code = vec![0u8; size as usize];
|
||||||
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
|
|
||||||
let _ = validation_code.splice(
|
|
||||||
..crate::WASM_MAGIC.len(),
|
|
||||||
crate::WASM_MAGIC.iter().cloned(),
|
|
||||||
).collect::<Vec<_>>();
|
|
||||||
ValidationCode(validation_code)
|
ValidationCode(validation_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,10 +59,6 @@ pub use impls::ToAuthor;
|
|||||||
|
|
||||||
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
|
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
|
||||||
|
|
||||||
/// The sequence of bytes a valid wasm module binary always starts with. Apart from that it's also a
|
|
||||||
/// valid wasm module.
|
|
||||||
pub const WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
|
|
||||||
|
|
||||||
/// We assume that an on-initialize consumes 1% of the weight on average, hence a single extrinsic
|
/// We assume that an on-initialize consumes 1% of the weight on average, hence a single extrinsic
|
||||||
/// will not be allowed to consume more than `AvailableBlockRatio - 1%`.
|
/// will not be allowed to consume more than `AvailableBlockRatio - 1%`.
|
||||||
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1);
|
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1);
|
||||||
|
|||||||
@@ -160,12 +160,7 @@ impl<T: frame_system::Config> Registrar for TestRegistrar<T> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn worst_validation_code() -> ValidationCode {
|
fn worst_validation_code() -> ValidationCode {
|
||||||
let mut validation_code = vec![0u8; 1000];
|
let validation_code = vec![0u8; 1000];
|
||||||
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
|
|
||||||
let _ = validation_code.splice(
|
|
||||||
..crate::WASM_MAGIC.len(),
|
|
||||||
crate::WASM_MAGIC.iter().cloned(),
|
|
||||||
).collect::<Vec<_>>();
|
|
||||||
validation_code.into()
|
validation_code.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
//! Module to handle parathread/parachain registration and related fund management.
|
//! Module to handle parathread/parachain registration and related fund management.
|
||||||
//! In essence this is a simple wrapper around `paras`.
|
//! In essence this is a simple wrapper around `paras`.
|
||||||
|
|
||||||
use crate::WASM_MAGIC;
|
|
||||||
use sp_std::{prelude::*, result};
|
use sp_std::{prelude::*, result};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_storage, decl_module, decl_error, decl_event, ensure,
|
decl_storage, decl_module, decl_error, decl_event, ensure,
|
||||||
@@ -133,8 +132,6 @@ decl_error! {
|
|||||||
CodeTooLarge,
|
CodeTooLarge,
|
||||||
/// Invalid para head data size.
|
/// Invalid para head data size.
|
||||||
HeadDataTooLarge,
|
HeadDataTooLarge,
|
||||||
/// The validation code provided doesn't start with the Wasm file magic string.
|
|
||||||
DefinitelyNotWasm,
|
|
||||||
/// Para is not a Parachain.
|
/// Para is not a Parachain.
|
||||||
NotParachain,
|
NotParachain,
|
||||||
/// Para is not a Parathread.
|
/// Para is not a Parathread.
|
||||||
@@ -304,12 +301,7 @@ impl<T: Config> Registrar for Module<T> {
|
|||||||
fn worst_validation_code() -> ValidationCode {
|
fn worst_validation_code() -> ValidationCode {
|
||||||
// TODO: Figure a way to allow bigger wasm in benchmarks?
|
// TODO: Figure a way to allow bigger wasm in benchmarks?
|
||||||
let max_code_size = (T::MaxCodeSize::get()).min(4 * 1024 * 1024);
|
let max_code_size = (T::MaxCodeSize::get()).min(4 * 1024 * 1024);
|
||||||
let mut validation_code = vec![0u8; max_code_size as usize];
|
let validation_code = vec![0u8; max_code_size as usize];
|
||||||
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
|
|
||||||
let _ = validation_code.splice(
|
|
||||||
..crate::WASM_MAGIC.len(),
|
|
||||||
crate::WASM_MAGIC.iter().cloned(),
|
|
||||||
).collect::<Vec<_>>();
|
|
||||||
validation_code.into()
|
validation_code.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +370,6 @@ impl<T: Config> Module<T> {
|
|||||||
) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> {
|
) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> {
|
||||||
ensure!(validation_code.0.len() <= T::MaxCodeSize::get() as usize, Error::<T>::CodeTooLarge);
|
ensure!(validation_code.0.len() <= T::MaxCodeSize::get() as usize, Error::<T>::CodeTooLarge);
|
||||||
ensure!(genesis_head.0.len() <= T::MaxHeadSize::get() as usize, Error::<T>::HeadDataTooLarge);
|
ensure!(genesis_head.0.len() <= T::MaxHeadSize::get() as usize, Error::<T>::HeadDataTooLarge);
|
||||||
ensure!(validation_code.0.starts_with(WASM_MAGIC), Error::<T>::DefinitelyNotWasm);
|
|
||||||
|
|
||||||
let per_byte_fee = T::DataDepositPerByte::get();
|
let per_byte_fee = T::DataDepositPerByte::get();
|
||||||
let deposit = T::ParaDeposit::get()
|
let deposit = T::ParaDeposit::get()
|
||||||
@@ -557,12 +548,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_validation_code(size: usize) -> ValidationCode {
|
fn test_validation_code(size: usize) -> ValidationCode {
|
||||||
let mut validation_code = vec![0u8; size as usize];
|
let validation_code = vec![0u8; size as usize];
|
||||||
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
|
|
||||||
let _ = validation_code.splice(
|
|
||||||
..crate::WASM_MAGIC.len(),
|
|
||||||
crate::WASM_MAGIC.iter().cloned(),
|
|
||||||
).collect::<Vec<_>>();
|
|
||||||
ValidationCode(validation_code)
|
ValidationCode(validation_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,7 +797,7 @@ mod tests {
|
|||||||
Origin::signed(1),
|
Origin::signed(1),
|
||||||
1u32.into(),
|
1u32.into(),
|
||||||
vec![1; 3].into(),
|
vec![1; 3].into(),
|
||||||
WASM_MAGIC.to_vec().into(),
|
vec![1, 2, 3].into()
|
||||||
));
|
));
|
||||||
|
|
||||||
// 2 session changes to fully onboard.
|
// 2 session changes to fully onboard.
|
||||||
@@ -827,7 +813,7 @@ mod tests {
|
|||||||
Origin::signed(1),
|
Origin::signed(1),
|
||||||
1u32.into(),
|
1u32.into(),
|
||||||
vec![1; 3].into(),
|
vec![1; 3].into(),
|
||||||
WASM_MAGIC.to_vec().into(),
|
vec![1, 2, 3].into()
|
||||||
), Error::<Test>::AlreadyRegistered);
|
), Error::<Test>::AlreadyRegistered);
|
||||||
|
|
||||||
// By session 4, it is offboarded, and we can register again.
|
// By session 4, it is offboarded, and we can register again.
|
||||||
@@ -837,7 +823,7 @@ mod tests {
|
|||||||
Origin::signed(1),
|
Origin::signed(1),
|
||||||
1u32.into(),
|
1u32.into(),
|
||||||
vec![1; 3].into(),
|
vec![1; 3].into(),
|
||||||
WASM_MAGIC.to_vec().into(),
|
vec![1, 2, 3].into()
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
//! A simple wrapper allowing `Sudo` to call into `paras` routines.
|
//! A simple wrapper allowing `Sudo` to call into `paras` routines.
|
||||||
|
|
||||||
use crate::WASM_MAGIC;
|
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_error, decl_module, ensure,
|
decl_error, decl_module, ensure,
|
||||||
@@ -47,8 +46,6 @@ decl_error! {
|
|||||||
/// A DMP message couldn't be sent because it exceeds the maximum size allowed for a downward
|
/// A DMP message couldn't be sent because it exceeds the maximum size allowed for a downward
|
||||||
/// message.
|
/// message.
|
||||||
ExceedsMaxMessageSize,
|
ExceedsMaxMessageSize,
|
||||||
/// The validation code provided doesn't start with the Wasm file magic string.
|
|
||||||
DefinitelyNotWasm,
|
|
||||||
/// Could not schedule para cleanup.
|
/// Could not schedule para cleanup.
|
||||||
CouldntCleanup,
|
CouldntCleanup,
|
||||||
/// Not a parathread.
|
/// Not a parathread.
|
||||||
@@ -75,7 +72,6 @@ decl_module! {
|
|||||||
genesis: ParaGenesisArgs,
|
genesis: ParaGenesisArgs,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
ensure!(genesis.validation_code.0.starts_with(WASM_MAGIC), Error::<T>::DefinitelyNotWasm);
|
|
||||||
runtime_parachains::schedule_para_initialize::<T>(id, genesis).map_err(|_| Error::<T>::ParaAlreadyExists)?;
|
runtime_parachains::schedule_para_initialize::<T>(id, genesis).map_err(|_| Error::<T>::ParaAlreadyExists)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user