Skip to content
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

feat: merge temporary branch main milestone three #152

Merged
merged 18 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
12f0484
feat: add move-project for multiple signers (#141)
neutrinoks Feb 15, 2024
afcece4
feat: add extrinsic to update stdlib (#142)
neutrinoks Feb 19, 2024
9423d9b
feat: add tests for extrinsic update_stdlib (#143)
neutrinoks Feb 20, 2024
a259901
doc: update-stdlib extrinsic documentation update (#144)
neutrinoks Feb 21, 2024
76d3d19
feat: rename update_stdlib extrinsic, add more tests (#145)
neutrinoks Feb 21, 2024
4e36311
feat: add memory protection for core address (#150)
neutrinoks Feb 27, 2024
ca7e176
feat: basic implementation for multi-signature feature (#149)
neutrinoks Feb 29, 2024
4536e8e
chore: restructure pallet part 1, unit tests and internal mockup (#154)
neutrinoks Mar 1, 2024
440b53c
feat: optimize multi signer feature and update existing tests (#155)
neutrinoks Mar 1, 2024
f42e934
chore: restructure pallet part 2, workspace manifest file (#156)
neutrinoks Mar 1, 2024
09edbf0
feat: implement clean up mechanism and add unit tests (#157)
neutrinoks Mar 7, 2024
cd48e3d
feat: implement currency locking and extend testing
neutrinoks Mar 7, 2024
14039c8
ci: update directory src to pallet after re-structuring
neutrinoks Mar 8, 2024
f3c2522
feat: improve readability in testing
neutrinoks Mar 8, 2024
feb5ee4
feat: unique usage of balance type in interfaces
neutrinoks Mar 8, 2024
60f27ab
feat: optimise storage access rate chore mechanism
neutrinoks Mar 8, 2024
e6b9e48
chore: update helper script parameters in example move project
neutrinoks Mar 25, 2024
d68cfec
feat: functionality update for smove, enabling gas estimation in mult…
neutrinoks Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Common jobs (fmt, clippy, test)
on:
pull_request:
paths:
- src/**
- pallet/**
- Cargo.toml
- rpc/**
- .github/workflows/common.yml
Expand Down
87 changes: 33 additions & 54 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
[package]
name = "pallet-move"
version = "0.1.0"
authors = ["Eiger <[email protected]>"]
[workspace]
members = [
"pallet",
"rpc",
]
resolver = "2"

[workspace.package]
edition = "2021"
authors = ["Eiger <[email protected]>"]
readme = "README.md"

repository = "https://github.com/eigerco/substrate-movevm-pallet"
description = "MoveVM support pallet"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
[workspace.dependencies]
# crates.io
anyhow = { version = "1.0", default-features = false }
bcs = { git = "https://github.com/eigerco/bcs.git", default-features = false, branch = "master" }
blake2 = { version = "0.10", default-features = false }
codec = { package = "parity-scale-codec", version = "3.6", default-features = false, features = ["derive"] }
hashbrown = { version = "0.14" }
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
frame-support = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
frame-system = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
hex = { version = "0.4", default-features = false }
jsonrpsee = { version = "0.16", features = ["server", "macros"] }
log = { version = "0.4", default-features = false }
rand = { version = "0.8", default-features = false }
scale-info = { version = "2.10", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
sp-core = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-std = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }

# MoveVM dependencies
move-core-types = { default-features = false, git = "https://github.com/eigerco/substrate-move.git", branch = "main", features = ["address32"] }

# MoveVM backend dependency
move-vm-backend = { default-features = false, git = "https://github.com/eigerco/substrate-move.git", branch = "main" }
move-vm-backend-common = { default-features = false, git = "https://github.com/eigerco/substrate-move.git", branch = "main" }

[dev-dependencies]
hex = "0.4"
rand = "0.8"
lazy_static = "1.4"
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }

[features]
default = ["std"]
std = [
"anyhow/std",
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"serde/std",
"sp-std/std",
"move-core-types/std",
"move-vm-backend/std",
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]

# Builds move projects for test purposes.
#
# The move projects in `tests/assets/move-projects/` are not built by default without this flag
# since rebuilding those tests takes lots of time.
build-move-projects-for-test = []
# Polkadot crates
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }

# Eiger crates
move-core-types = { git = "https://github.com/eigerco/substrate-move.git", branch = "main", features = ["address32"], default-features = false }
move-stdlib = { git = "https://github.com/eigerco/substrate-move.git", features = ["stdlib-bytecode"], default-features = false }
move-vm-backend = { git = "https://github.com/eigerco/substrate-move.git", branch = "main", default-features = false }
move-vm-backend-common = { git = "https://github.com/eigerco/substrate-move.git", branch = "main", default-features = false }
Binary file added doc/assets/polkadot.js_update_stdlib.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 13 additions & 13 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,21 @@ Let's dive into the crucial aspects of pallet architecture:
2) State: The MoveVM will define its state, which is the data they need to keep track of. That state consists of various variables containing information relevant to the pallet's functionalities. It is stored on the blockchain and updated through transactions and blocks.
3) Storage: It defines the data structures and how they are accessed and modified. The MoveVM pallet would use it to store data in the map of key-value pairs and provide a storage adapter for the Move Virtual Machine storage.
4) Dispatchable Functions - extrinsics: The MoveVM pallet will expose dispatchable functions, which users can call via transactions. Currently, there are three extrinsics defined:
- 'execute' - executes a Move script;
- 'publish_module' - publishes a Move module;
- 'publish_module_bundle' - publishes a bundle of Move modules.
- `execute` - executes a Move script;
- `publish_module` - publishes a Move module;
- `publish_module_bundle` - publishes a bundle of Move modules.
- `update_stdlib` - updates standard libraries (move-stdlib or substrate-stdlib)
5) Events: Events inform about changes within the pallet. The MoveVM pallet defines separate events for completing each extrinsic call. Somebody can subscribe to them, allowing external applications to react to specific changes or triggers within the blockchain.
6) Configuration: The MoveVM pallet is configured during the runtime's setup to customize its behaviour. Configuration is done in a standard way, like it's done for other pallets.
7) Traits: The MoveVM pallet defines a set of traits which can be used further in the runtime or RPC node.
8) RPC: The MoveVM pallet incorporates a sub-crate with RPC calls (`pallet-move-rpc` using `jsonrpsee`) that can be used to interact with the pallet from external applications:
- `mvm_estimateGasExecute`,
- `mvm_estimateGasPublish`,
- `mvm_gasToWeight`,
- `mvm_getModule`,
- `mvm_getModuleABI`,
- `mvm_getResource`,
- `mvm_weightToGas`.
- `mvm_estimateGasExecute`,
- `mvm_estimateGasPublish`,
- `mvm_gasToWeight`,
- `mvm_getModule`,
- `mvm_getModuleABI`,
- `mvm_getResource`,
- `mvm_weightToGas`.

The MoveVM pallet divides into three main components - the MoveVM pallet itself, runtime API (fulfilling the pallet's traits), and RPC. The MoveVM pallet is the core, containing all the logic needed to interact with the virtual machine. The runtime API is a separate crate that implements the pallet's traits and exposes them to the runtime. The RPC is a separate crate that implements the pallet's RPC calls and exposes them to the RPC node.

Expand Down Expand Up @@ -230,9 +231,8 @@ In order to keep things separated and easy to maintain, we propose to create a s

The package and repository structure will look like this:
- [`pallet-move`][pallet-move] - contains the pallet codebase, tests, and documentation.
- `pallet-move` - the main pallet crate.
- `pallet-move-rpc` - the RPC MoveVM pallet crate - placed under `src/rpc` directory. It contains the RPC codebase, tests, and documentation.
- `pallet-move-runtime-api` - the runtime API MoveVM pallet crate - placed under `src/rpc/runtime-api` directory.
- `pallet-move` - the main pallet crate with the runtime-api - placed under `pallet`.
- `pallet-move-rpc` - the RPC MoveVM pallet crate - placed under `rpc` directory. It contains the RPC codebase, tests, and documentation.
- [`substrate-move`][substrate-move] - Move language fork. Contains all the Move crates and the toolchain.
- [`substrate-node-template-move-vm-test`][substrate-node-template-move-vm-test] - testing node repository - contains the node codebase, tests, and documentation. Work is done in the `pallet-move` branch.
- [`bcs`][bcs] - Rust implementation of the Binary Canonical Serialization (BCS) format - a crate which is used by some Move crates.
Expand Down
19 changes: 16 additions & 3 deletions doc/final-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Scripts and modules have limited access to the balance transfer functionality vi
transaction_bc: Vec<u8>,
gas_limit: u64,
cheque_limit: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
) -> DispatchResultWithPostInfo;
```

```rust
Expand All @@ -38,7 +38,7 @@ Scripts and modules have limited access to the balance transfer functionality vi
origin: OriginFor<T>,
bytecode: Vec<u8>,
gas_limit: u64,
) -> DispatchResultWithPostInfo {
) -> DispatchResultWithPostInfo;
```

```rust
Expand All @@ -49,8 +49,21 @@ Scripts and modules have limited access to the balance transfer functionality vi
origin: OriginFor<T>,
bundle: Vec<u8>,
gas_limit: u64,
) -> DispatchResultWithPostInfo {
) -> DispatchResultWithPostInfo;
```

```rust
/// Publish a standard library bundle, e.g. Move-Stdlib or Substrate-Stdlib. Sudo user only.
///
/// It should be used carefully - and should not introduce backward, incompatible changes.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::update_stdlib())]
pub fn update_stdlib_bundle(
origin: OriginFor<T>,
stdlib: Vec<u8>,
) -> DispatchResultWithPostInfo;
```

## RPC

### Method `mvm_gasToWeight`
Expand Down
30 changes: 30 additions & 0 deletions doc/tech_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ In this tech guide, you will find instructions and details on:
- [Pallet Configuration in a Substrate-Node](#pallet-configuration-in-a-substrate-node)
- [Benchmarking](#benchmarking)
- [Docker](#docker)
- [Update Standard Libraries](#update-standard-libraries)


## Quickstart Guide for the Template-Node
Expand Down Expand Up @@ -141,3 +142,32 @@ It will start the `node-template` within a local Docker container. In dependency
> ```bash
> docker run --net host nodemove:Dockerfile
> ```
It will start the `node-template` on the local interface.
You can change the default behavior by passing your command when running the docker image.
All available options are in the [node template](https://docs.substrate.io/reference/command-line-tools/node-template/) documentation.


## Update Standard Libraries

Two standard libraries are provided for pallet-move at the genesis block creation:
- [`move-stdlib`](move-stdlib) - the normal Move standard library inherited from the Move repo.
- [`substrate-stdlib`](substrate-stdlib) - an extension of the standard library with additional modules - where some of those modules are also substrate-specific modules.

On rare occasions, those libraries can be updated after the genesis block creation by the root account. **WARNING: THIS CAN BREAK THE MOVE-VM ON-CHAIN STORAGE IF IT INTRODUCES BACKWARD INCOMPATIBLE CHANGES - BE CAREFUL WITH THIS OPERATION**

After edits are prepared to the standard library Move packages, compile both bundles using `smove`:
```bash
smove bundle -p substrate-move/language/move-stdlib
smove bundle -p substrate-stdlib
```
The two generated bundles will be located in the subfolders:
- `build/move-stdlib/bundles/move-stdlib.mvb`
- `build/substrate-stdlib/bundles/substrate-stdlib.mvb`

Use the extrinsic call `update_stdlib_bundle` as the sudo user to update both of them.
![Update Stdlib](assets/polkadot.js_update_stdlib.png)


[move-stdlib]: https://github.com/eigerco/substrate-move/tree/main/language/move-stdlib
[substrate-move]: https://github.com/eigerco/substrate-move
[substrate-stdlib]: https://github.com/eigerco/substrate-stdlib
71 changes: 71 additions & 0 deletions pallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[package]
name = "pallet-move"
version = "0.1.0"
description = "MoveVM support pallet"
authors = { workspace = true }
edition = { workspace = true }
readme = { workspace = true }
repository = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
anyhow = { workspace = true }
bcs = { workspace = true }
blake2 = { workspace = true }
codec = { workspace = true }
hashbrown = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
move-core-types = { workspace = true }
move-vm-backend = { workspace = true }
move-vm-backend-common = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }
sp-api = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
hex = { workspace = true }
rand = { workspace = true }
move-stdlib = { workspace = true }
sp-io = { workspace = true }
pallet-balances = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"anyhow/std",
"blake2/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"serde/std",
"sp-std/std",
"move-core-types/std",
"move-vm-backend/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]

# Builds move projects for test purposes.
#
# The move projects in `tests/assets/move-projects/` are not built by default without this flag
# since rebuilding those tests takes lots of time.
build-move-projects-for-test = []
2 changes: 1 addition & 1 deletion build.rs → pallet/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn build_move_projects() -> Result<(), Box<dyn Error>> {
println!("cargo:warning=Building move projects in tests/assets folder");

let smove_run = Command::new("bash")
.args(["tests/assets/move-projects/smove-build-all.sh"])
.args(["src/tests/assets/move-projects/smove-build-all.sh"])
.output()
.expect("failed to execute script which builds necessary move modules");

Expand Down
23 changes: 15 additions & 8 deletions rpc/runtime-api/src/lib.rs → pallet/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

extern crate alloc;

pub mod types;

use alloc::{string::String, vec::Vec};

use codec::{Decode, Encode};
use frame_support::weights::Weight;
pub use pallet_move::pallet::ModuleAbi;
use sp_runtime::{scale_info::TypeInfo, DispatchError};

pub use crate::types::MoveApiEstimation;
pub use move_vm_backend_common::abi::ModuleAbi;

/// Gas estimation information.
#[derive(Clone, PartialEq, Debug, Encode, Decode, TypeInfo)]
pub struct MoveApiEstimation {
/// Gas used.
pub gas_used: u64,
/// Status code for the MoveVM execution.
pub vm_status_code: u64,
}

// Here we declare the runtime API. It is implemented it the `impl` block in
// runtime file (the `runtime/src/lib.rs` of the node)
Expand All @@ -24,13 +31,13 @@ sp_api::decl_runtime_apis! {
fn weight_to_gas(weight: Weight) -> u64;

// Estimate gas for publishing a module.
fn estimate_gas_publish_module(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, sp_runtime::DispatchError>;
fn estimate_gas_publish_module(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, DispatchError>;

// Estimate gas for publishing a bundle.
fn estimate_gas_publish_bundle(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, sp_runtime::DispatchError>;
fn estimate_gas_publish_bundle(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, DispatchError>;

// Estimate gas for script execution.
fn estimate_gas_execute_script(account: AccountId, transaction: Vec<u8>, cheque_limit: u128) -> Result<MoveApiEstimation, sp_runtime::DispatchError>;
fn estimate_gas_execute_script(account: AccountId, transaction: Vec<u8>, cheque_limit: u128) -> Result<MoveApiEstimation, DispatchError>;

// Get module binary by its address.
fn get_module(address: String, name: String) -> Result<Option<Vec<u8>>, Vec<u8>>;
Expand Down
Loading
Loading