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

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
borispovod committed Oct 3, 2021
1 parent ec984f8 commit 11eef4e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 33 deletions.
4 changes: 2 additions & 2 deletions pallets/sp-mvm/src/addr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0
// Apache 2.0

//! By default Move VM supports only 0x{hex} address format, which has 32 bytes length.
//! To be in compatibility with Substrate SS58 addresses we implemented traits and functions that allow us to convert SS58 addresses to 0x{hex} format.
Expand Down Expand Up @@ -28,7 +28,7 @@ where
}

/// Convert AccountId to Move VM address format.
///
///
/// Returns a slice that could be represented as a Move VM address.
/// If provided AccountId length is less than expected address length, fills address with zeros.
/// Otherwise just copy bytes we need.
Expand Down
5 changes: 5 additions & 0 deletions pallets/sp-mvm/src/balance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0

use core::convert::TryFrom;
use core::convert::TryInto;
use move_vm::io::traits::{Balance as VmBalance, BalanceAccess};
Expand Down Expand Up @@ -239,6 +243,7 @@ pub mod boxed {
}
}

/// Tests.
#[cfg(test)]
mod tests {
use super::PONT;
Expand Down
2 changes: 1 addition & 1 deletion pallets/sp-mvm/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(feature = "runtime-benchmarks")]
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0
// Apache 2.0

//! Benchmarking setup for Move VM pallet.

Expand Down
2 changes: 1 addition & 1 deletion pallets/sp-mvm/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0
// Apache 2.0

//! Implement Move VM kind of events and adopt it for Substrate based events.
use core::convert::TryInto;
Expand Down
4 changes: 2 additions & 2 deletions pallets/sp-mvm/src/gas.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0
// Apache 2.0

//! Basic weight <-> gas trait implementation for Move VM.
//!
//!
//! Move VM uses a similar gas model to EVM.
//! As we are using Substrate we should allow us to convert gas to weight, and weight to gas.
use frame_support::weights::Weight;
Expand Down
36 changes: 18 additions & 18 deletions pallets/sp-mvm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0
// Apache 2.0

//! This pallet enables Move Virtual Machine developed by Facebook's Diem team in your Substrate based chain.
//! The pallet allows to execute Move Smart contracts, utilizing Move VM adopted for WASM Runtime.
Expand All @@ -18,7 +18,7 @@
//! execute(tx_bc: Vec<u8>, gas_limit: u64) - execute Move script with bytecode `tx_bc`.
//! publish_module(module_bc: Vec<u8>, gas_limit: u64) - publish Move module with bytecode `module_bc`.
//! publish_package(package: Vec<u8>, gas_limit: u64) - publish package (a set of Move modules) from binary `package`.
//! publish_std(modules: Vec<Vec<u8>>, gas_limit: u64) - publish a list of Standard Library modules (only callable by root). Would be possible to execute it only by gov in the future.
//! publish_std(modules: Vec<Vec<u8>>, gas_limit: u64) - publish a list of Standard Library modules (only callable by root). Would be possible to execute it only by gov in the future.

#![cfg_attr(not(feature = "std"), no_std)]

Expand Down Expand Up @@ -144,7 +144,7 @@ pub mod pallet {
OriginFor<T>: Into<Result<pallet_multisig::Origin<T>, OriginFor<T>>>,
{
/// Execute Move script.
///
///
/// User can send his Move script (compiled using 'dove tx' command) for execution by Move VM.
/// The gas limit should be provided.
#[pallet::weight(T::GasWeightMapping::gas_to_weight(*gas_limit))]
Expand All @@ -167,7 +167,7 @@ pub mod pallet {
}

/// Publish Move module.
///
///
/// User can publish his Move module under his address.
/// The gas limit should be provided.
#[pallet::weight(T::GasWeightMapping::gas_to_weight(*gas_limit))]
Expand All @@ -192,7 +192,7 @@ pub mod pallet {
}

/// Publish module package (could be generated using 'dove build --package'), e.g.: several modules in one transaction.
///
///
/// Deploy several modules in one transaction. Could be called by root in case needs to update Standard Library.
/// Read more about Standard Library - https://docs.pontem.network/03.-move-vm/stdlib
/// The gas limit should be provided.
Expand Down Expand Up @@ -233,9 +233,9 @@ pub mod pallet {
}

/// Batch publish Standard Library modules by root account only.
///
///
/// Not recommended to use, would be deprecated.
/// TODO??? (same for other methods): #[pallet::weight(T::GasWeightMapping::gas_to_weight(*gas_limit) * modules.len().into())]
/// TODO??? (same for other methods): #[pallet::weight(T::GasWeightMapping::gas_to_weight(*gas_limit) * modules.len().into())]
#[pallet::weight(T::GasWeightMapping::gas_to_weight(*gas_limit))]
pub fn publish_std(
origin: OriginFor<T>,
Expand Down Expand Up @@ -277,8 +277,8 @@ pub mod pallet {
}

/// Genesis configuration.
///
/// Allows to configure Move VM in the genesis block.
///
/// Allows to configure Move VM in the genesis block.
/// Accepts Standard Library modules list and initialize state by calling initialize function with arguments.
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
Expand All @@ -289,7 +289,7 @@ pub mod pallet {
pub init_module: Vec<u8>,
// Init function name.
pub init_func: Vec<u8>,
// Init function arguments.
// Init function arguments.
pub init_args: Vec<Vec<u8>>,
}

Expand All @@ -307,7 +307,7 @@ pub mod pallet {
}
}

/// Initialize Move VM during genesis block.
/// Initialize Move VM during genesis block.
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
Expand All @@ -328,7 +328,7 @@ pub mod pallet {
}
}

/// Clearing Move VM cache once block processed.
/// Clearing Move VM cache once block processed.
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
#[cfg(not(feature = "no-vm-static"))]
Expand Down Expand Up @@ -481,9 +481,9 @@ pub mod pallet {
}
}

/// Implement traits allows to create Move VM.
///
/// Supports both static (created at launch of chain), and dynamic one (usually we use regulated one);.
/// Implement traits allows to create Move VM.
///
/// Supports both static (created at launch of chain), and dynamic one (usually we use regulated one);.
impl<T: Config> mvm::TryCreateMoveVm<T> for Pallet<T> {
#[cfg(not(feature = "no-vm-static"))]
type Vm = Mvm<boxed::StorageAdapter, event::DefaultEventHandler, boxed::BalancesAdapter>;
Expand All @@ -495,8 +495,8 @@ pub mod pallet {
>;
type Error = Error<T>;

/// Try to create Move VM instance.
///
/// Try to create Move VM instance.
///
/// If successful it returns a VM instance, otherwise error.
fn try_create_move_vm() -> Result<Self::Vm, Self::Error> {
trace!("MoveVM created");
Expand Down Expand Up @@ -536,7 +536,7 @@ pub mod pallet {
}
}

/// Errors that occur during Move VM execution.
/// Errors that occur during Move VM execution.
/// Based on initial Move VM errors, but adopted for Substrate.
#[pallet::error]
pub enum Error<T> {
Expand Down
8 changes: 6 additions & 2 deletions pallets/sp-mvm/src/mvm.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0

use move_vm::mvm::Mvm;

use crate::balance::BalancesAdapter;
use crate::storage::*;

/// Default type of Move VM implementation
/// Default type of Move VM implementation.
pub type DefaultVm<S, E, R> = Mvm<StorageAdapter<S>, E, BalancesAdapter<R>>;

pub trait CreateMoveVm<T> {
type Vm: move_vm::Vm;

/// Create VM instance
/// Create VM instance.
fn create_move_vm() -> Self::Vm;
}

Expand Down
12 changes: 6 additions & 6 deletions pallets/sp-mvm/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0
// Apache 2.0

//! Converts Move VM execution results (Status, Gas Limit, Errors) to Substrate compatible results (Dispatch Results).
//!
//! Converts Move VM execution results (Status, Gas Limit, Errors) to Substrate compatible results (Dispatch Results).
//!
//! So in a nutshell, after getting the execution result from Move VM we should convert it to a format compatible with Substrate (usually it's DispatchResultWithPostInfo).
//! At the same time we convert status codes to Substrate errors if there is error.
//! Also, gas would be converted to weight and back here.
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn from_status_code_with_gas<T: Config>(
}

/// Converts VM result to dispatch result.
///
///
/// VM returns the VM result, so we use the current function to convert it to DispatchResultWithPostInfo.
pub fn from_vm_result<T: Config>(vm_result: VmResult) -> DispatchResultWithPostInfo {
let gas = PostDispatchInfo {
Expand Down Expand Up @@ -102,8 +102,8 @@ pub fn from_vm_results<T: Config>(vm_results: &[VmResult]) -> DispatchResultWith
Ok(gas)
}

/// Implement From trait for Status Code.
///
/// Implement From trait for Status Code.
///
/// Converts StatusCode to Error.
impl<T: Config> From<StatusCode> for Error<T> {
fn from(sp: StatusCode) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion pallets/sp-mvm/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020-2021 Pontem Foundation LTD.
// This file is part of Pontem Network.
// Apache 2.0

use core::marker::PhantomData;
use sp_std::prelude::*;
use parity_scale_codec::FullCodec;
Expand All @@ -16,7 +20,7 @@ pub trait MoveVmStorage<T, K: FullEncode, V: FullCodec> {
}
}

/// Vm storage adapter for native storage
/// Vm storage adapter for native storage.
pub struct StorageAdapter<T, K = Vec<u8>, V = Vec<u8>>(PhantomData<(T, K, V)>);

impl<T, K, V> Default for StorageAdapter<T, K, V> {
Expand Down

0 comments on commit 11eef4e

Please sign in to comment.