-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[contracts] API host functions: remove seal_
name prefix + enable aliasing
#12126
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rustdocs need to be updated with the new attribute
- No non-prefixed version of an aliased function is used in any test
Bonus: Make the alias call the non-aliased function instead of duplicating the body.
They are updated for the macro thing. Or are there any other places I forgot about?
Not exactly. For now, all tests for
Not realistic in current design. See e.g. how fn impls<F: FnMut(&[u8], &[u8], crate::wasm::env_def::HostFunc<E>)>(f: &mut F) {
f("seal0".as_bytes(), "gas".as_bytes(), {
fn gas<E: Ext>(
ctx: &mut crate::wasm::Runtime<E>,
args: &[sp_sandbox::Value],
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError>
where
<E::T as frame_system::Config>::AccountId: sp_core::crypto::UncheckedFrom<<E::T as frame_system::Config>::Hash>
+ AsRef<[u8]>,
{
#[allow(unused)]
let mut args = args.iter();
let mut body = || {
let amount : < u32 as crate :: wasm :: env_def :: ConvertibleToWasm > :: NativeType = args . next () . and_then (| v | < u32 as crate :: wasm :: env_def :: ConvertibleToWasm > :: from_typed_value (v . clone ())) . expect ("precondition: all imports should be checked against the signatures of corresponding
functions defined by `#[define_env]` proc macro by the user of the macro;
thus this can never be `None`;
qed;") ;
{
ctx.charge_gas(RuntimeCosts::MeteringBlock(amount))?;
Ok(())
}
};
body().map_err(|reason| {
ctx.set_trap_reason(reason);
sp_sandbox::HostError
})?;
return Ok(sp_sandbox::ReturnValue::Unit);
}
gas::<E>
});
... So basically each host fn becomes visible only inside a block which is a closure parameter. We can't call them from within each other. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are updated for the macro thing. Or are there any other places I forgot about?
No. I was just too stupid to scroll down. The docs are great.
Not exactly. For now, all tests for unstable functions use non-prefixed version, as they will eventually become stabilized and get used by users with the new naming. For all other tests prefixed functions left because they are the ones used by pallet_contract users.
But only for the function which don't use the new attribute. So there is no code which tests whether the new prefix leaves generates version.
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
I've added a test which catches this case. |
I think your changes broke the build. |
Yeah, making examples |
Added prefixes for the unstable host functions versions. Otherwise we break in-progress PR in ink!. We will remove the alias once we stabilize. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
bot merge |
…liasing (paritytech#12126) * works but ugly * refactored + renamed host fns * fixed tests * fix benchmarks * updated marco docs * Update frame/contracts/proc-macro/src/lib.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * fix for the duplicated prefixed alias bug + test * refactored a bit * fix warnings + try to make macro rustdoc compile * fmt after clearing * examples update + nocompile * add seal_ prefixes to unstable host functions * updated after a review Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Resolves #11444
Added
#[prefixed_alias]
to the#[define_env]
proc attribute macro.For a
host_fn()
marked by the attribute, the macro creates an additional alias functionseal_host_fn()
which is exactly the same as the original one but has the prefixed name for backwards compatibility. See this comment for a usage example.Renamed API functions + added aliases.
Updated tests and benchmarks.