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

2022 05 04 wasmer bump #1380

Merged
merged 16 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
193 changes: 129 additions & 64 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/hdk/Cargo.toml
Expand Up @@ -30,7 +30,7 @@ properties = ["holochain_zome_types/properties"]
holochain_deterministic_integrity = { version = "0.0.5", path = "../holochain_deterministic_integrity" }
hdk_derive = { version = "0.0.33", path = "../hdk_derive" }
holo_hash = { version = "0.0.25", path = "../holo_hash" }
holochain_wasmer_guest = "=0.0.77"
holochain_wasmer_guest = "=0.0.79"
# it's important that we depend on holochain_zome_types with no default
# features, both here AND in hdk_derive, to reduce code bloat
holochain_zome_types = { version = "0.0.33", path = "../holochain_zome_types", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/hdk/README.md
Expand Up @@ -88,7 +88,7 @@ let result: SerializedBytes = call_remote(
MyInput
)?;
// Get their output
let output: MyOutput = result.decode()?;
let output: MyOutput = result.decode().map_err(|e| wasm_error!(e.into()))?;
// Print their output
debug!(output);
```
Expand Down
7 changes: 5 additions & 2 deletions crates/hdk/src/countersigning.rs
Expand Up @@ -31,6 +31,9 @@ pub fn accept_countersigning_preflight_request(
pub fn session_times_from_millis(ms: u64) -> ExternResult<CounterSigningSessionTimes> {
let start = sys_time()?;
let end = start + core::time::Duration::from_millis(ms);
CounterSigningSessionTimes::try_new(start, end.map_err(|e| WasmError::Guest(e.to_string()))?)
.map_err(|e| WasmError::Guest(e.to_string()))
CounterSigningSessionTimes::try_new(
start,
end.map_err(|e| wasm_error!(WasmErrorInner::Guest(e.to_string())))?,
)
.map_err(|e| wasm_error!(WasmErrorInner::Guest(e.to_string())))
}
10 changes: 8 additions & 2 deletions crates/hdk/src/ed25519.rs
Expand Up @@ -10,7 +10,10 @@ where
K: Into<AgentPubKey>,
D: serde::Serialize + std::fmt::Debug,
{
HDK.with(|h| h.borrow().sign(Sign::new(key.into(), data)?))
HDK.with(|h| {
h.borrow()
.sign(Sign::new(key.into(), data).map_err(|e| wasm_error!(e.into()))?)
})
}

/// Sign some data using the private key for the passed public key.
Expand All @@ -33,7 +36,10 @@ pub fn sign_ephemeral<D>(datas: Vec<D>) -> ExternResult<EphemeralSignatures>
where
D: serde::Serialize + std::fmt::Debug,
{
HDK.with(|h| h.borrow().sign_ephemeral(SignEphemeral::new(datas)?))
HDK.with(|h| {
h.borrow()
.sign_ephemeral(SignEphemeral::new(datas).map_err(|e| wasm_error!(e.into()))?)
})
}

/// Sign N data using an ephemeral private key.
Expand Down
28 changes: 19 additions & 9 deletions crates/hdk/src/hash_path/anchor.rs
Expand Up @@ -53,31 +53,41 @@ impl TryFrom<&Path> for Anchor {
if components[0] == Component::new(ROOT.to_vec()) {
Ok(Anchor {
anchor_type: std::str::from_utf8(components[1].as_ref())
.map_err(|e| SerializedBytesError::Deserialize(e.to_string()))?
.map_err(|e| {
wasm_error!(SerializedBytesError::Deserialize(e.to_string()).into())
})?
.to_string(),
anchor_text: {
match components.get(2) {
Some(component) => Some(
std::str::from_utf8(component.as_ref())
.map_err(|e| SerializedBytesError::Deserialize(e.to_string()))?
.map_err(|e| {
wasm_error!(SerializedBytesError::Deserialize(
e.to_string()
)
.into())
})?
.to_string(),
),
None => None,
}
},
})
} else {
Err(WasmError::Serialize(SerializedBytesError::Deserialize(
format!(
Err(wasm_error!(WasmErrorInner::Serialize(
SerializedBytesError::Deserialize(format!(
"Bad anchor path root {:0?} should be {:1?}",
components[0].as_ref(),
ROOT,
),
),)
)))
}
} else {
Err(WasmError::Serialize(SerializedBytesError::Deserialize(
format!("Bad anchor path length {}", components.len()),
Err(wasm_error!(WasmErrorInner::Serialize(
SerializedBytesError::Deserialize(format!(
"Bad anchor path length {}",
components.len()
),)
)))
}
}
Expand Down Expand Up @@ -140,8 +150,8 @@ pub fn list_anchor_tags(anchor_type: String) -> ExternResult<Vec<String>> {
.map(|path| match Anchor::try_from(&path) {
Ok(anchor) => match anchor.anchor_text {
Some(text) => Ok(text),
None => Err(WasmError::Serialize(SerializedBytesError::Deserialize(
"missing anchor text".into(),
None => Err(wasm_error!(WasmErrorInner::Serialize(
SerializedBytesError::Deserialize("missing anchor text".into(),)
))),
},
Err(e) => Err(e),
Expand Down
10 changes: 6 additions & 4 deletions crates/hdk/src/hash_path/path.rs
Expand Up @@ -295,9 +295,11 @@ impl Path {
HdkLinkType::Paths,
LinkTag::new(match self.leaf() {
None => <Vec<u8>>::with_capacity(0),
Some(component) => {
UnsafeBytes::from(SerializedBytes::try_from(component)?).into()
}
Some(component) => UnsafeBytes::from(
SerializedBytes::try_from(component)
.map_err(|e| wasm_error!(e.into()))?,
)
.into(),
}),
)?;
}
Expand Down Expand Up @@ -345,7 +347,7 @@ impl Path {
Ok(Some(
SerializedBytes::from(UnsafeBytes::from(component_bytes.to_vec()))
.try_into()
.map_err(WasmError::Serialize)?,
.map_err(|e: SerializedBytesError| wasm_error!(e.into()))?,
))
}
})
Expand Down
4 changes: 3 additions & 1 deletion crates/hdk/src/hdk.rs
Expand Up @@ -169,7 +169,9 @@ pub struct ErrHdk;

impl ErrHdk {
fn err<T>() -> ExternResult<T> {
Err(WasmError::Guest(HDK_NOT_REGISTERED.to_string()))
Err(wasm_error!(WasmErrorInner::Guest(
HDK_NOT_REGISTERED.to_string()
)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hdk/src/lib.rs
Expand Up @@ -99,7 +99,7 @@
//! - The function must return an `ExternResult` where the success value implements `serde::Serialize + std::fmt::Debug`
//! - The function must have a unique name across all externs as they share a global namespace in WASM
//! - Everything inside the function is Rust-as-usual including `?` to interact with `ExternResult` that fails as `WasmError`
//! - Use the `WasmError::Guest` variant for failure conditions that the host or external processes needs to be aware of
//! - Use the `WasmErrorInner::Guest` variant for failure conditions that the host or external processes needs to be aware of
//! - Externed functions can be called as normal by other functions inside the same WASM
//!
//! For example:
Expand Down
11 changes: 6 additions & 5 deletions crates/hdk/src/p2p.rs
Expand Up @@ -28,7 +28,7 @@ where
zome_name,
fn_name,
cap_secret,
ExternIO::encode(payload)?,
ExternIO::encode(payload).map_err(|e| wasm_error!(e.into()))?,
)])
})?
.into_iter()
Expand Down Expand Up @@ -76,7 +76,7 @@ where
zome,
fn_name,
cap_secret,
ExternIO::encode(payload)?,
ExternIO::encode(payload).map_err(|e| wasm_error!(e.into()))?,
)])
})?
.into_iter()
Expand All @@ -98,8 +98,9 @@ where
I: serde::Serialize + std::fmt::Debug,
{
HDK.with(|h| {
h.borrow()
.emit_signal(AppSignal::new(ExternIO::encode(input)?))
h.borrow().emit_signal(AppSignal::new(
ExternIO::encode(input).map_err(|e| wasm_error!(e.into()))?,
))
})
}

Expand Down Expand Up @@ -136,7 +137,7 @@ where
{
HDK.with(|h| {
h.borrow().remote_signal(RemoteSignal {
signal: ExternIO::encode(input)?,
signal: ExternIO::encode(input).map_err(|e| wasm_error!(e.into()))?,
agents,
})
})
Expand Down
5 changes: 4 additions & 1 deletion crates/holochain/Cargo.toml
Expand Up @@ -31,7 +31,7 @@ holochain_sqlite = { version = "0.0.37", path = "../holochain_sqlite" }
holochain_serialized_bytes = "=0.0.51"
holochain_state = { version = "0.0.39", path = "../holochain_state" }
holochain_types = { version = "0.0.37", path = "../holochain_types" }
holochain_wasmer_host = "=0.0.77"
holochain_wasmer_host = "=0.0.79"
holochain_websocket = { version = "0.0.37", path = "../holochain_websocket" }
holochain_zome_types = { version = "0.0.33", path = "../holochain_zome_types", features = ["full"] }
human-panic = "1.0.3"
Expand Down Expand Up @@ -163,3 +163,6 @@ db-encryption = ['holochain_sqlite/db-encryption']
# Compile SQLite from source rather than depending on a library.
# Incompatible with "db-encryption"
no-deps = ['holochain_sqlite/no-deps']

# Extremely verbose wasm memory read/write logging
wasmer_debug_memory = ["holochain_wasmer_host/debug_memory"]
8 changes: 4 additions & 4 deletions crates/holochain/src/core/ribosome/error.rs
Expand Up @@ -8,7 +8,7 @@ use holochain_cascade::error::CascadeError;
use holochain_serialized_bytes::prelude::SerializedBytesError;
use holochain_state::source_chain::SourceChainError;
use holochain_types::prelude::*;
use holochain_wasmer_host::prelude::WasmError;
use holochain_wasmer_host::prelude::*;
use holochain_zome_types::inline_zome::error::InlineZomeError;
use thiserror::Error;
use tokio::task::JoinError;
Expand All @@ -20,9 +20,9 @@ pub enum RibosomeError {
#[error("Dna error while working with Ribosome: {0}")]
DnaError(#[from] DnaError),

/// Wasm error while working with Ribosome.
#[error("Wasm error while working with Ribosome: {0}")]
WasmError(#[from] WasmError),
/// Wasm runtime error while working with Ribosome.
#[error("Wasm runtime error while working with Ribosome: {0}")]
WasmRuntimeError(#[from] RuntimeError),

/// Serialization error while working with Ribosome.
#[error("Serialization error while working with Ribosome: {0}")]
Expand Down
Expand Up @@ -3,7 +3,7 @@ use crate::core::ribosome::HostFnAccess;
use crate::core::ribosome::RibosomeError;
use crate::core::ribosome::RibosomeT;
use holochain_types::prelude::*;
use holochain_wasmer_host::prelude::WasmError;
use holochain_wasmer_host::prelude::*;
use std::sync::Arc;
use tracing::error;

Expand All @@ -12,7 +12,7 @@ pub fn accept_countersigning_preflight_request<'a>(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
input: PreflightRequest,
) -> Result<PreflightRequestAcceptance, WasmError> {
) -> Result<PreflightRequestAcceptance, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
agent_info: Permission::Allow,
Expand Down Expand Up @@ -50,8 +50,8 @@ pub fn accept_countersigning_preflight_request<'a>(
.expect("Must have source chain if write_workspace access is given")
.accept_countersigning_preflight_request(input.clone(), agent_index)
.await
.map_err(|source_chain_error| {
WasmError::Host(source_chain_error.to_string())
.map_err(|source_chain_error| -> RuntimeError {
wasm_error!(WasmErrorInner::Host(source_chain_error.to_string())).into()
})?;
let signature: Signature = match call_context
.host_context
Expand All @@ -61,7 +61,8 @@ pub fn accept_countersigning_preflight_request<'a>(
PreflightResponse::encode_fields_for_signature(
&input,
&countersigning_agent_state,
)?
)
.map_err(|e| -> RuntimeError { wasm_error!(e.into()).into() })?
.into(),
)
.await
Expand All @@ -82,24 +83,27 @@ pub fn accept_countersigning_preflight_request<'a>(
{
error!(?unlock_result);
}
return Err(WasmError::Host(e.to_string()));
return Err(wasm_error!(WasmErrorInner::Host(e.to_string())).into());
}
};

Ok(PreflightRequestAcceptance::Accepted(
PreflightResponse::try_new(input, countersigning_agent_state, signature)
.map_err(|e| WasmError::Host(e.to_string()))?,
.map_err(|e| -> RuntimeError {
wasm_error!(WasmErrorInner::Host(e.to_string())).into()
})?,
))
})
}
_ => Err(WasmError::Host(
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"accept_countersigning_preflight_request".into(),
)
.to_string(),
)),
))
.into()),
}
}

Expand All @@ -110,11 +114,12 @@ pub mod wasm_test {
use crate::conductor::api::ZomeCall;
use crate::conductor::CellError;
use crate::core::ribosome::error::RibosomeError;
use crate::core::ribosome::wasm_test::RibosomeTestFixture;
use crate::core::workflow::error::WorkflowError;
use hdk::prelude::*;
use holochain_state::source_chain::SourceChainError;
use holochain_wasm_test_utils::TestWasm;
use crate::core::ribosome::wasm_test::RibosomeTestFixture;
use holochain_wasmer_host::prelude::*;

/// Allow ChainLocked error, panic on anything else
fn expect_chain_locked(
Expand Down Expand Up @@ -295,7 +300,7 @@ pub mod wasm_test {
.await;
assert!(matches!(
preflight_acceptance_fail,
Ok(Err(RibosomeError::WasmError(WasmError::Host(_))))
Ok(Err(RibosomeError::WasmRuntimeError(RuntimeError { .. })))
));

// Bob can also accept the preflight request.
Expand Down
10 changes: 5 additions & 5 deletions crates/holochain/src/core/ribosome/host_fn/agent_info.rs
Expand Up @@ -2,7 +2,7 @@ use crate::core::ribosome::CallContext;
use crate::core::ribosome::HostFnAccess;
use crate::core::ribosome::RibosomeT;
use holochain_types::prelude::*;
use holochain_wasmer_host::prelude::WasmError;
use holochain_wasmer_host::prelude::*;
use crate::core::ribosome::RibosomeError;
use std::sync::Arc;

Expand All @@ -11,7 +11,7 @@ pub fn agent_info<'a>(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<AgentInfo, WasmError> {
) -> Result<AgentInfo, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
agent_info: Permission::Allow,
Expand All @@ -35,14 +35,14 @@ pub fn agent_info<'a>(
.as_ref()
.expect("Must have source chain if agent_info access is given")
.chain_head()
.map_err(|e| WasmError::Host(e.to_string()))?,
.map_err(|e| wasm_error!(WasmErrorInner::Host(e.to_string())))?,
})
}
_ => Err(WasmError::Host(RibosomeError::HostFnPermissions(
_ => Err(wasm_error!(WasmErrorInner::Host(RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"agent_info".into()
).to_string()))
).to_string())).into())
}
}

Expand Down