-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unify native and wasm vp #1093
Closed
Closed
unify native and wasm vp #1093
Conversation
This file contains 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
tzemanovic
force-pushed
the
tomas/unify-native-and-wasm-vp
branch
2 times, most recently
from
July 1, 2022 09:07
4c822a8
to
29e026c
Compare
tzemanovic
force-pushed
the
tomas/unify-native-and-wasm-vp
branch
from
July 8, 2022 17:22
29e026c
to
e373a1e
Compare
tzemanovic
force-pushed
the
tomas/unify-native-and-wasm-vp
branch
from
July 20, 2022 19:04
2707a81
to
e948791
Compare
tzemanovic
force-pushed
the
tomas/unify-native-and-wasm-vp
branch
from
July 21, 2022 10:46
e948791
to
bd3b901
Compare
tzemanovic
force-pushed
the
tomas/unify-native-and-wasm-vp
branch
from
July 21, 2022 13:41
bd3b901
to
06fafdc
Compare
pls update wasm |
tzemanovic
commented
Jul 22, 2022
moved to anoma/namada#256 |
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 anoma/namada#110
depends and based on #1243
To facilitate code re-use between native and WASM VPs, this PR adds
trait VpEnv
that is implemented in both. Similarly, it addstrait TxEnv
for 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"Ctx
to bothvp_prelude
andtx_prelude
to 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
Result
type 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 associatedError
type. In native VPs, theError
is 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 theEnvResult
can be extended with user defined errors and messages.The
EnvResult
'sError
type 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 Ctx
as their first arg and returnTxResult
(TxResult = EnvResult<()>
)ctx: &Ctx
as their first arg returnVpResult
(VpResult
=EnvResult<bool>
)Additionally, the tx and VPs library code from
vm_env
crate has been moved to thetx_prelude
/vp_prelude
crates, so that only thing left invm_env
is 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).