mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 11:41:02 +00:00
Contracts Add deposit for dependencies (#14079)
* wip * fixes * rm comment * join fns * clippy * Fix limits * reduce diff * fix * fix * fix typo * refactor store to use self * refactor run to take self by value * pass tests * rm comment * fixes * fix typo * rm * fix fmt * clippy * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * Update frame/contracts/src/lib.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/wasm/mod.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/wasm/mod.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * PR review, rm duplicate increment_refcount * PR review * Update frame/contracts/src/wasm/prepare.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Add test for failing storage_deposit * fix lint * wip * Delegate update take 2 * update * fix migration * fix migration * doc * fix lint * update migration * fix warning * reformat comment * regenerate weightInfo trait * fix merge * PR review https://github.com/paritytech/substrate/pull/14079#discussion_r1255904563 * PR review https://github.com/paritytech/substrate/pull/14079/files#r1257521373 * PR review remove optimisation https://github.com/paritytech/substrate/pull/14079/files#r1263312237 * PR review fix return type https://github.com/paritytech/substrate/pull/14079/files#r1263315804 * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * PR review pass CodeInfo and update docstring https://github.com/paritytech/substrate/pull/14079/files#r1257522327 * PR review add code_info to the executable https://github.com/paritytech/substrate/pull/14079/files#r1263309049 * rename info -> contract_info * Update frame/contracts/src/exec.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Update frame/contracts/fixtures/add_remove_delegate_dependency.wat Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Update frame/contracts/src/migration/v13.rs * fix tests * Fmt & fix tests * Test Result<(), _> return type * Update frame/contracts/src/migration.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Revert "Test Result<(), _> return type" This reverts commit a876168f2054edf84d720c666387583ccbe78dcd. * add / update doc comments * fix backticks * Revert "Revert "Test Result<(), _> return type"" This reverts commit 3cbb6161d1abd9520cd9f8519b4dfbf4f29a2998. * fix bench * fix bench * fix * Update frame/contracts/src/storage/meter.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * rm stale comments * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * PR suggestion * Add missing doc * fx lint * ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_contracts * Update frame/contracts/src/lib.rs Co-authored-by: Juan <juangirini@gmail.com> --------- Co-authored-by: command-bot <> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: Juan <juangirini@gmail.com>
This commit is contained in:
@@ -30,7 +30,7 @@ use self::{
|
||||
};
|
||||
use crate::{
|
||||
exec::{AccountIdOf, Key},
|
||||
migration::{v09, v10, v11, v12, MigrationStep},
|
||||
migration::{v09, v10, v11, v12, v13, MigrationStep},
|
||||
wasm::CallFlags,
|
||||
Pallet as Contracts, *,
|
||||
};
|
||||
@@ -257,6 +257,19 @@ benchmarks! {
|
||||
m.step();
|
||||
}
|
||||
|
||||
// This benchmarks the v13 migration step (Add delegate_dependencies field).
|
||||
#[pov_mode = Measured]
|
||||
v13_migration_step {
|
||||
let contract = <Contract<T>>::with_caller(
|
||||
whitelisted_caller(), WasmModule::dummy(), vec![],
|
||||
)?;
|
||||
|
||||
v13::store_old_contract_info::<T>(contract.account_id.clone(), contract.info()?);
|
||||
let mut m = v13::Migration::<T>::default();
|
||||
}: {
|
||||
m.step();
|
||||
}
|
||||
|
||||
// This benchmarks the weight of executing Migration::migrate to execute a noop migration.
|
||||
#[pov_mode = Measured]
|
||||
migration_noop {
|
||||
@@ -832,20 +845,48 @@ benchmarks! {
|
||||
let beneficiary = account::<T::AccountId>("beneficiary", 0, 0);
|
||||
let beneficiary_bytes = beneficiary.encode();
|
||||
let beneficiary_len = beneficiary_bytes.len();
|
||||
|
||||
// Maximize the delegate_dependencies to account for the worst-case scenario.
|
||||
let code_hashes = (0..T::MaxDelegateDependencies::get())
|
||||
.map(|i| {
|
||||
let new_code = WasmModule::<T>::dummy_with_bytes(65 + i);
|
||||
Contracts::<T>::store_code_raw(new_code.code, whitelisted_caller())?;
|
||||
Ok(new_code.hash)
|
||||
})
|
||||
.collect::<Result<Vec<_>, &'static str>>()?;
|
||||
let code_hash_len = code_hashes.get(0).map(|x| x.encode().len()).unwrap_or(0);
|
||||
let code_hashes_bytes = code_hashes.iter().flat_map(|x| x.encode()).collect::<Vec<_>>();
|
||||
|
||||
let code = WasmModule::<T>::from(ModuleDefinition {
|
||||
memory: Some(ImportedMemory::max::<T>()),
|
||||
imported_functions: vec![ImportedFunction {
|
||||
module: "seal0",
|
||||
name: "seal_terminate",
|
||||
params: vec![ValueType::I32, ValueType::I32],
|
||||
return_type: None,
|
||||
}],
|
||||
imported_functions: vec![
|
||||
ImportedFunction {
|
||||
module: "seal0",
|
||||
name: "seal_terminate",
|
||||
params: vec![ValueType::I32, ValueType::I32],
|
||||
return_type: None,
|
||||
},
|
||||
ImportedFunction {
|
||||
module: "seal0",
|
||||
name: "add_delegate_dependency",
|
||||
params: vec![ValueType::I32],
|
||||
return_type: None,
|
||||
}
|
||||
],
|
||||
data_segments: vec![
|
||||
DataSegment {
|
||||
offset: 0,
|
||||
value: beneficiary_bytes,
|
||||
},
|
||||
DataSegment {
|
||||
offset: beneficiary_len as u32,
|
||||
value: code_hashes_bytes,
|
||||
},
|
||||
],
|
||||
deploy_body: Some(body::repeated_dyn(r, vec![
|
||||
Counter(beneficiary_len as u32, code_hash_len as u32), // code_hash_ptr
|
||||
Regular(Instruction::Call(1)),
|
||||
])),
|
||||
call_body: Some(body::repeated(r, &[
|
||||
Instruction::I32Const(0), // beneficiary_ptr
|
||||
Instruction::I32Const(beneficiary_len as i32), // beneficiary_len
|
||||
@@ -2327,6 +2368,89 @@ benchmarks! {
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
|
||||
#[pov_mode = Measured]
|
||||
add_delegate_dependency {
|
||||
let r in 0 .. T::MaxDelegateDependencies::get();
|
||||
let code_hashes = (0..r)
|
||||
.map(|i| {
|
||||
let new_code = WasmModule::<T>::dummy_with_bytes(65 + i);
|
||||
Contracts::<T>::store_code_raw(new_code.code, whitelisted_caller())?;
|
||||
Ok(new_code.hash)
|
||||
})
|
||||
.collect::<Result<Vec<_>, &'static str>>()?;
|
||||
let code_hash_len = code_hashes.get(0).map(|x| x.encode().len()).unwrap_or(0);
|
||||
let code_hashes_bytes = code_hashes.iter().flat_map(|x| x.encode()).collect::<Vec<_>>();
|
||||
|
||||
let code = WasmModule::<T>::from(ModuleDefinition {
|
||||
memory: Some(ImportedMemory::max::<T>()),
|
||||
imported_functions: vec![ImportedFunction {
|
||||
module: "seal0",
|
||||
name: "add_delegate_dependency",
|
||||
params: vec![ValueType::I32],
|
||||
return_type: None,
|
||||
}],
|
||||
data_segments: vec![
|
||||
DataSegment {
|
||||
offset: 0,
|
||||
value: code_hashes_bytes,
|
||||
},
|
||||
],
|
||||
call_body: Some(body::repeated_dyn(r, vec![
|
||||
Counter(0, code_hash_len as u32), // code_hash_ptr
|
||||
Regular(Instruction::Call(0)),
|
||||
])),
|
||||
.. Default::default()
|
||||
});
|
||||
let instance = Contract::<T>::new(code, vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
|
||||
remove_delegate_dependency {
|
||||
let r in 0 .. T::MaxDelegateDependencies::get();
|
||||
let code_hashes = (0..r)
|
||||
.map(|i| {
|
||||
let new_code = WasmModule::<T>::dummy_with_bytes(65 + i);
|
||||
Contracts::<T>::store_code_raw(new_code.code, whitelisted_caller())?;
|
||||
Ok(new_code.hash)
|
||||
})
|
||||
.collect::<Result<Vec<_>, &'static str>>()?;
|
||||
|
||||
let code_hash_len = code_hashes.get(0).map(|x| x.encode().len()).unwrap_or(0);
|
||||
let code_hashes_bytes = code_hashes.iter().flat_map(|x| x.encode()).collect::<Vec<_>>();
|
||||
|
||||
let code = WasmModule::<T>::from(ModuleDefinition {
|
||||
memory: Some(ImportedMemory::max::<T>()),
|
||||
imported_functions: vec![ImportedFunction {
|
||||
module: "seal0",
|
||||
name: "remove_delegate_dependency",
|
||||
params: vec![ValueType::I32],
|
||||
return_type: None,
|
||||
}, ImportedFunction {
|
||||
module: "seal0",
|
||||
name: "add_delegate_dependency",
|
||||
params: vec![ValueType::I32],
|
||||
return_type: None
|
||||
}],
|
||||
data_segments: vec![
|
||||
DataSegment {
|
||||
offset: 0,
|
||||
value: code_hashes_bytes,
|
||||
},
|
||||
],
|
||||
deploy_body: Some(body::repeated_dyn(r, vec![
|
||||
Counter(0, code_hash_len as u32), // code_hash_ptr
|
||||
Regular(Instruction::Call(1)),
|
||||
])),
|
||||
call_body: Some(body::repeated_dyn(r, vec![
|
||||
Counter(0, code_hash_len as u32), // code_hash_ptr
|
||||
Regular(Instruction::Call(0)),
|
||||
])),
|
||||
.. Default::default()
|
||||
});
|
||||
let instance = Contract::<T>::new(code, vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
|
||||
#[pov_mode = Measured]
|
||||
seal_reentrance_count {
|
||||
let r in 0 .. API_BENCHMARK_RUNS;
|
||||
|
||||
Reference in New Issue
Block a user