seal: Add benchmarks for dispatchables (#6715)

* seal: Fix syntax that confuses rust-analyzer

* seal: Add benchmarks for Dispatchables

These are only the benchmarks for the dispatchables of
the pallet. Those are not listed in the Schedule because
we do not want to pull the Schedule from storage before
dispatching.

This OK because those costs are not related to actual contract
execution. Those costs (instruction costs, ext_* costs) will
be benchmarked seperatly and entered into the default Schedule.

* seal: Add a maximum code size

* Fix comments from review

* Removed SEED constant
This commit is contained in:
Alexander Theißen
2020-07-29 12:32:27 +02:00
committed by GitHub
parent e7d8040af8
commit a2163420f4
10 changed files with 315 additions and 23 deletions
+11 -2
View File
@@ -85,6 +85,7 @@ mod storage;
mod exec;
mod wasm;
mod rent;
mod benchmarking;
#[cfg(test)]
mod tests;
@@ -107,7 +108,7 @@ use sp_runtime::{
RuntimeDebug,
};
use frame_support::{
decl_module, decl_event, decl_storage, decl_error,
decl_module, decl_event, decl_storage, decl_error, ensure,
parameter_types, storage::child::ChildInfo,
dispatch::{DispatchResult, DispatchResultWithPostInfo},
traits::{OnUnbalanced, Currency, Get, Time, Randomness},
@@ -420,6 +421,8 @@ decl_error! {
/// for a tombstone to be created. Use `ext_terminate` to remove a contract without
/// leaving a tombstone behind.
InsufficientBalance,
/// The code supplied to `put_code` exceeds the limit specified in the current schedule.
CodeTooLarge,
}
}
@@ -495,6 +498,7 @@ decl_module! {
) -> DispatchResult {
ensure_signed(origin)?;
let schedule = <Module<T>>::current_schedule();
ensure!(code.len() as u32 <= schedule.max_code_size, Error::<T>::CodeTooLarge);
let result = wasm::save_code::<T>(code, &schedule);
if let Ok(code_hash) = result {
Self::deposit_event(RawEvent::CodeStored(code_hash));
@@ -619,7 +623,7 @@ impl<T: Trait> Module<T> {
address: T::AccountId,
key: [u8; 32],
) -> sp_std::result::Result<Option<Vec<u8>>, ContractAccessError> {
let contract_info = <ContractInfoOf<T>>::get(&address)
let contract_info = ContractInfoOf::<T>::get(&address)
.ok_or(ContractAccessError::DoesntExist)?
.get_alive()
.ok_or(ContractAccessError::IsTombstone)?;
@@ -826,6 +830,10 @@ pub struct Schedule {
/// The maximum length of a subject used for PRNG generation.
pub max_subject_len: u32,
/// The maximum length of a contract code in bytes. This limit applies to the uninstrumented
// and pristine form of the code as supplied to `put_code`.
pub max_code_size: u32,
}
// 500 (2 instructions per nano second on 2GHZ) * 1000x slowdown through wasmi
@@ -857,6 +865,7 @@ impl Default for Schedule {
max_table_size: 16 * 1024,
enable_println: false,
max_subject_len: 32,
max_code_size: 512 * 1024,
}
}
}