Skip to content

Commit

Permalink
work on vm-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyTimes committed Jan 24, 2022
1 parent 280c019 commit 8f7bf8d
Show file tree
Hide file tree
Showing 81 changed files with 9,629 additions and 8,296 deletions.
457 changes: 330 additions & 127 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ members = [
'crates/skw-vm-host',
'crates/skw-vm-engine',
'crates/skw-vm-engine-cli',
'crates/skw-vm-runtime',
'crates/skw-vm-genesis-configs',
'crates/near-test-contracts',

# SkyeKiwi VM contract sdk based on near-sdk-rs
'crates/skw-contract-sdk',
'crates/skw-contract-macros',
'crates/skw-contract-sys',
# 'crates/skw-contract-sdk',
# 'crates/skw-contract-macros',
# 'crates/skw-contract-sys',

# sgx enclave host
'crates/skw-sgx-ipfs',
Expand All @@ -29,7 +31,6 @@ exclude = [
'teaclave-sgx-sdk',

# unfinished crates
'crates/skw-vm-runtime',
'crates/skw-vm-store',
'crates/skw-contract-sim',
'crates/near-contract-standards',
Expand Down
8 changes: 4 additions & 4 deletions crates/skw-contract-sim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ NEAR Simulator & cross-contract testing library

[dependencies]
skw-contract-sdk = { path = "../skw-contract-sdk" }
skw-vm-host = { path = "../../mock-enclave/src/skw-vm-host" }
skw-vm-host = { path = "../skw-vm-host" }
skw-vm-store = { path = "../skw-vm-store" }
skw-vm-primitives = { path = "../skw-vm-primitives" }

near-crypto = "=0.1.0"

near-primitives = "=0.1.0-pre.1"
near-crypto = "=0.1.0"
near-pool = "=0.1.0-pre.1"
near-store = "=0.1.0-pre.1"

lazy-static-include = "3"
# Temporary workaround see https://github.com/bitvecto-rs/bitvec/issues/105
Expand Down
7 changes: 0 additions & 7 deletions crates/skw-contract-sim/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//! # skw_sdk_sim
//!
//! This crate provides an interface for simulating transactions on SkyeKiwi Offchain VM - NEAR's Blockchain.
//! The simulator uses a standalone runtime that can handle any of the [actions](https://nomicon.io/RuntimeSpec/Actions.html) provided by the
//! real runtime, including: creating accounts, deploying contracts, making contract calls and
//! calling view methods.
pub mod outcome;
#[doc(inline)]
pub use outcome::*;
Expand Down
19 changes: 10 additions & 9 deletions crates/skw-contract-sim/src/outcome.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::hash::CryptoHash;
use crate::runtime::{init_runtime, RuntimeStandalone};
use crate::transaction::{ExecutionOutcome, ExecutionStatus};
use core::fmt;
use near_primitives::profile::ProfileData;
use near_primitives::transaction::ExecutionStatus::{SuccessReceiptId, SuccessValue};
use near_primitives::types::AccountId;
use near_sdk::borsh::BorshDeserialize;
use near_sdk::serde::de::DeserializeOwned;
use near_sdk::serde_json::Value;
use near_sdk::Gas;

use skw_vm_primitives::profile::ProfileData;
use skw_vm_primitives::transaction::ExecutionStatus::{SuccessReceiptId, SuccessValue, ExecutionOutcome, ExecutionStatus};
use skw_vm_primitives::contract_runtime::{AccountId, CryptoHash};

use skw_contract_sdk::borsh::BorshDeserialize;
use skw_contract_sdk::serde::de::DeserializeOwned;
use skw_contract_sdk::serde_json::Value;
use skw_contract_sdk::Gas;

use std::borrow::Borrow;
use std::cell::RefCell;
use std::fmt::Debug;
Expand Down
44 changes: 16 additions & 28 deletions crates/skw-contract-sim/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ use crate::ViewResult;
use near_crypto::{InMemorySigner, KeyType, PublicKey, Signer};
use near_pool::{types::PoolIterator, TransactionPool};

use near_primitives::account::{AccessKey, Account};
use near_primitives::errors::RuntimeError;
use near_primitives::hash::CryptoHash;
use near_primitives::profile::ProfileData;
use near_primitives::receipt::Receipt;
use near_primitives::runtime::config::RuntimeConfig;
use near_primitives::state_record::StateRecord;
use near_primitives::test_utils::account_new;
use near_primitives::test_utils::MockEpochInfoProvider;
use near_primitives::transaction::{ExecutionOutcome, ExecutionStatus, SignedTransaction};
use near_primitives::types::{
use skw_vm_primitives::account::{AccessKey, Account};
use skw_vm_primitives::errors::RuntimeError;
use skw_vm_primitives::hash::CryptoHash;
use skw_vm_primitives::profile::ProfileData;
use skw_vm_primitives::receipt::Receipt;
use skw_vm_primitives::runtime::config::RuntimeConfig;
use skw_vm_primitives::state_record::StateRecord;
use skw_vm_primitives::test_utils::account_new;
use skw_vm_primitives::test_utils::MockEpochInfoProvider;
use skw_vm_primitives::transaction::{ExecutionOutcome, ExecutionStatus, SignedTransaction};
use skw_vm_primitives::types::{
AccountInfo, Balance, BlockHeight, EpochHeight, EpochId, EpochInfoProvider, Gas,
StateChangeCause,
};
use near_primitives::version::PROTOCOL_VERSION;
use near_primitives::views::ViewApplyState;
use skw_vm_primitives::version::PROTOCOL_VERSION;
use skw_vm_primitives::views::ViewApplyState;

use near_runtime::{state_viewer::TrieViewer, ApplyState, Runtime};
use near_sdk::{AccountId, Duration};
use near_store::{
use skw_vm_runtime::{state_viewer::TrieViewer, ApplyState, Runtime};
use skw_contract_sdk:{AccountId, Duration};
use skw_vm_store::{
get_access_key, get_account, set_account, test_utils::create_test_store, ShardTries, Store,
};

Expand All @@ -51,7 +51,6 @@ pub struct GenesisConfig {
pub block_prod_time: Duration,
pub runtime_config: RuntimeConfig,
pub state_records: Vec<StateRecord>,
pub validators: Vec<AccountInfo>,
}

impl Default for GenesisConfig {
Expand All @@ -70,7 +69,6 @@ impl Default for GenesisConfig {
block_prod_time: DEFAULT_BLOCK_PROD_TIME,
runtime_config,
state_records: vec![],
validators: vec![],
}
}
}
Expand Down Expand Up @@ -304,16 +302,6 @@ impl RuntimeStandalone {
block_hash: Default::default(),
};

// pub fn apply(
// &self,
// trie: Trie,
// root: CryptoHash,
// validator_accounts_update: &Option<ValidatorAccountsUpdate>,
// apply_state: &ApplyState,
// incoming_receipts: &[Receipt],
// transactions: &[SignedTransaction],
// ) -> Result<ApplyResult, RuntimeError> {

// RUNTIME:: runtime.apply seems to be the critical method for importing states
let apply_result = self.runtime.apply(
self.tries.get_trie_for_shard(0),
Expand Down
13 changes: 5 additions & 8 deletions crates/skw-contract-sim/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ use skw_contract_sdk::PendingContractTx;

use crate::runtime::init_runtime;
pub use crate::to_yocto;
use crate::runtime::{GenesisConfig, RuntimeStandalone};
use crate::outcome::{outcome_into_result, ExecutionResult, ViewResult};

// TODO: these are primitives imports
use crate::{
account::{AccessKey, Account},
hash::CryptoHash,
outcome_into_result,
runtime::{GenesisConfig, RuntimeStandalone},
use skw_vm_primitives::{
account::{Account},
contract_runtime::{CryptoHash, Balance, Gas},
transaction::Transaction,
types::{Balance, Gas},
ExecutionResult, ViewResult,
};

pub const DEFAULT_GAS: u64 = 300_000_000_000_000;
Expand Down
26 changes: 26 additions & 0 deletions crates/skw-vm-genesis-configs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "skw-vm-genesis-configs"
version = "0.0.0"
authors = ["SkyeKiwi <[email protected]>", "Near Inc <[email protected]>"]
publish = false
edition = "2021"
license = "GPL-3.0"
repository = "https://github.com/skyekiwi/skyekiwi-network"
description = "This crate provides typed interfaces to the NEAR Genesis and Chain Configs"

[dependencies]
chrono = { version = "0.4.4", features = ["serde"] }
derive_more = "0.99.3"
num-rational = { version = "0.3", features = ["serde"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.9"
smart-default = "0.6"
tracing = "0.1.13"
anyhow = "1.0.51"

near-crypto = { git = "https://github.com/near/nearcore" }
skw-vm-primitives = { path = "../skw-vm-primitives" }

[features]
default = []
Loading

0 comments on commit 8f7bf8d

Please sign in to comment.