-
Notifications
You must be signed in to change notification settings - Fork 986
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 #256
Merged
Merged
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
August 11, 2022 16:40
52ff433
to
13623c0
Compare
tzemanovic
force-pushed
the
tomas/unify-native-and-wasm-vp
branch
2 times, most recently
from
August 17, 2022 15:57
c039262
to
1e6c868
Compare
tzemanovic
force-pushed
the
tomas/unify-native-and-wasm-vp
branch
from
August 17, 2022 16:39
1e6c868
to
14f638a
Compare
pls update wasm |
tzemanovic
added a commit
that referenced
this pull request
Aug 24, 2022
* tomas/unify-native-and-wasm-vp: [ci skip] wasm checksums update update wasm checksums wasm_for_tests: make Update shared/src/ledger/vp_env.rs changelog: add #1093 wasm: improve error handling macros: add error handling to transaction and validity_predicate macros wasm: update for VM API changes tests: update for VM API changes VM: move vm_env sub-mod into tx/vp_prelude and add Tx/VpEnv and Ctx shared: update native_vp implementations for VpEnv methods shared/ledger/native_vp: implement VpEnv shared/vm: rename host_env TxEnv/VpEnv to TxVmEnv/VpVmEnv ledger: add tx and VP traits with host env functions
Closed
tzemanovic
added a commit
that referenced
this pull request
Sep 23, 2022
- Updated tx_bond, tx_unbond and tx_withdraw and their tests to the new tx API * tomas/unify-native-and-wasm-vp: [ci skip] wasm checksums update update wasm checksums wasm_for_tests: make Update shared/src/ledger/vp_env.rs changelog: add #1093 wasm: improve error handling macros: add error handling to transaction and validity_predicate macros wasm: update for VM API changes tests: update for VM API changes VM: move vm_env sub-mod into tx/vp_prelude and add Tx/VpEnv and Ctx shared: update native_vp implementations for VpEnv methods shared/ledger/native_vp: implement VpEnv shared/vm: rename host_env TxEnv/VpEnv to TxVmEnv/VpVmEnv ledger: add tx and VP traits with host env functions
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.
moved from anoma/anoma#1093
closes #110 and #87
depends and based on #351
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
(anoma/anoma@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 (anoma/anoma@562267d).The
debug_log!
macro is also improve here to justprintln!
to stdout in non-WASM target, e.g. unit test (anoma/anoma@76e1458.This is a breaking change for WASM transactions and VPs (anoma/anoma@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 (anoma/anoma@d9f0c0b).