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 IbcSend message type to stargate code #710

Merged
merged 2 commits into from
Jan 13, 2021

Conversation

ethanfrey
Copy link
Member

Expose simple message to allow contracts to send native tokens to other chains

/// A Stargate message encoded the same way as a protobof [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)
#[cfg(feature = "stargate")]
Stargate {
type_url: String,
data: Binary,
},
Wasm(WasmMsg),
/// Sends *native tokens* owned by the contract to the given address on another chain.
Copy link
Member

Choose a reason for hiding this comment

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

What mean "native token" exactly? A bank token of the contract's chain?

Copy link
Contributor

Choose a reason for hiding this comment

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

good 👁️ . This can be a bank token but also a ibc voucher or anything else that got minted on the sdk mint module.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. As opposed to a cw20 token.

I will use the term bank token (others in cosmos used native token)

/// We cannot select the port_id, this is whatever the local chain has bound the ibctransfer
/// module to.
#[cfg(feature = "stargate")]
IbcSend {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I will rebase on another PR that adds IBC message types.

My issue was that the other ones (SendPacket and CloseChannel) only are valid for contracts that actively participate in ibc channels (and have 6 entry points for that). This one could be used by any contract.

I guess I can make that distinction with docstrings as well

Copy link
Contributor

Choose a reason for hiding this comment

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

agree that is a transfer is a better naming. it is used in the sdk module as well as on the cli.

Copy link
Member

Choose a reason for hiding this comment

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

My issue was that the other ones (SendPacket and CloseChannel) only are valid for contracts that actively participate in ibc channels (and have 6 entry points for that). This one could be used by any contract.

I guess I can make that distinction with docstrings as well

Yeah, I think this way would be better.

I guess this would be reflected in the necessary fiels as well (the other messages would require more fields that include all this channel state information)?

@@ -24,7 +25,6 @@ pub enum QueryRequest<C: CustomQuery> {
/// this is the expected protobuf message type (not any), binary encoded
data: Binary,
},
Wasm(WasmQuery),
Copy link
Member

Choose a reason for hiding this comment

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

What's the idea behind this move? Before it was alphabetically. I'm happy either way but I'd like to understand how you want to order this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I left it alphabetic for the standard ones, then all the stargate ones below (under feature flag). So sorting (is_stargate, name).

Maybe that is not very good idea, as staking is also under a different feature flag. I can make it alphabetical again

Copy link
Member

Choose a reason for hiding this comment

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

I'd either use plain alphabetic order or introduce ordered groups that are separated by an empty line

/// A Stargate message encoded the same way as a protobof [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)
#[cfg(feature = "stargate")]
Stargate {
type_url: String,
data: Binary,
},
Wasm(WasmMsg),
/// Sends *native tokens* owned by the contract to the given address on another chain.
Copy link
Contributor

Choose a reason for hiding this comment

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

good 👁️ . This can be a bank token but also a ibc voucher or anything else that got minted on the sdk mint module.

/// We cannot select the port_id, this is whatever the local chain has bound the ibctransfer
/// module to.
#[cfg(feature = "stargate")]
IbcSend {
Copy link
Contributor

Choose a reason for hiding this comment

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

agree that is a transfer is a better naming. it is used in the sdk module as well as on the cli.

/// packet data only supports one coin
/// https://github.com/cosmos/cosmos-sdk/blob/master/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20
amount: Coin,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have an optional field port_id:String?
The default should be transfer but this can be set in the genesis for every chain

Copy link
Member

Choose a reason for hiding this comment

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

Optinal fields are not super convenient in Rust (you cannot omit them like in JavaScript/Go). Instead you always have to write them either port: Some(value) or port: None.

Would it be an option to store this as a constant in the chain code, such that it is added when the Rust type is translated to a Cosmos SDK 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.

Can we have an optional field port_id:String?
The default should be transfer but this can be set in the genesis for every chain

This detail is super important for the Go module handling the transfers. There should be one official IbcTransfer port for the application, which may be name transfer or ibctransfer or foobar or wasm12334556775fg4g43tuhti44tt4yt74yt47.

The contract should run the same on any chain, regardless of how genesis was set up. By just sending a token, we leave the port naming up to the wasmd-based app. The channel is needed to differentiate various chains and should be set by the calling user.

Does that make sense? Setting a port to anything other than what the ibctransfer module was bound to will lead to an error, so let's just set it for them, as there is only one "right" value

@ethanfrey ethanfrey changed the base branch from master to ibc-entry-points January 13, 2021 12:34
@ethanfrey
Copy link
Member Author

Okay, I rebased this on #711 and then simplified it from the comments.
Can you please re-review?

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.

LGTM

@ethanfrey ethanfrey merged commit 942f389 into ibc-entry-points Jan 13, 2021
@ethanfrey ethanfrey deleted the ibc-transfer-msg branch January 13, 2021 12:52
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.

3 participants