Closed
Conversation
4c822a8 to
29e026c
Compare
29e026c to
e373a1e
Compare
2707a81 to
e948791
Compare
e948791 to
bd3b901
Compare
bd3b901 to
06fafdc
Compare
Author
|
pls update wasm |
tzemanovic
commented
Jul 22, 2022
Author
|
moved to namada-net/namada#256 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes namada-net/namada#110
depends and based on #1243
To facilitate code re-use between native and WASM VPs, this PR adds
trait VpEnvthat is implemented in both. Similarly, it addstrait TxEnvfor transaction, currently only implemented in WASM.Because the native VPs use methods on
Ctx, but in WASM the "context" is implicit (WASM source itself doesn't have a direct access to it and the host env functions are resolved by the runtime), we're adding a "fake"Ctxto bothvp_preludeandtx_preludeto be able to fit them under the same interface.Another key difference is that in native VPs, gas handling is explicit and the env method's
Resulttype is used to return early on out of gas error, whereas in WASM VPs, gas handling is not included in the source, but rather injected into the WASM before it's executed on the ledger. To unify their host env interfaces, the methods inVpEnv(and inTxEnv) use an associatedErrortype. In native VPs, theErroris instantiated to include out of gas error, however, in WASM the host environment functions are essentially infallible at type level (std::convert::Infallible) and out of gas error (or any other runtime errors for that matter) instead panic the WASM execution. However, it presented an opportunity to add more seamless error-handling for txs and VPs, so in WASM theEnvResultcan be extended with user defined errors and messages.The
EnvResult'sErrortype can be used to add a static message to errors and/or wrap any other errorE where E: std::error::Error(bd3b901) and the errors can be printed in debug build viadebug_log!macro (the WASM debug build recipes are added in #1243). Transactions' and VPs' results are handled in the macros (562267d).The
debug_log!macro is also improve here to justprintln!to stdout in non-WASM target, e.g. unit test (76e1458.This is a breaking change for WASM transactions and VPs (e90da7c for the changes in the current tx and VPs), where
ctx: &mut Ctxas their first arg and returnTxResult(TxResult = EnvResult<()>)ctx: &Ctxas their first arg returnVpResult(VpResult=EnvResult<bool>)Additionally, the tx and VPs library code from
vm_envcrate has been moved to thetx_prelude/vp_preludecrates, so that only thing left invm_envis the low-level host env functions API and a small helper for 2-step buffer read for dynamically-sized data.For WASM testing helpers, a
vp_host_env::ctx()andtx_host_env::ctx()is provided (d9f0c0b).