Skip to content

Commit 7247161

Browse files
authored
Merge pull request #1302 from CosmWasm/add-ibc-v3-support
Add ibc v3 support to message types
2 parents 7ee0518 + ada176f commit 7247161

File tree

15 files changed

+164
-236
lines changed

15 files changed

+164
-236
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ and this project adheres to
1515
([#1299])
1616
- cosmwasm-vm: A new import `abort` is created to abort contract execution when
1717
requested by the contract. ([#1299])
18+
- cosmwasm-std: Add new `ibc3` feature that allows to use IBC-Go V3 features,
19+
like version negotiation and exposing relayer address to the contract.
20+
Requires a compatible wasmd runtime (v0.27.0+) ([#1302])
1821

1922
[#1299]: https://github.com/CosmWasm/cosmwasm/pull/1299
23+
[#1302]: https://github.com/CosmWasm/cosmwasm/pull/1302
2024

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

contracts/ibc-reflect-send/src/ibc.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::ibc_msg::{
99
};
1010
use crate::state::{accounts, AccountData};
1111

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

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

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

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

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

287-
let wrong_order = mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_VERSION);
288+
let wrong_order =
289+
mock_ibc_channel_open_try("channel-12", IbcOrder::Unordered, IBC_APP_VERSION);
288290
ibc_channel_open(deps.as_mut(), mock_env(), wrong_order).unwrap_err();
289291

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

293295
let valid_handshake =
294-
mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_VERSION);
296+
mock_ibc_channel_open_try("channel-12", IbcOrder::Ordered, IBC_APP_VERSION);
295297
ibc_channel_open(deps.as_mut(), mock_env(), valid_handshake).unwrap();
296298
}
297299

contracts/ibc-reflect-send/tests/integration.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use cosmwasm_vm::testing::{
3131
};
3232
use cosmwasm_vm::{from_slice, Instance};
3333

34-
use ibc_reflect_send::ibc::IBC_VERSION;
34+
use ibc_reflect_send::ibc::IBC_APP_VERSION;
3535
use ibc_reflect_send::ibc_msg::{AcknowledgementMsg, PacketMsg, WhoAmIResponse};
3636
use ibc_reflect_send::msg::{AccountResponse, AdminResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
3737

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

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

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

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

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

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

contracts/ibc-reflect/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cranelift = ["cosmwasm-vm/cranelift"]
3232
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3333

3434
[dependencies]
35-
cosmwasm-std = { path = "../../packages/std", features = ["iterator", "staking", "stargate"] }
35+
cosmwasm-std = { path = "../../packages/std", features = ["iterator", "ibc3"] }
3636
cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] }
3737
schemars = "0.8.1"
3838
serde = { version = "1.0.103", default-features = false, features = ["derive"] }

contracts/ibc-reflect/schema/packet_msg.json

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -153,30 +153,6 @@
153153
},
154154
"additionalProperties": false
155155
},
156-
{
157-
"type": "object",
158-
"required": [
159-
"staking"
160-
],
161-
"properties": {
162-
"staking": {
163-
"$ref": "#/definitions/StakingMsg"
164-
}
165-
},
166-
"additionalProperties": false
167-
},
168-
{
169-
"type": "object",
170-
"required": [
171-
"distribution"
172-
],
173-
"properties": {
174-
"distribution": {
175-
"$ref": "#/definitions/DistributionMsg"
176-
}
177-
},
178-
"additionalProperties": false
179-
},
180156
{
181157
"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)",
182158
"type": "object",
@@ -240,55 +216,6 @@
240216
}
241217
]
242218
},
243-
"DistributionMsg": {
244-
"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",
245-
"oneOf": [
246-
{
247-
"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.",
248-
"type": "object",
249-
"required": [
250-
"set_withdraw_address"
251-
],
252-
"properties": {
253-
"set_withdraw_address": {
254-
"type": "object",
255-
"required": [
256-
"address"
257-
],
258-
"properties": {
259-
"address": {
260-
"description": "The `withdraw_address`",
261-
"type": "string"
262-
}
263-
}
264-
}
265-
},
266-
"additionalProperties": false
267-
},
268-
{
269-
"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.",
270-
"type": "object",
271-
"required": [
272-
"withdraw_delegator_reward"
273-
],
274-
"properties": {
275-
"withdraw_delegator_reward": {
276-
"type": "object",
277-
"required": [
278-
"validator"
279-
],
280-
"properties": {
281-
"validator": {
282-
"description": "The `validator_address`",
283-
"type": "string"
284-
}
285-
}
286-
}
287-
},
288-
"additionalProperties": false
289-
}
290-
]
291-
},
292219
"Empty": {
293220
"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)",
294221
"type": "object"
@@ -477,90 +404,6 @@
477404
}
478405
}
479406
},
480-
"StakingMsg": {
481-
"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",
482-
"oneOf": [
483-
{
484-
"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.",
485-
"type": "object",
486-
"required": [
487-
"delegate"
488-
],
489-
"properties": {
490-
"delegate": {
491-
"type": "object",
492-
"required": [
493-
"amount",
494-
"validator"
495-
],
496-
"properties": {
497-
"amount": {
498-
"$ref": "#/definitions/Coin"
499-
},
500-
"validator": {
501-
"type": "string"
502-
}
503-
}
504-
}
505-
},
506-
"additionalProperties": false
507-
},
508-
{
509-
"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.",
510-
"type": "object",
511-
"required": [
512-
"undelegate"
513-
],
514-
"properties": {
515-
"undelegate": {
516-
"type": "object",
517-
"required": [
518-
"amount",
519-
"validator"
520-
],
521-
"properties": {
522-
"amount": {
523-
"$ref": "#/definitions/Coin"
524-
},
525-
"validator": {
526-
"type": "string"
527-
}
528-
}
529-
}
530-
},
531-
"additionalProperties": false
532-
},
533-
{
534-
"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.",
535-
"type": "object",
536-
"required": [
537-
"redelegate"
538-
],
539-
"properties": {
540-
"redelegate": {
541-
"type": "object",
542-
"required": [
543-
"amount",
544-
"dst_validator",
545-
"src_validator"
546-
],
547-
"properties": {
548-
"amount": {
549-
"$ref": "#/definitions/Coin"
550-
},
551-
"dst_validator": {
552-
"type": "string"
553-
},
554-
"src_validator": {
555-
"type": "string"
556-
}
557-
}
558-
}
559-
},
560-
"additionalProperties": false
561-
}
562-
]
563-
},
564407
"Timestamp": {
565408
"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); ```",
566409
"allOf": [

0 commit comments

Comments
 (0)