mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
contracts: add seal_code_hash and seal_own_code_hash to API (#10933)
* `seal_origin` + tests added * `seal_origin` benchmark added * `seal_code_hash` + tests added * `seal_code_hash` benchmark added * `seal_own_code_hash` + tests added * `seal_own_code_hash` benchmark added * fmt lil fix * akward accident bug fix * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * benchmark fix * `WasmModule::getter()` to take `module_name` arg * test enhanced * fixes based on review feedback * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Hash left as const to return a ref to it from mock * HASH test val to local const in mock * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * fixes to benchmarks according to review feedback * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs * removed `seal_origin` from API Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
committed by
GitHub
parent
83d4be6151
commit
e4caf7388a
@@ -394,7 +394,7 @@ benchmarks! {
|
||||
seal_caller {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_caller", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_caller", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -436,6 +436,59 @@ benchmarks! {
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
|
||||
seal_code_hash {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let accounts = (0 .. r * API_BENCHMARK_BATCH_SIZE)
|
||||
.map(|n| account::<T::AccountId>("account", n, 0))
|
||||
.collect::<Vec<_>>();
|
||||
let account_len = accounts.get(0).map(|i| i.encode().len()).unwrap_or(0);
|
||||
let accounts_bytes = accounts.iter().map(|a| a.encode()).flatten().collect::<Vec<_>>();
|
||||
let accounts_len = accounts_bytes.len();
|
||||
let pages = code::max_pages::<T>();
|
||||
let code = WasmModule::<T>::from(ModuleDefinition {
|
||||
memory: Some(ImportedMemory::max::<T>()),
|
||||
imported_functions: vec![ImportedFunction {
|
||||
module: "__unstable__",
|
||||
name: "seal_code_hash",
|
||||
params: vec![ValueType::I32, ValueType::I32, ValueType::I32],
|
||||
return_type: Some(ValueType::I32),
|
||||
}],
|
||||
data_segments: vec![
|
||||
DataSegment {
|
||||
offset: 0,
|
||||
value: 32u32.to_le_bytes().to_vec(), // output length
|
||||
},
|
||||
DataSegment {
|
||||
offset: 36,
|
||||
value: accounts_bytes,
|
||||
},
|
||||
],
|
||||
call_body: Some(body::repeated_dyn(r * API_BENCHMARK_BATCH_SIZE, vec![
|
||||
Counter(36, account_len as u32), // address_ptr
|
||||
Regular(Instruction::I32Const(4)), // ptr to output data
|
||||
Regular(Instruction::I32Const(0)), // ptr to output length
|
||||
Regular(Instruction::Call(0)),
|
||||
Regular(Instruction::Drop),
|
||||
])),
|
||||
.. Default::default()
|
||||
});
|
||||
let instance = Contract::<T>::new(code, vec![])?;
|
||||
let info = instance.info()?;
|
||||
// every account would be a contract (worst case)
|
||||
for acc in accounts.iter() {
|
||||
<ContractInfoOf<T>>::insert(acc, info.clone());
|
||||
}
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
|
||||
seal_own_code_hash {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"__unstable__", "seal_own_code_hash", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
|
||||
seal_caller_is_origin {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let code = WasmModule::<T>::from(ModuleDefinition {
|
||||
@@ -459,7 +512,7 @@ benchmarks! {
|
||||
seal_address {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_address", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_address", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -467,7 +520,7 @@ benchmarks! {
|
||||
seal_gas_left {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_gas_left", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_gas_left", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -475,7 +528,7 @@ benchmarks! {
|
||||
seal_balance {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_balance", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_balance", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -483,7 +536,7 @@ benchmarks! {
|
||||
seal_value_transferred {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_value_transferred", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_value_transferred", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -491,7 +544,7 @@ benchmarks! {
|
||||
seal_minimum_balance {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_minimum_balance", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_minimum_balance", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -499,7 +552,7 @@ benchmarks! {
|
||||
seal_block_number {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_block_number", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_block_number", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -507,7 +560,7 @@ benchmarks! {
|
||||
seal_now {
|
||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||
let instance = Contract::<T>::new(WasmModule::getter(
|
||||
"seal_now", r * API_BENCHMARK_BATCH_SIZE
|
||||
"seal0", "seal_now", r * API_BENCHMARK_BATCH_SIZE
|
||||
), vec![])?;
|
||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||
@@ -2341,7 +2394,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
// w_memory_grow = w_bench - 2 * w_param
|
||||
// We can only allow allocate as much memory as it is allowed in a a contract.
|
||||
// We can only allow allocate as much memory as it is allowed in a contract.
|
||||
// Therefore the repeat count is limited by the maximum memory any contract can have.
|
||||
// Using a contract with more memory will skew the benchmark because the runtime of grow
|
||||
// depends on how much memory is already allocated.
|
||||
|
||||
Reference in New Issue
Block a user