-
Notifications
You must be signed in to change notification settings - Fork 14
API change: substitute env, context, and msg for tx #484
Description
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:
svm/crates/runtime-ffi/src/api.rs
Line 262 in 6edb73d
| pub unsafe extern "C" fn svm_deploy( |
#[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:
svm/crates/runtime/src/runtime/runtime.rs
Line 548 in 6edb73d
| pub fn deploy( |
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::decodebut it only addresses theMessagepart.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
verifywe could probably manage only with decoding theEnvelopepart.
So we can have insteadsvm_codec::decode_env. -
The validations method (i.e
validate_deploy/validate_spawn/validate_callshould expect the whole raw transactions as a parameter.
For example, this code:
svm/crates/runtime/src/runtime/runtime.rs
Line 521 in 6edb73d
| pub fn validate_deploy(&self, message: &[u8]) -> std::result::Result<(), ValidateError> { |
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> {
// ...
}