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(runtime): Wasmer 1.0 runner #3799

Merged
merged 60 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
17c9c7d
initial add wasmer 1.0 and features
ailisp Jan 5, 2021
bef831c
wasmtime neard compiles
ailisp Jan 5, 2021
22a3610
wasmtime neard compiles
ailisp Jan 5, 2021
d248733
all driver code
ailisp Jan 5, 2021
4408a0e
wip wasmer 1.0
ailisp Jan 6, 2021
ee61fbc
translate unsafe wasmer 0.17 ctx.data as safe 1.0 myEnv.logic
ailisp Jan 7, 2021
7b82b8d
fix most compile errors except wasmer error conversion
ailisp Jan 7, 2021
cac1740
fix more errors, stuck in wasmer 1.0 cannot import native func return…
ailisp Jan 9, 2021
3e52892
fix HostFunction trait not implemented issue
ailisp Jan 9, 2021
e064e6a
fix HostFunction trait not implemented issue
ailisp Jan 9, 2021
cd5d291
fix compilation errors
ailisp Jan 9, 2021
746ea2b
fix vmlogic inject
ailisp Jan 11, 2021
a63ec4a
adding all into_vm_errors, fixed some tests
ailisp Jan 12, 2021
a83d0ab
avx check and no nan check needed now
ailisp Jan 12, 2021
e563ad3
fix two more tests
ailisp Jan 12, 2021
2d1c129
fix runner stuck infinite
ailisp Jan 14, 2021
6c7ad15
fix runtime error downcast error
ailisp Jan 14, 2021
6e064f6
refactor vmlogicerror into vmerror
ailisp Jan 14, 2021
11be303
fix runtime error on call initializer
ailisp Jan 14, 2021
beccd74
fix all vm error test
ailisp Jan 14, 2021
fc4aca9
rename VMKind::Wasmer to Wasmer0
ailisp Jan 15, 2021
b3264ee
add cranelift-frontend to cargo deny
ailisp Jan 15, 2021
c5417e8
resolve conflict
ailisp Jan 15, 2021
cbd5169
fix cargo deny
ailisp Jan 15, 2021
69a77e0
fix test workspace
ailisp Jan 15, 2021
43fb8a3
workaround all-features
ailisp Jan 15, 2021
20dbb3f
reuse import reference to vmlogicreference
ailisp Jan 15, 2021
d3f2ad2
test_stack_overflow for wasmer1
ailisp Jan 15, 2021
1a2c845
fix test_stack_overflow for wasmer1
ailisp Jan 15, 2021
672e029
Merge branch 'master' into wasmer-1.0
ailisp Jan 15, 2021
b802df2
upgrade to git wasmer to get internal of RuntimeError
ailisp Jan 16, 2021
5061b4c
test wasmer trap and user error
ailisp Jan 16, 2021
5d632f5
merge master
ailisp Jan 19, 2021
841482d
rename
ailisp Jan 20, 2021
50911ae
Merge branch 'master' into wasmer-1.0
ailisp Jan 20, 2021
0f0751e
Merge branch 'master' into wasmer-1.0
olonho Jan 27, 2021
1638987
fix a compilation error from merge
ailisp Feb 1, 2021
82f69a8
actix 0.9 also works, so undo it
ailisp Feb 2, 2021
d4c8ad3
merge master resolve conflict
ailisp Feb 3, 2021
d0f377b
enable ability to build neard with wasmer 1.0
ailisp Feb 3, 2021
f452f9d
cache in wasmer1
ailisp Feb 4, 2021
afa9b25
remove delay detector
ailisp Feb 5, 2021
df0b5bf
fix feature set for ci
ailisp Feb 5, 2021
1848478
use fork released wasmer
ailisp Feb 5, 2021
e202e37
merge master
ailisp Feb 5, 2021
6f32f4e
resolve conflict in Cargo.lock
ailisp Feb 5, 2021
bae0e08
cargo deny
ailisp Feb 5, 2021
7fc2454
wasmer 1.0.2
ailisp Feb 5, 2021
9ca118e
error into
ailisp Feb 12, 2021
56e3786
typo
ailisp Feb 12, 2021
51ffe38
precompile wasmer1
ailisp Feb 12, 2021
cc338ff
wasmer1 by default, optional wasmer 0
ailisp Feb 13, 2021
b1fb114
test pass again
ailisp Feb 13, 2021
e22752a
resolve conflict
ailisp Feb 13, 2021
365ccbf
fix all tests
ailisp Feb 17, 2021
ee1b5ea
wasmer0 as default, all vm enabled in tests
ailisp Feb 17, 2021
61b8514
fix cargo check all features
ailisp Feb 17, 2021
c565693
Merge branch 'master' into wasmer-1.0
ailisp Feb 17, 2021
d7e2e1c
nit
ailisp Feb 23, 2021
6cec70f
Merge branch 'master' into wasmer-1.0
ailisp Feb 23, 2021
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
408 changes: 383 additions & 25 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ delay_detector = ["neard/delay_detector"]
rosetta_rpc = ["neard/rosetta_rpc"]
protocol_feature_forward_chunk_parts = ["neard/protocol_feature_forward_chunk_parts"]
nightly_protocol = ["near-primitives/nightly_protocol", "near-jsonrpc/nightly_protocol"]
# enable this to build neard with wasmer 1.0 runner
# now if none of wasmer0_default, wasmer1_default or wasmtime_default is enabled, wasmer1 would be default
wasmer1_default = ["node-runtime/wasmer1_default"]
wasmer0_default = ["node-runtime/wasmer0_default"]
wasmtime_default = ["node-runtime/wasmtime_default"]
# enable some of these to run runtime tests with wasmer 1.0, 0.x and wasmtime vm enabled
# but would not change default runner used by neard
wasmer1_vm = ["node-runtime/wasmer1_vm"]
wasmer0_vm = ["node-runtime/wasmer0_vm"]
wasmtime_vm = ["node-runtime/wasmtime_vm"]
nightly_protocol_features = ["nightly_protocol", "neard/nightly_protocol_features", "protocol_feature_evm", "protocol_feature_block_header_v3"]
protocol_feature_evm = ["neard/protocol_feature_evm", "testlib/protocol_feature_evm", "runtime-params-estimator/protocol_feature_evm"]
protocol_feature_block_header_v3 = ["near-primitives/protocol_feature_block_header_v3", "near-chain/protocol_feature_block_header_v3", "neard/protocol_feature_block_header_v3"]
Expand Down
15 changes: 15 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ skip = [
# actix 0.11 and actix-rt 2.0 use conflicting versions
{ name = "actix-macros", version = "=0.1.3" },

# wasmer 1.0 use some newer version of crates than wasmer 0.17 & wasmtime, old ones are skipped here
ailisp marked this conversation as resolved.
Show resolved Hide resolved
{ name = "cranelift-bforest", version = "=0.67.0" },
{ name = "cranelift-codegen", version = "=0.67.0" },
{ name = "cranelift-codegen-meta", version = "=0.67.0" },
{ name = "cranelift-codegen-shared", version = "=0.67.0" },
{ name = "cranelift-entity", version = "=0.67.0" },
{ name = "cranelift-frontend", version = "=0.67.0" },
{ name = "gimli", version = "=0.21.0" },
{ name = "libloading", version = "=0.5.2" },
{ name = "regalloc", version = "=0.0.30" },
{ name = "strsim", version = "=0.8.0" },
{ name = "wasmparser", version = "=0.57.0" },
{ name = "which", version = "=3.1.1" },
{ name = "object", version = "=0.23.0" },

# hashbrown uses an older version
{ name = "ahash", version = "=0.4.7" },
]
23 changes: 23 additions & 0 deletions runtime/near-vm-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub enum FunctionCallError {
WasmUnknownError,
HostError(HostError),
EvmError(EvmError),
/// An error message when wasmer 1.0 returns a wasmer::RuntimeError
WasmerRuntimeError(String),
/// A trap in Wasmer 1.0, not same as WasmTrap above, String is a machine readable form like "stk_ovf"
/// String is used instead of wasmer internal enum is because of BorshSerializable.
/// It can be convert back by wasmer_vm::TrapCode::from_str
Wasmer1Trap(String),
}
#[derive(
Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize, Deserialize, Serialize, RpcError,
Expand Down Expand Up @@ -277,6 +283,8 @@ pub enum VMLogicError {
EvmError(EvmError),
}

impl std::error::Error for VMLogicError {}

/// An error that is caused by an operation on an inconsistent state.
/// E.g. a deserialization error or an integer overflow.
#[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize, Deserialize, Serialize)]
Expand Down Expand Up @@ -306,6 +314,19 @@ impl From<PrepareError> for VMError {
}
}

impl From<&VMLogicError> for VMError {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why we use &VMLogicError instead of VMLogicError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There're two calls this with e.into(), one e is a &VMLogicError, another is VMLogicError, so make a From<&VMLogicError> works for both

fn from(err: &VMLogicError) -> Self {
match err {
VMLogicError::HostError(h) => {
VMError::FunctionCallError(FunctionCallError::HostError(h.clone()))
}
VMLogicError::ExternalError(s) => VMError::ExternalError(s.clone()),
VMLogicError::InconsistentStateError(e) => VMError::InconsistentStateError(e.clone()),
VMLogicError::EvmError(_) => unreachable!("Wasm can't return EVM error"),
}
}
}

impl fmt::Display for VMLogicError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
write!(f, "{:?}", self)
Expand Down Expand Up @@ -341,6 +362,8 @@ impl fmt::Display for FunctionCallError {
write!(f, "Unknown error during Wasm contract execution")
}
FunctionCallError::EvmError(e) => write!(f, "EVM: {:?}", e),
FunctionCallError::WasmerRuntimeError(e) => write!(f, "Wasmer Runtime: {}", e),
FunctionCallError::Wasmer1Trap(e) => write!(f, "Wasmer 1.0 trap: {}", e),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/near-vm-logic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ serde_json = {version= "1", features= ["preserve_order"]}
[features]
default = []
protocol_feature_evm = ["near-primitives-core/protocol_feature_evm"]
wasmer0_default = []
wasmtime_default = []

wasmer1_default = []

# Use this feature to enable counting of fees and costs applied.
costs_counting = ["near-primitives-core/costs_counting"]
Expand Down
47 changes: 40 additions & 7 deletions runtime/near-vm-logic/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,58 @@ use std::hash::Hash;

#[derive(Clone, Copy, Debug, Hash, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
pub enum VMKind {
/// Wasmer VM.
Wasmer,
/// Wasmer 0.17.x VM.
Wasmer0,
/// Wasmtime VM.
Wasmtime,
/// Wasmer 1.x VM.
Wasmer1,
}

impl Default for VMKind {
#[cfg(feature = "wasmer_default")]
#[cfg(all(
feature = "wasmer0_default",
not(feature = "wasmer1_default"),
not(feature = "wasmtime_default")
))]
fn default() -> Self {
VMKind::Wasmer
VMKind::Wasmer0
}

#[cfg(feature = "wasmtime_default")]
#[cfg(all(
not(feature = "wasmer0_default"),
feature = "wasmer1_default",
not(feature = "wasmtime_default")
))]
fn default() -> Self {
VMKind::Wasmer1
}

#[cfg(all(
not(feature = "wasmer0_default"),
not(feature = "wasmer1_default"),
feature = "wasmtime_default"
))]
fn default() -> Self {
VMKind::Wasmtime
}

#[cfg(all(not(feature = "wasmer_default"), not(feature = "wasmtime_default")))]
#[cfg(all(
not(feature = "wasmer0_default"),
not(feature = "wasmer1_default"),
not(feature = "wasmtime_default")
))]
fn default() -> Self {
VMKind::Wasmer0
}

// These features should be mutually exclusive, but implement this to work around CI cargo check --all-features
#[cfg(all(
feature = "wasmer0_default",
feature = "wasmer1_default",
feature = "wasmtime_default"
))]
fn default() -> Self {
VMKind::Wasmer
VMKind::Wasmer0
}
}
2 changes: 1 addition & 1 deletion runtime/near-vm-runner-standalone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ strum = "0.20"
num-rational = { version = "0.3" }

near-vm-logic = { path = "../near-vm-logic", version = "3.0.0", features = ["costs_counting"]}
near-vm-runner = { path = "../near-vm-runner", version = "3.0.0", features = ["wasmtime_vm"] }
near-vm-runner = { path = "../near-vm-runner", version = "3.0.0", features = ["wasmtime_vm", "wasmer1_vm"] }
near-primitives-core = { path = "../../core/primitives-core", version = "0.1.0" }

[features]
Expand Down
3 changes: 2 additions & 1 deletion runtime/near-vm-runner-standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ fn main() {
let vm_kind: VMKind = match matches.value_of("vm-kind") {
Some(value) => match value {
"wasmtime" => VMKind::Wasmtime,
"wasmer" => VMKind::Wasmer,
"wasmer" => VMKind::Wasmer0,
"wasmer1" => VMKind::Wasmer1,
_ => VMKind::default(),
},
None => VMKind::default(),
Expand Down
13 changes: 9 additions & 4 deletions runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ This crate implements the specification of the interface that Near blockchain ex

[dependencies]
borsh = "0.8.1"
wasmer-runtime = { version="0.17.1", features = ["default-backend-singlepass"], default-features = false, package = "wasmer-runtime-near" }
wasmer-runtime = { version="0.17.1", features = ["default-backend-singlepass"], default-features = false, package = "wasmer-runtime-near", optional = true }
# Always used even for wasmer 1.0 for validating wasm, will be replaced when refactor prepare.rs
wasmer-runtime-core = {version = "0.17.1", package = "wasmer-runtime-core-near" }
wasmer = { version = "1.0.2", optional = true }
wasmer-types = { version = "1.0.2", optional = true }
wasmer-compiler-singlepass = { version = "1.0.2", optional = true }
pwasm-utils = "0.12"
parity-wasm = "0.41"
wasmtime = { version = "0.20.0", default-features = false, optional = true }
Expand All @@ -33,11 +37,12 @@ wabt = "0.9"
bencher = "^0.1.5"

[features]
default = [ "wasmer_default" ]
# all vms enabled for tests, but only one default vm, specified by runtime crate
default = ["wasmer0_vm", "wasmtime_vm", "wasmer1_vm"]
wasmer0_vm = [ "wasmer-runtime" ]
wasmtime_vm = [ "wasmtime", "anyhow"]
wasmer1_vm = [ "wasmer", "wasmer-types", "wasmer-compiler-singlepass" ]
lightbeam = ["wasmtime/lightbeam"]
wasmer_default = []
wasmtime_default = ["wasmtime_vm"]
no_cpu_compatibility_checks = []
protocol_feature_evm = ["near-primitives/protocol_feature_evm", "near-evm-runner/protocol_feature_evm"]

Expand Down
Loading