Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eacb017
added [unstable][seal2] call()
agryaznov Mar 7, 2023
b3c9265
updated test to cover new seal_call proof_limit
agryaznov Mar 7, 2023
e226add
docs updated
agryaznov Mar 7, 2023
aba8782
add [seal2][unstable] instantiate() and test
agryaznov Mar 7, 2023
53d8fde
add [seal2][unstable] weight_to_fee() + docs and test
agryaznov Mar 7, 2023
09d1df6
add [seal2][unstable] gas_left() + docs and test
agryaznov Mar 8, 2023
c644fa1
update benchmarks
agryaznov Mar 8, 2023
2cb30c7
add DefaultDepositLimit to pallet Config
agryaznov Mar 8, 2023
a968b29
specify deposit limit for nested call
agryaznov Mar 9, 2023
45b48c2
specify deposit limit for nested instantiate
agryaznov Mar 13, 2023
ec58346
Merge branch 'master' into ag-proof_limit
agryaznov Mar 14, 2023
edf1aac
update benchmarks
agryaznov Mar 14, 2023
2bfb866
added missing fixtures
agryaznov Mar 16, 2023
1ff3f16
fix benches
agryaznov Mar 16, 2023
b0f3103
pass explicit deposit limit to storage bench
agryaznov Mar 16, 2023
3af8712
explicit deposit limit for another set_storage bench
agryaznov Mar 16, 2023
825a6bc
add more deposit limit for storage benches
agryaznov Mar 16, 2023
8f9ea17
moving to simplified benchmarks
agryaznov Mar 16, 2023
6ac5355
Merge branch 'master' into ag-proof_limit
agryaznov Mar 16, 2023
04ead1b
moved to simplified benchmarks
agryaznov Mar 16, 2023
7d1023d
fix seal_weight_to_fee bench
agryaznov Mar 16, 2023
8e6c6d2
fix seal_instantiate benchmark
agryaznov Mar 16, 2023
d618957
Merge branch 'master' into ag-proof_limit
agryaznov Mar 30, 2023
16f0994
doc typo fix
agryaznov Mar 31, 2023
24dcd0e
default dl for benchmarking
agryaznov Mar 31, 2023
d7eab4a
max_runtime_mem to Schedule limits
agryaznov Apr 3, 2023
91fd102
Merge branch 'master' into ag-proof_limit
agryaznov Apr 3, 2023
af1b353
add default deposit limit fallback check to test
agryaznov Apr 12, 2023
04bea78
weight params renaming
agryaznov Apr 12, 2023
c01f166
Merge branch 'master' into ag-proof_limit
agryaznov Apr 12, 2023
50c96da
fmt
agryaznov Apr 12, 2023
95c83ea
Update frame/contracts/src/benchmarking/mod.rs
agryaznov Apr 25, 2023
22c5794
prettify inputs in tests
agryaznov Apr 25, 2023
418aa50
Merge branch 'ag-proof_limit' of github.com:paritytech/substrate into…
agryaznov Apr 25, 2023
0dac6f6
typestate param refactored
agryaznov Apr 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add [seal2][unstable] gas_left() + docs and test
  • Loading branch information
agryaznov committed Mar 8, 2023
commit 09d1df6deb32b6e733c1dc255fd4a1fd9a5259ac
41 changes: 21 additions & 20 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ mod tests {
};
use assert_matches::assert_matches;
use frame_support::{
assert_err, assert_ok,
dispatch::DispatchResultWithPostInfo,
weights::{OldWeight, Weight},
assert_err, assert_ok, dispatch::DispatchResultWithPostInfo, weights::Weight,
};
use pallet_contracts_primitives::{ExecReturnValue, ReturnFlags};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -615,8 +613,11 @@ mod tests {
16_384
}
fn get_weight_price(&self, weight: Weight) -> BalanceOf<Self::T> {
BalanceOf::<Self::T>::from(1312_u32).saturating_mul(weight.ref_time().into()).saturating_add(
BalanceOf::<Self::T>::from(103_u32).saturating_mul(weight.proof_size()))
BalanceOf::<Self::T>::from(1312_u32)
.saturating_mul(weight.ref_time().into())
.saturating_add(
BalanceOf::<Self::T>::from(103_u32).saturating_mul(weight.proof_size()),
)
}
fn schedule(&self) -> &Schedule<Self::T> {
&self.schedule
Expand Down Expand Up @@ -1617,12 +1618,12 @@ mod tests {

const CODE_GAS_LEFT: &str = r#"
(module
(import "seal0" "seal_gas_left" (func $seal_gas_left (param i32 i32)))
(import "seal1" "gas_left" (func $seal_gas_left (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

;; size of our buffer is 32 bytes
(data (i32.const 32) "\20")
;; Make output buffer size 20 bytes
(data (i32.const 20) "\14")

(func $assert (param i32)
(block $ok
Expand All @@ -1634,19 +1635,19 @@ mod tests {
)

(func (export "call")
;; This stores the gas left in the buffer
(call $seal_gas_left (i32.const 0) (i32.const 32))
;; This stores the weight left to the buffer
(call $seal_gas_left (i32.const 0) (i32.const 20))

;; assert len == 8
;; Assert len <= 16 (max encoded Weight len)
(call $assert
(i32.eq
(i32.load (i32.const 32))
(i32.const 8)
(i32.le_u
(i32.load (i32.const 20))
(i32.const 16)
)
)

;; return gas left
(call $seal_return (i32.const 0) (i32.const 0) (i32.const 8))
;; Return weight left and its encoded value len
(call $seal_return (i32.const 0) (i32.const 0) (i32.load (i32.const 20)))

(unreachable)
)
Expand All @@ -1661,11 +1662,11 @@ mod tests {

let output = execute(CODE_GAS_LEFT, vec![], &mut ext).unwrap();

let OldWeight(gas_left) = OldWeight::decode(&mut &*output.data).unwrap();
let weight_left = Weight::decode(&mut &*output.data).unwrap();
let actual_left = ext.gas_meter.gas_left();
// TODO: account for proof size weight
assert!(gas_left < gas_limit.ref_time(), "gas_left must be less than initial");
assert!(gas_left > actual_left.ref_time(), "gas_left must be greater than final");

assert!(weight_left.all_lt(gas_limit), "gas_left must be less than initial");
assert!(weight_left.all_gt(actual_left), "gas_left must be greater than final");
}

const CODE_VALUE_TRANSFERRED: &str = r#"
Expand Down
32 changes: 26 additions & 6 deletions frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1909,30 +1909,50 @@ pub mod env {
out_ptr: u32,
out_len_ptr: u32,
) -> Result<(), TrapReason> {
let gas = Weight::from_parts(ref_time, proof_limit);
let weight = Weight::from_parts(ref_time, proof_limit);
ctx.charge_gas(RuntimeCosts::WeightToFee)?;
Ok(ctx.write_sandbox_output(
memory,
out_ptr,
out_len_ptr,
&ctx.ext.get_weight_price(gas).encode(),
&ctx.ext.get_weight_price(weight).encode(),
false,
already_charged,
)?)
}

/// Stores the weight left into the supplied buffer.
///
/// Equivalent to the newer [`seal1`][`super::api_doc::Version2::gas_left`] version but
/// works with *ref_time* Weight only. It is recommended to switch to the latest version, once
/// it's stabilized.
#[prefixed_alias]
fn gas_left(ctx: _, memory: _, out_ptr: u32, out_len_ptr: u32) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::GasLeft)?;
let gas_left = &ctx.ext.gas_meter().gas_left().ref_time().encode();
Ok(ctx.write_sandbox_output(
memory,
out_ptr,
out_len_ptr,
gas_left,
false,
already_charged,
)?)
}

/// Stores the amount of gas left into the supplied buffer.
/// Stores the amount of weight left into the supplied buffer.
///
/// The value is stored to linear memory at the address pointed to by `out_ptr`.
/// `out_len_ptr` must point to a u32 value that describes the available space at
/// `out_ptr`. This call overwrites it with the size of the value. If the available
/// space at `out_ptr` is less than the size of the value a trap is triggered.
///
/// The data is encoded as Gas.
#[prefixed_alias]
/// The data is encoded as Weight.
#[version(1)]
#[unstable]
fn gas_left(ctx: _, memory: _, out_ptr: u32, out_len_ptr: u32) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::GasLeft)?;
let gas_left = &ctx.ext.gas_meter().gas_left().ref_time().encode();
let gas_left = &ctx.ext.gas_meter().gas_left().encode();
Ok(ctx.write_sandbox_output(
memory,
out_ptr,
Expand Down