Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

API change: substitute env, context, and msg for tx #484

Open
YaronWittenstein opened this issue Dec 26, 2021 · 1 comment
Open

API change: substitute env, context, and msg for tx #484

YaronWittenstein opened this issue Dec 26, 2021 · 1 comment
Assignees
Labels
codec Related to the Codec simple-coin-iteration-1 svm svm-core SVM core change

Comments

@YaronWittenstein
Copy link
Contributor

YaronWittenstein commented Dec 26, 2021

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:

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:

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 by deploy.
    note that, right now we have svm_codec::template::decode but it only addresses the Message part.
  • svm_codec::decode_spawn - to be used by spawn.
  • svm_codec::decode_call - to be used by call.
  • svm_codec::decode_tx - to be used by verify.

Notes

  • For verify we could probably manage only with decoding the Envelope part.
    So we can have instead svm_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:

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> {
  // ...
}
@neysofu neysofu changed the title API change: substitute env and msg for tx API change: substitute env, context, and msg for tx Feb 16, 2022
@neysofu
Copy link
Contributor

neysofu commented Feb 16, 2022

Closely related to #493.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
codec Related to the Codec simple-coin-iteration-1 svm svm-core SVM core change
Projects
None yet
Development

No branches or pull requests

2 participants