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

Add ibc v3 support to message types #1302

Merged
merged 10 commits into from
May 12, 2022
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ and this project adheres to
([#1299])
- cosmwasm-vm: A new import `abort` is created to abort contract execution when
requested by the contract. ([#1299])
- cosmwasm-std: Add new `ibc3` feature that allows to use IBC-Go V3 features,
like version negotiation and exposing relayer address to the contract.
Requires a compatible wasmd runtime (v0.27.0+) ([#1302])

[#1299]: https://github.com/CosmWasm/cosmwasm/pull/1299
[#1302]: https://github.com/CosmWasm/cosmwasm/pull/1302

## [1.0.0-rc.0] - 2022-05-05

Expand Down
20 changes: 11 additions & 9 deletions contracts/ibc-reflect-send/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::ibc_msg::{
};
use crate::state::{accounts, AccountData};

pub const IBC_VERSION: &str = "ibc-reflect-v1";
pub const IBC_APP_VERSION: &str = "ibc-reflect-v1";

// TODO: make configurable?
/// packets live one hour
Expand All @@ -23,18 +23,18 @@ pub fn ibc_channel_open(_deps: DepsMut, _env: Env, msg: IbcChannelOpenMsg) -> St
if channel.order != IbcOrder::Ordered {
return Err(StdError::generic_err("Only supports ordered channels"));
}
if channel.version.as_str() != IBC_VERSION {
if channel.version.as_str() != IBC_APP_VERSION {
return Err(StdError::generic_err(format!(
"Must set version to `{}`",
IBC_VERSION
IBC_APP_VERSION
)));
}

if let Some(counter_version) = msg.counterparty_version() {
if counter_version != IBC_VERSION {
if counter_version != IBC_APP_VERSION {
return Err(StdError::generic_err(format!(
"Counterparty version must be `{}`",
IBC_VERSION
IBC_APP_VERSION
)));
}
}
Expand Down Expand Up @@ -249,13 +249,14 @@ mod tests {
// connect will run through the entire handshake to set up a proper connect and
// save the account (tested in detail in `proper_handshake_flow`)
fn connect(mut deps: DepsMut, channel_id: &str) {
let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION);
let handshake_open =
mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION);
// first we try to open with a valid handshake
ibc_channel_open(deps.branch(), mock_env(), handshake_open).unwrap();

// then we connect (with counter-party version set)
let handshake_connect =
mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION);
mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION);
let res = ibc_channel_connect(deps.branch(), mock_env(), handshake_connect).unwrap();

// this should send a WhoAmI request, which is received some blocks later
Expand Down Expand Up @@ -284,14 +285,15 @@ mod tests {
fn enforce_version_in_handshake() {
let mut deps = setup();

let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_VERSION);
let wrong_order =
mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_APP_VERSION);
ibc_channel_open(deps.as_mut(), mock_env(), wrong_order).unwrap_err();

let wrong_version = mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, "reflect");
ibc_channel_open(deps.as_mut(), mock_env(), wrong_version).unwrap_err();

let valid_handshake =
mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_VERSION);
mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_APP_VERSION);
ibc_channel_open(deps.as_mut(), mock_env(), valid_handshake).unwrap();
}

Expand Down
11 changes: 6 additions & 5 deletions contracts/ibc-reflect-send/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use cosmwasm_vm::testing::{
};
use cosmwasm_vm::{from_slice, Instance};

use ibc_reflect_send::ibc::IBC_VERSION;
use ibc_reflect_send::ibc::IBC_APP_VERSION;
use ibc_reflect_send::ibc_msg::{AcknowledgementMsg, PacketMsg, WhoAmIResponse};
use ibc_reflect_send::msg::{AccountResponse, AdminResponse, ExecuteMsg, InstantiateMsg, QueryMsg};

Expand All @@ -56,13 +56,13 @@ fn setup() -> Instance<MockApi, MockStorage, MockQuerier> {
// save the account (tested in detail in `proper_handshake_flow`)
fn connect(deps: &mut Instance<MockApi, MockStorage, MockQuerier>, channel_id: &str) {
// open packet has no counterparty version, connect does
let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_VERSION);
let handshake_open = mock_ibc_channel_open_init(channel_id, IbcOrder::Ordered, IBC_APP_VERSION);
// first we try to open with a valid handshake
ibc_channel_open(deps, mock_env(), handshake_open).unwrap();

// then we connect (with counter-party version set)
let handshake_connect =
mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_VERSION);
mock_ibc_channel_connect_ack(channel_id, IbcOrder::Ordered, IBC_APP_VERSION);
let res: IbcBasicResponse = ibc_channel_connect(deps, mock_env(), handshake_connect).unwrap();

// this should send a WhoAmI request, which is received some blocks later
Expand Down Expand Up @@ -103,13 +103,14 @@ fn instantiate_works() {
fn enforce_version_in_handshake() {
let mut deps = setup();

let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_VERSION);
let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_APP_VERSION);
ibc_channel_open(&mut deps, mock_env(), wrong_order).unwrap_err();

let wrong_version = mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, "reflect");
ibc_channel_open(&mut deps, mock_env(), wrong_version).unwrap_err();

let valid_handshake = mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_VERSION);
let valid_handshake =
mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_APP_VERSION);
ibc_channel_open(&mut deps, mock_env(), valid_handshake).unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/ibc-reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cranelift = ["cosmwasm-vm/cranelift"]
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-std = { path = "../../packages/std", features = ["iterator", "staking", "stargate"] }
cosmwasm-std = { path = "../../packages/std", features = ["iterator", "ibc3"] }
cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] }
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
Expand Down
157 changes: 0 additions & 157 deletions contracts/ibc-reflect/schema/packet_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,6 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"staking"
],
"properties": {
"staking": {
"$ref": "#/definitions/StakingMsg"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"distribution"
],
"properties": {
"distribution": {
"$ref": "#/definitions/DistributionMsg"
}
},
"additionalProperties": false
},
{
"description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)",
"type": "object",
Expand Down Expand Up @@ -240,55 +216,6 @@
}
]
},
"DistributionMsg": {
"description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto",
"oneOf": [
{
"description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"set_withdraw_address"
],
"properties": {
"set_withdraw_address": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"description": "The `withdraw_address`",
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"withdraw_delegator_reward"
],
"properties": {
"withdraw_delegator_reward": {
"type": "object",
"required": [
"validator"
],
"properties": {
"validator": {
"description": "The `validator_address`",
"type": "string"
}
}
}
},
"additionalProperties": false
}
]
},
"Empty": {
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
Expand Down Expand Up @@ -477,90 +404,6 @@
}
}
},
"StakingMsg": {
"description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto",
"oneOf": [
{
"description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"delegate"
],
"properties": {
"delegate": {
"type": "object",
"required": [
"amount",
"validator"
],
"properties": {
"amount": {
"$ref": "#/definitions/Coin"
},
"validator": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"undelegate"
],
"properties": {
"undelegate": {
"type": "object",
"required": [
"amount",
"validator"
],
"properties": {
"amount": {
"$ref": "#/definitions/Coin"
},
"validator": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"redelegate"
],
"properties": {
"redelegate": {
"type": "object",
"required": [
"amount",
"dst_validator",
"src_validator"
],
"properties": {
"amount": {
"$ref": "#/definitions/Coin"
},
"dst_validator": {
"type": "string"
},
"src_validator": {
"type": "string"
}
}
}
},
"additionalProperties": false
}
]
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```",
"allOf": [
Expand Down
Loading