spacemeshos / svm

SVM - Spacemesh Virtual Machine
https://spacemesh.io
MIT License
85 stars 14 forks source link

Extend the SDK + CLI to support `Immutable Storage` #473

Open YaronWittenstein opened 2 years ago

YaronWittenstein commented 2 years ago

Here is an example of how it could look like:

use svm_sdk_mock::template;

#[template]
mod Template {
  #[storage]
  struct Storage {
    #[immutable]
    pub_keys: [svm_sdk::Blob32; 3],
    started: bool,
    #[immutable]
    master_key: svm_sdk::Blob64,
    word: [u16; 3],
  }
}

The Var under svm-sdk-macros crate should have is_mutable: bool field added: https://github.com/spacemeshos/svm/blob/master/crates/sdk-macros/src/struct/var.rs

This piecse of code should determine for each var whether it's mutable or not: https://github.com/spacemeshos/svm/blob/9b6b8f89e25f605e686d43dc46d73c7fe49d3e1d/crates/sdk-macros/src/struct/storage.rs#L33

https://github.com/spacemeshos/svm/blob/9b6b8f89e25f605e686d43dc46d73c7fe49d3e1d/crates/sdk-macros/src/struct/storage.rs#L33

The generated code should gather variables pub_keys and master_key to sit together under the Immutable Storage Section (which is enforced to be at index #0 - see) and variables to be under Storage Section #1.

The emitted Storage Schema should reflect that and then the CLI should be updated as well: https://github.com/spacemeshos/svm/blob/22fb1cf627d5c82d20c285744dd9ee708e9c7c08/crates/cli/src/subcmd_craft_deploy/meta.rs

The Data Section should always include the Immutable Storage under Section #0 and the Mutable Storage under Section #1 (both will be of type Fixed-Layout)