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
Merged

Add ibc v3 support to message types #1302

merged 10 commits into from
May 12, 2022

Conversation

ethanfrey
Copy link
Member

@ethanfrey ethanfrey commented May 10, 2022

Part of #1200 that is very close to me as I just worked on the ibcv3 integration in wasmd.

Added a new feature flag "ibcv3".

I made all effort to ensure the types are backwards compatible with ibcv1. With ibcv3 enabled:

The ibc_connection_open call may return a struct with a version field to set a custom version in handshake. (Previously it returned () which serialised to null, so they both can be safely parsed into *MyStruct / Option<MyStruct>)

IbcPacketReceiveMsg, IbcPacketAckMsg, and IbcPacketTimeoutMsg all require an additional relayer field from the runtime. Ibc v1 contracts will silently ignore this info if passed from the runtime.

Also updated the VM to handle this, and updated ibc-reflect contract to use ibcv3 (while ibc-reflect-send remains with "stargate" to ensure they both work)

@webmaster128 I would really like to get this into the 1.0 release if possible (along with your #1299 enhancement). It is just a type signature issue, so no major code/logic changes, but it will allow wasmd to to a lot more. (And implement ICA as a contract)

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Great stuff!

Any objections to simplify the term "ibcv3" to "ibc3" for simplification and avoid the unnecessary "version" word?

contracts/ibc-reflect/src/contract.rs Outdated Show resolved Hide resolved
contracts/ibc-reflect/src/contract.rs Outdated Show resolved Hide resolved
packages/std/src/ibc.rs Outdated Show resolved Hide resolved
packages/std/src/ibc.rs Outdated Show resolved Hide resolved
#[cfg(feature = "ibcv3")]
pub fn new(packet: IbcPacket, relayer: Addr) -> Self {
Self { packet, relayer }
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of a problematic use of features. Rust assumes adding features does not break compilation. The original dependency resolver just enabled all features required by some caller and compiled the dependency once. Code like this then suddenly breaks in a hard to understand way.

But yeah, we'll probably remove all non-v3 code soon anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good point. My thought was a contract is written either with one or the other. I guess for some internal tests this may cause issues, or unit tests where ibc1 contracts import ibc3 contracts.

Happy to change this if you have a better idea

packages/vm/Cargo.toml Outdated Show resolved Hide resolved
@ethanfrey
Copy link
Member Author

ethanfrey commented May 12, 2022

Any objections to simplify the term "ibcv3" to "ibc3" for simplification and avoid the unnecessary "version" word?

Happy to change this and some of the smaller feedback.

@ethanfrey
Copy link
Member Author

@webmaster128 I addressed the majority of the points.

I am unsure if there is some way I can improve contract compilation with feature flags.
Should I always have new, which defaults to relayer: "" in ibc3 and then use new_with_relayer which is only in ibc3 and includes the relayer?

@ethanfrey
Copy link
Member Author

I made a demo on handling this less-breaking in #1304 feel free to merge that into this PR if you like the approach, leave it as is, or give me a concrete suggestion of another approach to take here.

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Cool. Let's Just remove this one V and write a CHANGELOG entry for this.

packages/std/src/ibc.rs Outdated Show resolved Hide resolved
@@ -227,7 +227,7 @@ where
let env = to_vec(env)?;
let msg = to_vec(msg)?;
let data = call_ibc_channel_open_raw(instance, &env, &msg)?;
let result: ContractResult<()> =
let result: ContractResult<Option<IbcV3ChannelOpenResponse>> =
Copy link
Member

Choose a reason for hiding this comment

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

Ah nice, here we unify the two versions now into one type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, the VM uses the backwards compatible ibc3 versions. Well noted we don't need a flag for this repo

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

okay, just CHANGELOG entries left

CHANGELOG.md Outdated
like version negotiation and exposing relayer address to the contract.
Requires a compatible wasmd runtime (v0.27.0+) ([#1297])

[#1302]: https://github.com/CosmWasm/cosmwasm/pull/1302
Copy link
Member

Choose a reason for hiding this comment

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

Can you rebase this to main and move the block to the Unreleased section?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

CHANGELOG.md Outdated
@@ -23,6 +23,11 @@ and this project adheres to
- cosmwasm-std: Implement `Div`/`DivAssign` for `Decimal`/`Decimal256`.
- cosmwasm-vm: Add feature `allow_interface_version_7` to run CosmWasm 0.16
contracts in modern hosts. Be careful if you consider using this!
- 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+) ([#1297])
Copy link
Member

Choose a reason for hiding this comment

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

The PR number needs to be updated

Copy link
Member Author

Choose a reason for hiding this comment

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

also done

@webmaster128
Copy link
Member

🐎🐎🐎🐎🐎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants