From ea2be32cfc6089e4d7fc2fe38dca5f9ec93950ad Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 13 Jan 2021 21:31:42 +0100 Subject: [PATCH 01/10] Add stargate feature and first ibc vm call --- packages/vm/Cargo.toml | 2 ++ packages/vm/src/calls.rs | 2 +- packages/vm/src/ibc_calls.rs | 28 ++++++++++++++++++++++++++++ packages/vm/src/lib.rs | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 packages/vm/src/ibc_calls.rs diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml index 9423985a5c..8863e07aea 100644 --- a/packages/vm/Cargo.toml +++ b/packages/vm/Cargo.toml @@ -24,6 +24,8 @@ backtraces = [] # we keep this optional, to allow possible future integration (or different Cosmos Backends) iterator = ["cosmwasm-std/iterator"] staking = ["cosmwasm-std/staking"] +# this enables all stargate-related functionality, including the ibc entry points +stargate = ["cosmwasm-std/stargate"] # Use cranelift backend instead of singlepass. This is required for development on Windows. cranelift = ["wasmer/cranelift"] diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index 470a3f3a6b..974f965c81 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -168,7 +168,7 @@ where /// Calls a function with the given arguments. /// The exported function must return exactly one result (an offset to the result Region). -fn call_raw( +pub(crate) fn call_raw( instance: &mut Instance, name: &str, args: &[&[u8]], diff --git a/packages/vm/src/ibc_calls.rs b/packages/vm/src/ibc_calls.rs new file mode 100644 index 0000000000..d483f0b89e --- /dev/null +++ b/packages/vm/src/ibc_calls.rs @@ -0,0 +1,28 @@ +#![cfg(feature = "stargate")] +use cosmwasm_std::{ContractResult, Env, IbcChannel}; + +use crate::backend::{Api, Querier, Storage}; +use crate::calls::call_raw; +use crate::errors::VmResult; +use crate::instance::Instance; +use crate::serde::{from_slice, to_vec}; + +const MAX_LENGTH_IBC: usize = 100_000; + +pub fn call_ibc_channel_open( + instance: &mut Instance, + env: &Env, + channel: &IbcChannel, +) -> VmResult> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + let env = to_vec(env)?; + let msg = to_vec(channel)?; + instance.set_storage_readonly(false); + let data = call_raw(instance, "ibc_channel_open", &[&env, &msg], MAX_LENGTH_IBC)?; + let result: ContractResult<()> = from_slice(&data)?; + Ok(result) +} diff --git a/packages/vm/src/lib.rs b/packages/vm/src/lib.rs index fb57ba199f..982af0ad58 100644 --- a/packages/vm/src/lib.rs +++ b/packages/vm/src/lib.rs @@ -9,6 +9,7 @@ mod conversion; mod environment; mod errors; mod features; +mod ibc_calls; mod imports; mod instance; mod limited; @@ -32,6 +33,8 @@ pub use crate::errors::{ VmError, VmResult, }; pub use crate::features::features_from_csv; +#[cfg(feature = "stargate")] +pub use crate::ibc_calls::call_ibc_channel_open; pub use crate::instance::{GasReport, Instance, InstanceOptions}; pub use crate::serde::{from_slice, to_vec}; pub use crate::size::Size; From 5332621f8f6a1924b86118a216ae177fd76a4736 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 13 Jan 2021 21:40:30 +0100 Subject: [PATCH 02/10] Add all ibc entry points to the vm calls --- packages/vm/src/ibc_calls.rs | 118 ++++++++++++++++++++++++++++++++++- packages/vm/src/lib.rs | 5 +- 2 files changed, 121 insertions(+), 2 deletions(-) diff --git a/packages/vm/src/ibc_calls.rs b/packages/vm/src/ibc_calls.rs index d483f0b89e..f8681db577 100644 --- a/packages/vm/src/ibc_calls.rs +++ b/packages/vm/src/ibc_calls.rs @@ -1,5 +1,11 @@ #![cfg(feature = "stargate")] -use cosmwasm_std::{ContractResult, Env, IbcChannel}; +use cosmwasm_std::{ + ContractResult, Env, IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcPacket, + IbcReceiveResponse, +}; +use schemars::JsonSchema; +use serde::de::DeserializeOwned; +use std::fmt; use crate::backend::{Api, Querier, Storage}; use crate::calls::call_raw; @@ -26,3 +32,113 @@ where let result: ContractResult<()> = from_slice(&data)?; Ok(result) } + +pub fn call_ibc_channel_connect( + instance: &mut Instance, + env: &Env, + channel: &IbcChannel, +) -> VmResult>> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, +{ + let env = to_vec(env)?; + let msg = to_vec(channel)?; + instance.set_storage_readonly(false); + let data = call_raw( + instance, + "ibc_channel_connect", + &[&env, &msg], + MAX_LENGTH_IBC, + )?; + let result = from_slice(&data)?; + Ok(result) +} + +pub fn call_ibc_channel_close( + instance: &mut Instance, + env: &Env, + channel: &IbcChannel, +) -> VmResult>> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, +{ + let env = to_vec(env)?; + let msg = to_vec(channel)?; + instance.set_storage_readonly(false); + let data = call_raw(instance, "ibc_channel_close", &[&env, &msg], MAX_LENGTH_IBC)?; + let result = from_slice(&data)?; + Ok(result) +} + +pub fn call_ibc_packet_receive( + instance: &mut Instance, + env: &Env, + packet: &IbcPacket, +) -> VmResult>> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, +{ + let env = to_vec(env)?; + let msg = to_vec(packet)?; + instance.set_storage_readonly(false); + let data = call_raw( + instance, + "ibc_packet_receive", + &[&env, &msg], + MAX_LENGTH_IBC, + )?; + let result = from_slice(&data)?; + Ok(result) +} + +pub fn call_ibc_packet_ack( + instance: &mut Instance, + env: &Env, + channel: &IbcAcknowledgement, +) -> VmResult>> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, +{ + let env = to_vec(env)?; + let msg = to_vec(channel)?; + instance.set_storage_readonly(false); + let data = call_raw(instance, "ibc_packet_ack", &[&env, &msg], MAX_LENGTH_IBC)?; + let result = from_slice(&data)?; + Ok(result) +} + +pub fn call_ibc_packet_timeout( + instance: &mut Instance, + env: &Env, + channel: &IbcPacket, +) -> VmResult>> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, +{ + let env = to_vec(env)?; + let msg = to_vec(channel)?; + instance.set_storage_readonly(false); + let data = call_raw( + instance, + "ibc_packet_timeout", + &[&env, &msg], + MAX_LENGTH_IBC, + )?; + let result = from_slice(&data)?; + Ok(result) +} diff --git a/packages/vm/src/lib.rs b/packages/vm/src/lib.rs index 982af0ad58..c6dea0be8f 100644 --- a/packages/vm/src/lib.rs +++ b/packages/vm/src/lib.rs @@ -34,7 +34,10 @@ pub use crate::errors::{ }; pub use crate::features::features_from_csv; #[cfg(feature = "stargate")] -pub use crate::ibc_calls::call_ibc_channel_open; +pub use crate::ibc_calls::{ + call_ibc_channel_close, call_ibc_channel_connect, call_ibc_channel_open, call_ibc_packet_ack, + call_ibc_packet_receive, call_ibc_packet_timeout, +}; pub use crate::instance::{GasReport, Instance, InstanceOptions}; pub use crate::serde::{from_slice, to_vec}; pub use crate::size::Size; From d7c8d08f2caf277c6bde701335bb06a15dffdfaf Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 13 Jan 2021 21:52:05 +0100 Subject: [PATCH 03/10] Start adding testing call helpers --- packages/vm/src/ibc_calls.rs | 1 + packages/vm/src/testing/ibc_calls.rs | 60 ++++++++++++++++++++++++++++ packages/vm/src/testing/mod.rs | 3 ++ 3 files changed, 64 insertions(+) create mode 100644 packages/vm/src/testing/ibc_calls.rs diff --git a/packages/vm/src/ibc_calls.rs b/packages/vm/src/ibc_calls.rs index f8681db577..5c7185488c 100644 --- a/packages/vm/src/ibc_calls.rs +++ b/packages/vm/src/ibc_calls.rs @@ -1,4 +1,5 @@ #![cfg(feature = "stargate")] + use cosmwasm_std::{ ContractResult, Env, IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcPacket, IbcReceiveResponse, diff --git a/packages/vm/src/testing/ibc_calls.rs b/packages/vm/src/testing/ibc_calls.rs new file mode 100644 index 0000000000..7bd10de2da --- /dev/null +++ b/packages/vm/src/testing/ibc_calls.rs @@ -0,0 +1,60 @@ +#![cfg(feature = "stargate")] +use schemars::JsonSchema; +use serde::de::DeserializeOwned; +use std::fmt; + +use cosmwasm_std::{ContractResult, Env, IbcBasicResponse, IbcChannel}; + +use crate::ibc_calls::{call_ibc_channel_close, call_ibc_channel_connect, call_ibc_channel_open}; +use crate::instance::Instance; +use crate::{Api, Querier, Storage}; + +// ibc_channel_open mimicks the call signature of the smart contracts. +// thus it moves env and channel rather than take them as reference. +// this is inefficient here, but only used in test code +pub fn ibc_channel_open( + instance: &mut Instance, + env: Env, + channel: IbcChannel, +) -> ContractResult<()> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + call_ibc_channel_open(instance, &env, &channel).expect("VM error") +} + +// ibc_channel_connect mimicks the call signature of the smart contracts. +// thus it moves env and channel rather than take them as reference. +// this is inefficient here, but only used in test code +pub fn ibc_channel_connect( + instance: &mut Instance, + env: Env, + channel: IbcChannel, +) -> ContractResult> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug, +{ + call_ibc_channel_connect(instance, &env, &channel).expect("VM error") +} + +// ibc_channel_connect mimicks the call signature of the smart contracts. +// thus it moves env and channel rather than take them as reference. +// this is inefficient here, but only used in test code +pub fn ibc_channel_close( + instance: &mut Instance, + env: Env, + channel: IbcChannel, +) -> ContractResult> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug, +{ + call_ibc_channel_close(instance, &env, &channel).expect("VM error") +} diff --git a/packages/vm/src/testing/mod.rs b/packages/vm/src/testing/mod.rs index d47c13c093..04da84f622 100644 --- a/packages/vm/src/testing/mod.rs +++ b/packages/vm/src/testing/mod.rs @@ -1,12 +1,15 @@ // The external interface is `use cosmwasm_vm::testing::X` for all integration testing symbols, no matter where they live internally. mod calls; +mod ibc_calls; mod instance; mod mock; mod querier; mod storage; pub use calls::{handle, init, migrate, query}; +#[cfg(feature = "stargate")] +pub use ibc_calls::{ibc_channel_close, ibc_channel_connect, ibc_channel_open}; pub use instance::{ mock_instance, mock_instance_options, mock_instance_with_balances, mock_instance_with_failing_api, mock_instance_with_gas_limit, mock_instance_with_options, From 0493f9a8795f01cf98fe56ae58365b758b7a3a40 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 13 Jan 2021 22:01:24 +0100 Subject: [PATCH 04/10] Add remaining ibc calls to testing helpers --- packages/vm/src/testing/ibc_calls.rs | 63 ++++++++++++++++++++++++++-- packages/vm/src/testing/mod.rs | 5 ++- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/packages/vm/src/testing/ibc_calls.rs b/packages/vm/src/testing/ibc_calls.rs index 7bd10de2da..c342c30ea3 100644 --- a/packages/vm/src/testing/ibc_calls.rs +++ b/packages/vm/src/testing/ibc_calls.rs @@ -3,9 +3,15 @@ use schemars::JsonSchema; use serde::de::DeserializeOwned; use std::fmt; -use cosmwasm_std::{ContractResult, Env, IbcBasicResponse, IbcChannel}; +use cosmwasm_std::{ + ContractResult, Env, IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcPacket, + IbcReceiveResponse, +}; -use crate::ibc_calls::{call_ibc_channel_close, call_ibc_channel_connect, call_ibc_channel_open}; +use crate::ibc_calls::{ + call_ibc_channel_close, call_ibc_channel_connect, call_ibc_channel_open, call_ibc_packet_ack, + call_ibc_packet_receive, call_ibc_packet_timeout, +}; use crate::instance::Instance; use crate::{Api, Querier, Storage}; @@ -42,7 +48,7 @@ where call_ibc_channel_connect(instance, &env, &channel).expect("VM error") } -// ibc_channel_connect mimicks the call signature of the smart contracts. +// ibc_channel_close mimicks the call signature of the smart contracts. // thus it moves env and channel rather than take them as reference. // this is inefficient here, but only used in test code pub fn ibc_channel_close( @@ -58,3 +64,54 @@ where { call_ibc_channel_close(instance, &env, &channel).expect("VM error") } + +// ibc_packet_receive mimicks the call signature of the smart contracts. +// thus it moves env and packet rather than take them as reference. +// this is inefficient here, but only used in test code +pub fn ibc_packet_receive( + instance: &mut Instance, + env: Env, + packet: IbcPacket, +) -> ContractResult> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug, +{ + call_ibc_packet_receive(instance, &env, &packet).expect("VM error") +} + +// ibc_packet_ack mimicks the call signature of the smart contracts. +// thus it moves env and acknowledgement rather than take them as reference. +// this is inefficient here, but only used in test code +pub fn ibc_packet_ack( + instance: &mut Instance, + env: Env, + ack: IbcAcknowledgement, +) -> ContractResult> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug, +{ + call_ibc_packet_ack(instance, &env, &ack).expect("VM error") +} + +// ibc_packet_timeout mimicks the call signature of the smart contracts. +// thus it moves env and packet rather than take them as reference. +// this is inefficient here, but only used in test code +pub fn ibc_packet_timeout( + instance: &mut Instance, + env: Env, + packet: IbcPacket, +) -> ContractResult> +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, + U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug, +{ + call_ibc_packet_timeout(instance, &env, &packet).expect("VM error") +} diff --git a/packages/vm/src/testing/mod.rs b/packages/vm/src/testing/mod.rs index 04da84f622..a31bc76473 100644 --- a/packages/vm/src/testing/mod.rs +++ b/packages/vm/src/testing/mod.rs @@ -9,7 +9,10 @@ mod storage; pub use calls::{handle, init, migrate, query}; #[cfg(feature = "stargate")] -pub use ibc_calls::{ibc_channel_close, ibc_channel_connect, ibc_channel_open}; +pub use ibc_calls::{ + ibc_channel_close, ibc_channel_connect, ibc_channel_open, ibc_packet_ack, ibc_packet_receive, + ibc_packet_timeout, +}; pub use instance::{ mock_instance, mock_instance_options, mock_instance_with_balances, mock_instance_with_failing_api, mock_instance_with_gas_limit, mock_instance_with_options, From 0392d22cc654e4498d8133032df610470c8d7508 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 13 Jan 2021 21:57:34 +0100 Subject: [PATCH 05/10] MockInstance supports stargate export if stargate feature enabled --- packages/vm/src/testing/instance.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/vm/src/testing/instance.rs b/packages/vm/src/testing/instance.rs index 8d6ac75238..e1eec97fb1 100644 --- a/packages/vm/src/testing/instance.rs +++ b/packages/vm/src/testing/instance.rs @@ -92,6 +92,18 @@ pub struct MockInstanceOptions<'a> { pub memory_limit: Option, } +impl MockInstanceOptions<'_> { + #[cfg(feature = "stargate")] + fn default_features() -> HashSet { + features_from_csv("staking,stargate") + } + + #[cfg(not(feature = "stargate"))] + fn default_features() -> HashSet { + features_from_csv("staking") + } +} + impl Default for MockInstanceOptions<'_> { fn default() -> Self { Self { @@ -101,7 +113,7 @@ impl Default for MockInstanceOptions<'_> { backend_error: None, // instance - supported_features: features_from_csv("staking"), + supported_features: Self::default_features(), gas_limit: DEFAULT_GAS_LIMIT, print_debug: DEFAULT_PRINT_DEBUG, memory_limit: DEFAULT_MEMORY_LIMIT, From 02aba72cc3fd8d08e2e1216069c8af52b980ed3c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 13 Jan 2021 22:04:09 +0100 Subject: [PATCH 06/10] Add stargate testing to cosmwasm-vm in CI --- .circleci/config.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2d2ac008d4..8571d83355 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -176,6 +176,10 @@ jobs: name: Build with iterator working_directory: ~/project/packages/vm command: cargo build --locked --features iterator + - run: + name: Build for stargate + working_directory: ~/project/packages/vm + command: cargo build --locked --features iterator,staking,stargate - run: name: Test working_directory: ~/project/packages/vm @@ -184,6 +188,10 @@ jobs: name: Test with iterator working_directory: ~/project/packages/vm command: cargo test --locked --features iterator + - run: + name: Test for stargate + working_directory: ~/project/packages/vm + command: cargo test --locked --features iterator,staking,stargate - save_cache: paths: - /usr/local/cargo/registry From 73403e2740347d24dd3f4dabe6a63ed97b739f92 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 14 Jan 2021 16:27:34 +0100 Subject: [PATCH 07/10] Remove unused generic parameter --- packages/vm/src/testing/ibc_calls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vm/src/testing/ibc_calls.rs b/packages/vm/src/testing/ibc_calls.rs index c342c30ea3..d109baa4f2 100644 --- a/packages/vm/src/testing/ibc_calls.rs +++ b/packages/vm/src/testing/ibc_calls.rs @@ -18,7 +18,7 @@ use crate::{Api, Querier, Storage}; // ibc_channel_open mimicks the call signature of the smart contracts. // thus it moves env and channel rather than take them as reference. // this is inefficient here, but only used in test code -pub fn ibc_channel_open( +pub fn ibc_channel_open( instance: &mut Instance, env: Env, channel: IbcChannel, From 5047572add1d44685d2a77cfdef0adc817e1901d Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 14 Jan 2021 17:45:10 +0100 Subject: [PATCH 08/10] Add _raw variants of the ibc vm calls --- packages/vm/src/ibc_calls.rs | 133 ++++++++++++++++++++++++++--------- packages/vm/src/lib.rs | 6 +- 2 files changed, 102 insertions(+), 37 deletions(-) diff --git a/packages/vm/src/ibc_calls.rs b/packages/vm/src/ibc_calls.rs index 5c7185488c..53d53c2b79 100644 --- a/packages/vm/src/ibc_calls.rs +++ b/packages/vm/src/ibc_calls.rs @@ -27,9 +27,8 @@ where Q: Querier + 'static, { let env = to_vec(env)?; - let msg = to_vec(channel)?; - instance.set_storage_readonly(false); - let data = call_raw(instance, "ibc_channel_open", &[&env, &msg], MAX_LENGTH_IBC)?; + let channel = to_vec(channel)?; + let data = call_ibc_channel_open_raw(instance, &env, &channel)?; let result: ContractResult<()> = from_slice(&data)?; Ok(result) } @@ -46,14 +45,8 @@ where U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, { let env = to_vec(env)?; - let msg = to_vec(channel)?; - instance.set_storage_readonly(false); - let data = call_raw( - instance, - "ibc_channel_connect", - &[&env, &msg], - MAX_LENGTH_IBC, - )?; + let channel = to_vec(channel)?; + let data = call_ibc_channel_connect_raw(instance, &env, &channel)?; let result = from_slice(&data)?; Ok(result) } @@ -70,9 +63,8 @@ where U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, { let env = to_vec(env)?; - let msg = to_vec(channel)?; - instance.set_storage_readonly(false); - let data = call_raw(instance, "ibc_channel_close", &[&env, &msg], MAX_LENGTH_IBC)?; + let channel = to_vec(channel)?; + let data = call_ibc_channel_close_raw(instance, &env, &channel)?; let result = from_slice(&data)?; Ok(result) } @@ -89,14 +81,8 @@ where U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, { let env = to_vec(env)?; - let msg = to_vec(packet)?; - instance.set_storage_readonly(false); - let data = call_raw( - instance, - "ibc_packet_receive", - &[&env, &msg], - MAX_LENGTH_IBC, - )?; + let packet = to_vec(packet)?; + let data = call_ibc_packet_receive_raw(instance, &env, &packet)?; let result = from_slice(&data)?; Ok(result) } @@ -104,7 +90,7 @@ where pub fn call_ibc_packet_ack( instance: &mut Instance, env: &Env, - channel: &IbcAcknowledgement, + ack: &IbcAcknowledgement, ) -> VmResult>> where A: Api + 'static, @@ -113,9 +99,8 @@ where U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, { let env = to_vec(env)?; - let msg = to_vec(channel)?; - instance.set_storage_readonly(false); - let data = call_raw(instance, "ibc_packet_ack", &[&env, &msg], MAX_LENGTH_IBC)?; + let ack = to_vec(ack)?; + let data = call_ibc_packet_ack_raw(instance, &env, &ack)?; let result = from_slice(&data)?; Ok(result) } @@ -123,7 +108,7 @@ where pub fn call_ibc_packet_timeout( instance: &mut Instance, env: &Env, - channel: &IbcPacket, + packet: &IbcPacket, ) -> VmResult>> where A: Api + 'static, @@ -132,14 +117,92 @@ where U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq, { let env = to_vec(env)?; - let msg = to_vec(channel)?; - instance.set_storage_readonly(false); - let data = call_raw( - instance, - "ibc_packet_timeout", - &[&env, &msg], - MAX_LENGTH_IBC, - )?; + let packet = to_vec(packet)?; + let data = call_ibc_packet_timeout_raw(instance, &env, &packet)?; let result = from_slice(&data)?; Ok(result) } + +pub fn call_ibc_channel_open_raw( + instance: &mut Instance, + env: &[u8], + channel: &[u8], +) -> VmResult> + where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + instance.set_storage_readonly(false); + call_raw(instance, "ibc_channel_open", &[env, channel], MAX_LENGTH_IBC) +} + +pub fn call_ibc_channel_connect_raw( + instance: &mut Instance, + env: &[u8], + channel: &[u8], +) -> VmResult> + where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + instance.set_storage_readonly(false); + call_raw(instance, "ibc_channel_connect", &[env, channel], MAX_LENGTH_IBC) +} + +pub fn call_ibc_channel_close_raw( + instance: &mut Instance, + env: &[u8], + channel: &[u8], +) -> VmResult> + where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + instance.set_storage_readonly(false); + call_raw(instance, "ibc_channel_close", &[env, channel], MAX_LENGTH_IBC) +} + +pub fn call_ibc_packet_receive_raw( + instance: &mut Instance, + env: &[u8], + packet: &[u8], +) -> VmResult> + where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + instance.set_storage_readonly(false); + call_raw(instance, "ibc_packet_receive", &[env, packet], MAX_LENGTH_IBC) +} + +pub fn call_ibc_packet_ack_raw( + instance: &mut Instance, + env: &[u8], + ack: &[u8], +) -> VmResult> + where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + instance.set_storage_readonly(false); + call_raw(instance, "ibc_packet_ack", &[env, ack], MAX_LENGTH_IBC) +} + +pub fn call_ibc_packet_timeout_raw( + instance: &mut Instance, + env: &[u8], + packet: &[u8], +) -> VmResult> + where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, +{ + instance.set_storage_readonly(false); + call_raw(instance, "ibc_packet_timeout", &[env, packet], MAX_LENGTH_IBC) +} diff --git a/packages/vm/src/lib.rs b/packages/vm/src/lib.rs index c6dea0be8f..dc3b37bc87 100644 --- a/packages/vm/src/lib.rs +++ b/packages/vm/src/lib.rs @@ -35,8 +35,10 @@ pub use crate::errors::{ pub use crate::features::features_from_csv; #[cfg(feature = "stargate")] pub use crate::ibc_calls::{ - call_ibc_channel_close, call_ibc_channel_connect, call_ibc_channel_open, call_ibc_packet_ack, - call_ibc_packet_receive, call_ibc_packet_timeout, + call_ibc_channel_close, call_ibc_channel_close_raw, call_ibc_channel_connect, + call_ibc_channel_connect_raw, call_ibc_channel_open, call_ibc_channel_open_raw, + call_ibc_packet_ack, call_ibc_packet_ack_raw, call_ibc_packet_receive, + call_ibc_packet_receive_raw, call_ibc_packet_timeout, call_ibc_packet_timeout_raw, }; pub use crate::instance::{GasReport, Instance, InstanceOptions}; pub use crate::serde::{from_slice, to_vec}; From f16adcd7ba0654ecadebfb48901f3e297f3e27a7 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 14 Jan 2021 17:51:58 +0100 Subject: [PATCH 09/10] cargo fmt --- packages/vm/src/ibc_calls.rs | 83 +++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/packages/vm/src/ibc_calls.rs b/packages/vm/src/ibc_calls.rs index 53d53c2b79..fe07a20fd4 100644 --- a/packages/vm/src/ibc_calls.rs +++ b/packages/vm/src/ibc_calls.rs @@ -128,13 +128,18 @@ pub fn call_ibc_channel_open_raw( env: &[u8], channel: &[u8], ) -> VmResult> - where - A: Api + 'static, - S: Storage + 'static, - Q: Querier + 'static, +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, { instance.set_storage_readonly(false); - call_raw(instance, "ibc_channel_open", &[env, channel], MAX_LENGTH_IBC) + call_raw( + instance, + "ibc_channel_open", + &[env, channel], + MAX_LENGTH_IBC, + ) } pub fn call_ibc_channel_connect_raw( @@ -142,13 +147,18 @@ pub fn call_ibc_channel_connect_raw( env: &[u8], channel: &[u8], ) -> VmResult> - where - A: Api + 'static, - S: Storage + 'static, - Q: Querier + 'static, +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, { instance.set_storage_readonly(false); - call_raw(instance, "ibc_channel_connect", &[env, channel], MAX_LENGTH_IBC) + call_raw( + instance, + "ibc_channel_connect", + &[env, channel], + MAX_LENGTH_IBC, + ) } pub fn call_ibc_channel_close_raw( @@ -156,13 +166,18 @@ pub fn call_ibc_channel_close_raw( env: &[u8], channel: &[u8], ) -> VmResult> - where - A: Api + 'static, - S: Storage + 'static, - Q: Querier + 'static, +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, { instance.set_storage_readonly(false); - call_raw(instance, "ibc_channel_close", &[env, channel], MAX_LENGTH_IBC) + call_raw( + instance, + "ibc_channel_close", + &[env, channel], + MAX_LENGTH_IBC, + ) } pub fn call_ibc_packet_receive_raw( @@ -170,13 +185,18 @@ pub fn call_ibc_packet_receive_raw( env: &[u8], packet: &[u8], ) -> VmResult> - where - A: Api + 'static, - S: Storage + 'static, - Q: Querier + 'static, +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, { instance.set_storage_readonly(false); - call_raw(instance, "ibc_packet_receive", &[env, packet], MAX_LENGTH_IBC) + call_raw( + instance, + "ibc_packet_receive", + &[env, packet], + MAX_LENGTH_IBC, + ) } pub fn call_ibc_packet_ack_raw( @@ -184,10 +204,10 @@ pub fn call_ibc_packet_ack_raw( env: &[u8], ack: &[u8], ) -> VmResult> - where - A: Api + 'static, - S: Storage + 'static, - Q: Querier + 'static, +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, { instance.set_storage_readonly(false); call_raw(instance, "ibc_packet_ack", &[env, ack], MAX_LENGTH_IBC) @@ -198,11 +218,16 @@ pub fn call_ibc_packet_timeout_raw( env: &[u8], packet: &[u8], ) -> VmResult> - where - A: Api + 'static, - S: Storage + 'static, - Q: Querier + 'static, +where + A: Api + 'static, + S: Storage + 'static, + Q: Querier + 'static, { instance.set_storage_readonly(false); - call_raw(instance, "ibc_packet_timeout", &[env, packet], MAX_LENGTH_IBC) + call_raw( + instance, + "ibc_packet_timeout", + &[env, packet], + MAX_LENGTH_IBC, + ) } From 790c0462e228202a796d68f430322fa92fabf660 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 14 Jan 2021 19:21:07 +0100 Subject: [PATCH 10/10] Cleanup from PR comments --- .circleci/config.yml | 20 ++++++-------------- packages/vm/src/lib.rs | 1 + 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8571d83355..09dbda2c7f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -173,11 +173,7 @@ jobs: working_directory: ~/project/packages/vm command: cargo build --locked - run: - name: Build with iterator - working_directory: ~/project/packages/vm - command: cargo build --locked --features iterator - - run: - name: Build for stargate + name: Build with all features working_directory: ~/project/packages/vm command: cargo build --locked --features iterator,staking,stargate - run: @@ -185,11 +181,7 @@ jobs: working_directory: ~/project/packages/vm command: cargo test --locked - run: - name: Test with iterator - working_directory: ~/project/packages/vm - command: cargo test --locked --features iterator - - run: - name: Test for stargate + name: Test with all features working_directory: ~/project/packages/vm command: cargo test --locked --features iterator,staking,stargate - save_cache: @@ -216,17 +208,17 @@ jobs: working_directory: ~/project/packages/vm command: cargo build --locked --features cranelift - run: - name: Build with iterator + name: Build with all features working_directory: ~/project/packages/vm - command: cargo build --locked --features cranelift,iterator + command: cargo build --locked --features cranelift,iterator,staking,stargate - run: name: Test working_directory: ~/project/packages/vm command: cargo test --locked --features cranelift - run: - name: Test with iterator + name: Test with all features working_directory: ~/project/packages/vm - command: cargo test --locked --features cranelift,iterator + command: cargo test --locked --features cranelift,iterator,staking,stargate - save_cache: paths: - /usr/local/cargo/registry diff --git a/packages/vm/src/lib.rs b/packages/vm/src/lib.rs index dc3b37bc87..71fdf86ccf 100644 --- a/packages/vm/src/lib.rs +++ b/packages/vm/src/lib.rs @@ -9,6 +9,7 @@ mod conversion; mod environment; mod errors; mod features; +#[cfg(feature = "stargate")] mod ibc_calls; mod imports; mod instance;