mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 11:15:47 +00:00
[contracts] stabilize seal_code_hash, seal_set_code_hash and seal_own_code_hash (#11337)
* stabilize seal_code_hash, seal_set_code_hash, seal_own_code_hash * fix missed place found by CI * Fixed missed __unstable__ Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
committed by
GitHub
parent
e8c688e301
commit
9fd4df9ccf
@@ -1,7 +1,7 @@
|
|||||||
(module
|
(module
|
||||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||||
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
|
||||||
(import "__unstable__" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))
|
(import "seal0" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))
|
||||||
|
|
||||||
(import "env" "memory" (memory 1 1))
|
(import "env" "memory" (memory 1 1))
|
||||||
|
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ benchmarks! {
|
|||||||
let code = WasmModule::<T>::from(ModuleDefinition {
|
let code = WasmModule::<T>::from(ModuleDefinition {
|
||||||
memory: Some(ImportedMemory::max::<T>()),
|
memory: Some(ImportedMemory::max::<T>()),
|
||||||
imported_functions: vec![ImportedFunction {
|
imported_functions: vec![ImportedFunction {
|
||||||
module: "__unstable__",
|
module: "seal0",
|
||||||
name: "seal_code_hash",
|
name: "seal_code_hash",
|
||||||
params: vec![ValueType::I32, ValueType::I32, ValueType::I32],
|
params: vec![ValueType::I32, ValueType::I32, ValueType::I32],
|
||||||
return_type: Some(ValueType::I32),
|
return_type: Some(ValueType::I32),
|
||||||
@@ -484,7 +484,7 @@ benchmarks! {
|
|||||||
seal_own_code_hash {
|
seal_own_code_hash {
|
||||||
let r in 0 .. API_BENCHMARK_BATCHES;
|
let r in 0 .. API_BENCHMARK_BATCHES;
|
||||||
let instance = Contract::<T>::new(WasmModule::getter(
|
let instance = Contract::<T>::new(WasmModule::getter(
|
||||||
"__unstable__", "seal_own_code_hash", r * API_BENCHMARK_BATCH_SIZE
|
"seal0", "seal_own_code_hash", r * API_BENCHMARK_BATCH_SIZE
|
||||||
), vec![])?;
|
), vec![])?;
|
||||||
let origin = RawOrigin::Signed(instance.caller.clone());
|
let origin = RawOrigin::Signed(instance.caller.clone());
|
||||||
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
|
||||||
@@ -2017,7 +2017,7 @@ benchmarks! {
|
|||||||
let code = WasmModule::<T>::from(ModuleDefinition {
|
let code = WasmModule::<T>::from(ModuleDefinition {
|
||||||
memory: Some(ImportedMemory::max::<T>()),
|
memory: Some(ImportedMemory::max::<T>()),
|
||||||
imported_functions: vec![ImportedFunction {
|
imported_functions: vec![ImportedFunction {
|
||||||
module: "__unstable__",
|
module: "seal0",
|
||||||
name: "seal_set_code_hash",
|
name: "seal_set_code_hash",
|
||||||
params: vec![
|
params: vec![
|
||||||
ValueType::I32,
|
ValueType::I32,
|
||||||
|
|||||||
@@ -3088,7 +3088,6 @@ fn code_rejected_error_works() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
fn set_code_hash() {
|
fn set_code_hash() {
|
||||||
let (wasm, code_hash) = compile_module::<Test>("set_code_hash").unwrap();
|
let (wasm, code_hash) = compile_module::<Test>("set_code_hash").unwrap();
|
||||||
let (new_wasm, new_code_hash) = compile_module::<Test>("new_set_code_hash_contract").unwrap();
|
let (new_wasm, new_code_hash) = compile_module::<Test>("new_set_code_hash_contract").unwrap();
|
||||||
|
|||||||
@@ -2407,12 +2407,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
fn code_hash_works() {
|
fn code_hash_works() {
|
||||||
/// calls `seal_code_hash` and compares the result with the constant.
|
/// calls `seal_code_hash` and compares the result with the constant.
|
||||||
const CODE_CODE_HASH: &str = r#"
|
const CODE_CODE_HASH: &str = r#"
|
||||||
(module
|
(module
|
||||||
(import "__unstable__" "seal_code_hash" (func $seal_code_hash (param i32 i32 i32) (result i32)))
|
(import "seal0" "seal_code_hash" (func $seal_code_hash (param i32 i32 i32) (result i32)))
|
||||||
(import "env" "memory" (memory 1 1))
|
(import "env" "memory" (memory 1 1))
|
||||||
|
|
||||||
;; size of our buffer is 32 bytes
|
;; size of our buffer is 32 bytes
|
||||||
@@ -2460,12 +2459,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
fn own_code_hash_works() {
|
fn own_code_hash_works() {
|
||||||
/// calls `seal_own_code_hash` and compares the result with the constant.
|
/// calls `seal_own_code_hash` and compares the result with the constant.
|
||||||
const CODE_OWN_CODE_HASH: &str = r#"
|
const CODE_OWN_CODE_HASH: &str = r#"
|
||||||
(module
|
(module
|
||||||
(import "__unstable__" "seal_own_code_hash" (func $seal_own_code_hash (param i32 i32)))
|
(import "seal0" "seal_own_code_hash" (func $seal_own_code_hash (param i32 i32)))
|
||||||
(import "env" "memory" (memory 1 1))
|
(import "env" "memory" (memory 1 1))
|
||||||
|
|
||||||
;; size of our buffer is 32 bytes
|
;; size of our buffer is 32 bytes
|
||||||
@@ -2546,11 +2544,10 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
fn set_code_hash() {
|
fn set_code_hash() {
|
||||||
const CODE: &str = r#"
|
const CODE: &str = r#"
|
||||||
(module
|
(module
|
||||||
(import "__unstable__" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))
|
(import "seal0" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))
|
||||||
(import "env" "memory" (memory 1 1))
|
(import "env" "memory" (memory 1 1))
|
||||||
(func $assert (param i32)
|
(func $assert (param i32)
|
||||||
(block $ok
|
(block $ok
|
||||||
|
|||||||
@@ -147,10 +147,8 @@ pub enum RuntimeCosts {
|
|||||||
/// Weight of calling `seal_is_contract`.
|
/// Weight of calling `seal_is_contract`.
|
||||||
IsContract,
|
IsContract,
|
||||||
/// Weight of calling `seal_code_hash`.
|
/// Weight of calling `seal_code_hash`.
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
CodeHash,
|
CodeHash,
|
||||||
/// Weight of calling `seal_own_code_hash`.
|
/// Weight of calling `seal_own_code_hash`.
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
OwnCodeHash,
|
OwnCodeHash,
|
||||||
/// Weight of calling `seal_caller_is_origin`.
|
/// Weight of calling `seal_caller_is_origin`.
|
||||||
CallerIsOrigin,
|
CallerIsOrigin,
|
||||||
@@ -225,7 +223,6 @@ pub enum RuntimeCosts {
|
|||||||
#[cfg(feature = "unstable-interface")]
|
#[cfg(feature = "unstable-interface")]
|
||||||
CallRuntime(Weight),
|
CallRuntime(Weight),
|
||||||
/// Weight of calling `seal_set_code_hash`
|
/// Weight of calling `seal_set_code_hash`
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
SetCodeHash,
|
SetCodeHash,
|
||||||
/// Weight of calling `ecdsa_to_eth_address`
|
/// Weight of calling `ecdsa_to_eth_address`
|
||||||
#[cfg(feature = "unstable-interface")]
|
#[cfg(feature = "unstable-interface")]
|
||||||
@@ -245,9 +242,7 @@ impl RuntimeCosts {
|
|||||||
CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()),
|
CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()),
|
||||||
Caller => s.caller,
|
Caller => s.caller,
|
||||||
IsContract => s.is_contract,
|
IsContract => s.is_contract,
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
CodeHash => s.code_hash,
|
CodeHash => s.code_hash,
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
OwnCodeHash => s.own_code_hash,
|
OwnCodeHash => s.own_code_hash,
|
||||||
CallerIsOrigin => s.caller_is_origin,
|
CallerIsOrigin => s.caller_is_origin,
|
||||||
Address => s.address,
|
Address => s.address,
|
||||||
@@ -312,7 +307,6 @@ impl RuntimeCosts {
|
|||||||
|
|
||||||
#[cfg(feature = "unstable-interface")]
|
#[cfg(feature = "unstable-interface")]
|
||||||
CallRuntime(weight) => weight,
|
CallRuntime(weight) => weight,
|
||||||
#[cfg(feature = "unstable-interface")]
|
|
||||||
SetCodeHash => s.set_code_hash,
|
SetCodeHash => s.set_code_hash,
|
||||||
#[cfg(feature = "unstable-interface")]
|
#[cfg(feature = "unstable-interface")]
|
||||||
EcdsaToEthAddress => s.ecdsa_to_eth_address,
|
EcdsaToEthAddress => s.ecdsa_to_eth_address,
|
||||||
@@ -1401,7 +1395,7 @@ define_env!(Env, <E: Ext>,
|
|||||||
// # Errors
|
// # Errors
|
||||||
//
|
//
|
||||||
// `ReturnCode::KeyNotFound`
|
// `ReturnCode::KeyNotFound`
|
||||||
[__unstable__] seal_code_hash(ctx, account_ptr: u32, out_ptr: u32, out_len_ptr: u32) -> ReturnCode => {
|
[seal0] seal_code_hash(ctx, account_ptr: u32, out_ptr: u32, out_len_ptr: u32) -> ReturnCode => {
|
||||||
ctx.charge_gas(RuntimeCosts::CodeHash)?;
|
ctx.charge_gas(RuntimeCosts::CodeHash)?;
|
||||||
let address: <<E as Ext>::T as frame_system::Config>::AccountId =
|
let address: <<E as Ext>::T as frame_system::Config>::AccountId =
|
||||||
ctx.read_sandbox_memory_as(account_ptr)?;
|
ctx.read_sandbox_memory_as(account_ptr)?;
|
||||||
@@ -1420,7 +1414,7 @@ define_env!(Env, <E: Ext>,
|
|||||||
// - `out_ptr`: pointer to the linear memory where the returning value is written to.
|
// - `out_ptr`: pointer to the linear memory where the returning value is written to.
|
||||||
// - `out_len_ptr`: in-out pointer into linear memory where the buffer length
|
// - `out_len_ptr`: in-out pointer into linear memory where the buffer length
|
||||||
// is read from and the value length is written to.
|
// is read from and the value length is written to.
|
||||||
[__unstable__] seal_own_code_hash(ctx, out_ptr: u32, out_len_ptr: u32) => {
|
[seal0] seal_own_code_hash(ctx, out_ptr: u32, out_len_ptr: u32) => {
|
||||||
ctx.charge_gas(RuntimeCosts::OwnCodeHash)?;
|
ctx.charge_gas(RuntimeCosts::OwnCodeHash)?;
|
||||||
let code_hash_encoded = &ctx.ext.own_code_hash().encode();
|
let code_hash_encoded = &ctx.ext.own_code_hash().encode();
|
||||||
Ok(ctx.write_sandbox_output(out_ptr, out_len_ptr, code_hash_encoded, false, already_charged)?)
|
Ok(ctx.write_sandbox_output(out_ptr, out_len_ptr, code_hash_encoded, false, already_charged)?)
|
||||||
@@ -2048,7 +2042,7 @@ define_env!(Env, <E: Ext>,
|
|||||||
// # Errors
|
// # Errors
|
||||||
//
|
//
|
||||||
// `ReturnCode::CodeNotFound`
|
// `ReturnCode::CodeNotFound`
|
||||||
[__unstable__] seal_set_code_hash(ctx, code_hash_ptr: u32) -> ReturnCode => {
|
[seal0] seal_set_code_hash(ctx, code_hash_ptr: u32) -> ReturnCode => {
|
||||||
ctx.charge_gas(RuntimeCosts::SetCodeHash)?;
|
ctx.charge_gas(RuntimeCosts::SetCodeHash)?;
|
||||||
let code_hash: CodeHash<<E as Ext>::T> = ctx.read_sandbox_memory_as(code_hash_ptr)?;
|
let code_hash: CodeHash<<E as Ext>::T> = ctx.read_sandbox_memory_as(code_hash_ptr)?;
|
||||||
match ctx.ext.set_code_hash(code_hash) {
|
match ctx.ext.set_code_hash(code_hash) {
|
||||||
|
|||||||
Reference in New Issue
Block a user