svm
svm copied to clipboard
API change: substitute `env`, `context`, and `msg` for `tx`
Depends on #458
On issue #458, we've extended the svm-codec
to be aware of the Envelope
.
We'll adapt both the Runtime
and the C-API require a Transaction
instead of Envelope
and Message
.
As an example, here we have the svm_deploy
under the FFI API:
https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/runtime-ffi/src/api.rs#L262
#[must_use]
#[no_mangle]
pub unsafe extern "C" fn svm_deploy(
runtime: *mut c_void,
envelope: *const u8,
message: *const u8,
message_size: u32,
context: *const u8,
) -> svm_result_t {
svm_runtime_action(
runtime,
envelope,
message,
message_size,
context,
|r, e, m, c| Runtime::deploy(r, e, m, c),
"svm_deploy",
)
}
We'll modify the API to look as the following:
#[must_use]
#[no_mangle]
pub unsafe extern "C" fn svm_deploy(
runtime: *mut c_void,
tx: *const u8,
tx_size: u32,
context: *const u8,
) -> svm_result_t {
svm_runtime_action(
runtime,
tx,
tx_size,
context,
|r, t, c| Runtime::deploy(r, t, c),
"svm_deploy",
)
}
Consequently, we'll change the Runtime
.
In the Deploy
context, we've this link:
https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/runtime/src/runtime/runtime.rs#L548
impl Runtime {
pub fn deploy(
&mut self,
envelope: &Envelope,
message: &[u8],
context: &Context,
) -> DeployReceipt {
// ...
}
it'll be modified to something similar to this:
impl Runtime {
pub fn deploy(
&mut self,
raw_tx: &[u8],
context: &Context,
) -> DeployReceipt {
let tx = svm_codec::tx::decode_deploy(raw_tx);
if tx.is_err() {
let err = err::func_invalid_deploy(tx);
Err(err)
}
let tx = tx.unwrap();
let env = tx.envelope();
let msg = tx.message();
}
}
Now, we want to keep the raw_tx
since we'll need it for further usage.
In the Deploy
transaction, it'll be used for deriving the Template Address
.
We'll need the' raw_tx' for Spawn
, Call
, and Verify
we'll need the raw_tx
for executing code.
(the raw transaction will be copied to the Wasm Instance Memory - see issue #462).
In similar fashion, we need to update the spawn
, call
and verify
to require only the raw transaction.
The svm_codec
should expose:
-
svm_codec::decode_deploy
- to be used bydeploy
. note that, right now we havesvm_codec::template::decode
but it only addresses theMessage
part. -
svm_codec::decode_spawn
- to be used byspawn
. -
svm_codec::decode_call
- to be used bycall
. -
svm_codec::decode_tx
- to be used byverify
.
Notes
-
For
verify
we could probably manage only with decoding theEnvelope
part. So we can have insteadsvm_codec::decode_env
. -
The validations method (i.e
validate_deploy/validate_spawn/validate_call
should expect the whole raw transactions as a parameter.
For example, this code: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/runtime/src/runtime/runtime.rs#L521
It should be modified to validate the whole transaction instead of only the Message
part of a Deploy Transaction
.
pub fn validate_deploy(&self, tx: &[u8]) -> std::result::Result<(), ValidateError> {
// ...
}
Closely related to #493.