contracts: Expose rent parameter to contracts (#8231)

* contracts: Expose rent parameter to contracts

* cargo run --release --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

* Fix typos

* Improve comments

* Add rent parameter weights

* Allow deploying a new schedule with the same version

* Add storage migration for new schedule

* Only decode the schedule version in storage migration

* Remove confusing docs

* Replace original_code_len() by aggregate_code_len()

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
This commit is contained in:
Alexander Theißen
2021-03-12 12:21:08 +01:00
committed by GitHub
parent 3743cec9bd
commit a4e8875897
11 changed files with 1129 additions and 698 deletions
@@ -215,6 +215,8 @@ pub enum RuntimeToken {
ChainExtension(u64),
/// Weight charged for copying data from the sandbox.
CopyIn(u32),
/// Weight of calling `seal_rent_params`.
RentParams,
}
impl<T: Config> Token<T> for RuntimeToken
@@ -283,6 +285,7 @@ where
.saturating_add(s.hash_blake2_128_per_byte.saturating_mul(len.into())),
ChainExtension(amount) => amount,
CopyIn(len) => s.return_per_byte.saturating_mul(len.into()),
RentParams => s.rent_params,
}
}
}
@@ -1513,4 +1516,25 @@ define_env!(Env, <E: Ext>,
})),
}
},
// Stores the rent params 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 [`crate::exec::RentParams`].
//
// # Note
//
// The returned information was collected and cached when the current contract call
// started execution. Any change to those values that happens due to actions of the
// current call or contracts that are called by this contract are not considered.
seal_rent_params(ctx, out_ptr: u32, out_len_ptr: u32) => {
ctx.charge_gas(RuntimeToken::RentParams)?;
Ok(ctx.write_sandbox_output(
out_ptr, out_len_ptr, &ctx.ext.rent_params().encode(), false, already_charged
)?)
},
);