Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
407920b
seal: Add capability to put uninstrumented code (for benchmarks)
athei Jul 31, 2020
343f0fb
seal: Cap the the data length for deposited events
athei Aug 19, 2020
1235f26
seal: Fix error reporting in the case out of bound sandbox access
athei Aug 27, 2020
ec69d05
seal: Refactor existing benchmarks
athei Aug 3, 2020
b1a1133
seal: Convert benchmark file to tabs
athei Aug 5, 2020
dfa6076
seal: Add benchmarks for functions called by contracts
athei Aug 10, 2020
2cbe472
seal: Create a default schedule from benchmark generated WeightInfo
athei Aug 31, 2020
1e065cf
seal: Make use of WeightInfo in extrinsic weight annotations
athei Sep 1, 2020
c680745
seal: Replace the old schedule by the benchmark generated one
athei Sep 1, 2020
0132ede
Merge branch 'master' into at-seal-api-benchmarks
athei Sep 23, 2020
ca7742d
Review: Fix copy paste typo in schedule construction
athei Sep 23, 2020
cdec9ae
Review: Fix stale docs
athei Sep 23, 2020
0a2bd2a
Fix whitespace errors
athei Sep 23, 2020
771bf8a
Review: Use checked_div in order to be more defensive
athei Sep 23, 2020
a326fac
Merge branch 'master' into at-seal-api-benchmarks
athei Sep 24, 2020
d76bcde
Review: Rename no_charge to already_charged
athei Sep 24, 2020
b3aa6ac
Review: Whitelist caller of extrinsics
athei Sep 24, 2020
678f155
Review: Remove trailing whitespace
athei Sep 24, 2020
190144e
Review: Remove confusing "self::" syntax
athei Sep 24, 2020
dd2edeb
Review: Add docs for the benchmark prepration submodule
athei Sep 24, 2020
4e65609
Review: Move code generation functions to own module
athei Sep 24, 2020
687c2a5
Review: Refactor and document benchmark helper functions
athei Sep 24, 2020
b42e400
Remove additional empty line
athei Sep 24, 2020
56b8d31
Added missing comment on caller_funding
athei Sep 24, 2020
a7d3da1
Update frame/contracts/src/benchmarking/code.rs
athei Sep 24, 2020
09766bb
Fix missing sp_std::prelude import in code.rs
athei Sep 25, 2020
c54fa98
Merge branch 'master' into at-seal-api-benchmarks
athei Sep 25, 2020
9d1c66b
Merge remote-tracking branch 'origin/master' into at-seal-api-benchmarks
shawntabrizi Oct 6, 2020
e565433
cargo run --release --features runtime-benchmarks --manifest-path bin…
shawntabrizi Oct 6, 2020
036a8ba
Use weights from the benchmark machine for the substrate node
athei Oct 6, 2020
2c154dd
Remove prefixes from Schedule members
athei Oct 7, 2020
6f2f333
Data lengths in the WeightInfo Trait are specified in kilobytes
athei Oct 7, 2020
51a8c38
Rename ApiWeights to HostFunctionWeights
athei Oct 8, 2020
94a08b5
Merge branch 'master' into at-seal-api-benchmarks
athei Oct 8, 2020
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
Review: Rename no_charge to already_charged
  • Loading branch information
athei committed Sep 24, 2020
commit d76bcde664c15694e37e4ba56f580bde4cc89944
41 changes: 24 additions & 17 deletions frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ fn write_sandbox_memory<E: Ext>(
/// length of the buffer located at `out_ptr`. If that buffer is large enough the actual
/// `buf.len()` is written to this location.
///
/// If `out_ptr` is set to the sentinel value of `u32::max_value()` and `allow_skip` is true the
/// If `out_ptr` is set to the sentinel value of `u32::max_value()` and `allow_skip` is true the
/// operation is skipped and `Ok` is returned. This is supposed to help callers to make copying
/// output optional. For example to skip copying back the output buffer of an `seal_call`
/// when the caller is not interested in the result.
Expand Down Expand Up @@ -457,9 +457,12 @@ fn write_sandbox_output<E: Ext>(
Ok(())
}

/// Can be supplied to `write_sandbox_output` to indicate that the gas meter is not be
/// be charged for the copied data.
fn no_charge(_: u32) -> Option<RuntimeToken> {
/// Supply to `write_sandbox_output` to indicate that the gas meter should not be charged.
///
/// This is only appropriate when writing out data of constant size that does not depend on user
/// input. In this case the costs for this copy was already charged as part of the token at
/// the beginning of the API entry point.
fn already_charged(_: u32) -> Option<RuntimeToken> {
None
}

Expand Down Expand Up @@ -833,7 +836,7 @@ define_env!(Env, <E: Ext>,
if let Ok((address, output)) = &instantiate_outcome {
if !output.flags.contains(ReturnFlags::REVERT) {
write_sandbox_output(
ctx, address_ptr, address_len_ptr, &address.encode(), true, no_charge,
ctx, address_ptr, address_len_ptr, &address.encode(), true, already_charged,
)?;
}
write_sandbox_output(ctx, output_ptr, output_len_ptr, &output.data, true, |len| {
Expand Down Expand Up @@ -926,7 +929,7 @@ define_env!(Env, <E: Ext>,
seal_caller(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::Caller)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.caller().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.caller().encode(), false, already_charged
)
},

Expand All @@ -939,7 +942,7 @@ define_env!(Env, <E: Ext>,
seal_address(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::Address)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.address().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.address().encode(), false, already_charged
)
},

Expand All @@ -959,7 +962,8 @@ define_env!(Env, <E: Ext>,
seal_weight_to_fee(ctx, gas: u64, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::WeightToFee)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.get_weight_price(gas).encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.get_weight_price(gas).encode(), false,
already_charged
)
},

Expand All @@ -974,7 +978,7 @@ define_env!(Env, <E: Ext>,
seal_gas_left(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::GasLeft)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.gas_meter.gas_left().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.gas_meter.gas_left().encode(), false, already_charged
)
},

Expand All @@ -989,7 +993,7 @@ define_env!(Env, <E: Ext>,
seal_balance(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::Balance)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.balance().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.balance().encode(), false, already_charged
)
},

Expand All @@ -1004,7 +1008,8 @@ define_env!(Env, <E: Ext>,
seal_value_transferred(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::ValueTransferred)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.value_transferred().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.value_transferred().encode(), false,
already_charged
)
},

Expand All @@ -1024,7 +1029,8 @@ define_env!(Env, <E: Ext>,
}
let subject_buf = read_sandbox_memory(ctx, subject_ptr, subject_len)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.random(&subject_buf).encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.random(&subject_buf).encode(), false,
already_charged
)
},

Expand All @@ -1037,7 +1043,7 @@ define_env!(Env, <E: Ext>,
seal_now(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::Now)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.now().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.now().encode(), false, already_charged
)
},

Expand All @@ -1047,7 +1053,7 @@ define_env!(Env, <E: Ext>,
seal_minimum_balance(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::MinimumBalance)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.minimum_balance().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.minimum_balance().encode(), false, already_charged
)
},

Expand All @@ -1069,7 +1075,8 @@ define_env!(Env, <E: Ext>,
seal_tombstone_deposit(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::TombstoneDeposit)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.tombstone_deposit().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.tombstone_deposit().encode(), false,
already_charged
)
},

Expand Down Expand Up @@ -1215,7 +1222,7 @@ define_env!(Env, <E: Ext>,
seal_rent_allowance(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::RentAllowance)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.rent_allowance().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.rent_allowance().encode(), false, already_charged
)
},

Expand All @@ -1239,7 +1246,7 @@ define_env!(Env, <E: Ext>,
seal_block_number(ctx, out_ptr: u32, out_len_ptr: u32) => {
charge_gas(ctx, RuntimeToken::BlockNumber)?;
write_sandbox_output(
ctx, out_ptr, out_len_ptr, &ctx.ext.block_number().encode(), false, no_charge
ctx, out_ptr, out_len_ptr, &ctx.ext.block_number().encode(), false, already_charged
)
},

Expand Down