mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
seal: Add automated weights for contract API calls (#7017)
* seal: Add capability to put uninstrumented code (for benchmarks) Benchmarks should only measure the overhead of the API calls itself. For that reason we want to run them without instrumentation. * seal: Cap the the data length for deposited events Data used in events has storage implications for archive nodes. Those need to keep the events in storage forever. For that reason we want to limit the amount of storage that can be used inside events. * seal: Fix error reporting in the case out of bound sandbox access * seal: Refactor existing benchmarks * seal: Convert benchmark file to tabs * seal: Add benchmarks for functions called by contracts * seal: Create a default schedule from benchmark generated WeightInfo * seal: Make use of WeightInfo in extrinsic weight annotations * seal: Replace the old schedule by the benchmark generated one * Review: Fix copy paste typo in schedule construction * Review: Fix stale docs * Fix whitespace errors Co-authored-by: Sergei Shulepov <sergei@parity.io> * Review: Use checked_div in order to be more defensive * Review: Rename no_charge to already_charged * Review: Whitelist caller of extrinsics * Review: Remove trailing whitespace * Review: Remove confusing "self::" syntax * Review: Add docs for the benchmark prepration submodule * Review: Move code generation functions to own module * Review: Refactor and document benchmark helper functions * Remove additional empty line * Added missing comment on caller_funding * Update frame/contracts/src/benchmarking/code.rs Co-authored-by: Sergei Shulepov <sergei@parity.io> * Fix missing sp_std::prelude import in code.rs * cargo run --release --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml -- benchmark --chain dev --steps 50 --repeat 20 --extrinsic * --execution=wasm --wasm-execution=compiled --output ./bin/node/runtime/src/weights --header ./HEADER --pallet pallet_contracts --heap-pages 4096 * Use weights from the benchmark machine for the substrate node * Remove prefixes from Schedule members * Data lengths in the WeightInfo Trait are specified in kilobytes * Rename ApiWeights to HostFunctionWeights Co-authored-by: Sergei Shulepov <sergei@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e3682fa2f4
commit
443725f0f6
@@ -199,6 +199,7 @@ impl Trait for Test {
|
||||
type MaxDepth = MaxDepth;
|
||||
type MaxValueSize = MaxValueSize;
|
||||
type WeightPrice = Self;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
@@ -261,7 +262,7 @@ impl ExtBuilder {
|
||||
balances: vec![],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
GenesisConfig {
|
||||
current_schedule: Schedule {
|
||||
current_schedule: Schedule::<Test> {
|
||||
enable_println: true,
|
||||
..Default::default()
|
||||
},
|
||||
@@ -290,7 +291,8 @@ where
|
||||
|
||||
// Perform a call to a plain account.
|
||||
// The actual transfer fails because we can only call contracts.
|
||||
// Then we check that only the base costs are returned as actual costs.
|
||||
// Then we check that no gas was used because the base costs for calling are either charged
|
||||
// as part of the `call` extrinsic or by `seal_call`.
|
||||
#[test]
|
||||
fn calling_plain_account_fails() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
@@ -302,7 +304,7 @@ fn calling_plain_account_fails() {
|
||||
DispatchErrorWithPostInfo {
|
||||
error: Error::<Test>::NotCallable.into(),
|
||||
post_info: PostDispatchInfo {
|
||||
actual_weight: Some(67500000),
|
||||
actual_weight: Some(0),
|
||||
pays_fee: Default::default(),
|
||||
},
|
||||
}
|
||||
@@ -460,6 +462,52 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deposit_event_max_value_limit() {
|
||||
let (wasm, code_hash) = compile_module::<Test>("event_size").unwrap();
|
||||
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(50)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// Create
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
|
||||
assert_ok!(Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
30_000,
|
||||
GAS_LIMIT,
|
||||
code_hash.into(),
|
||||
vec![],
|
||||
));
|
||||
|
||||
// Check creation
|
||||
let bob_contract = ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap();
|
||||
assert_eq!(bob_contract.rent_allowance, <BalanceOf<Test>>::max_value());
|
||||
|
||||
// Call contract with allowed storage value.
|
||||
assert_ok!(Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
BOB,
|
||||
0,
|
||||
GAS_LIMIT * 2, // we are copying a huge buffer,
|
||||
<Test as Trait>::MaxValueSize::get().encode(),
|
||||
));
|
||||
|
||||
// Call contract with too large a storage value.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
BOB,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
(<Test as Trait>::MaxValueSize::get() + 1).encode(),
|
||||
),
|
||||
Error::<Test>::ValueTooLarge,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_out_of_gas() {
|
||||
let (wasm, code_hash) = compile_module::<Test>("run_out_of_gas").unwrap();
|
||||
@@ -1310,7 +1358,7 @@ fn storage_max_value_limit() {
|
||||
BOB,
|
||||
0,
|
||||
GAS_LIMIT * 2, // we are copying a huge buffer
|
||||
Encode::encode(&self::MaxValueSize::get()),
|
||||
<Test as Trait>::MaxValueSize::get().encode(),
|
||||
));
|
||||
|
||||
// Call contract with too large a storage value.
|
||||
@@ -1320,9 +1368,9 @@ fn storage_max_value_limit() {
|
||||
BOB,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
Encode::encode(&(self::MaxValueSize::get() + 1)),
|
||||
(<Test as Trait>::MaxValueSize::get() + 1).encode(),
|
||||
),
|
||||
Error::<Test>::ContractTrapped,
|
||||
Error::<Test>::ValueTooLarge,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user