-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added optional packet metadata to the packet and message types (#2305)
* added optional packet metadata to the packet and message types * added docs * breaking the api (backports should add a utility function for this) * adding nil metadata on all the calls * added metadata to the cli * added events * breaking api for FungibleTokenPacketData * hex encoding metadata * added abstraction * fixed bad merge * added tests with metadata * added missing metadata to packet for recv * cleaning up metadata on every test * reset metadata * added metadata flag * lint * Update modules/apps/transfer/client/cli/tx.go Co-authored-by: Damian Nolan <damiannolan@gmail.com> * fixed bad call in tests Co-authored-by: Damian Nolan <damiannolan@gmail.com> (cherry picked from commit 82397d6) # Conflicts: # docs/apps/transfer/messages.md # docs/ibc/proto-docs.md # go.mod # go.sum # modules/apps/29-fee/transfer_test.go # modules/apps/transfer/ibc_module.go # modules/apps/transfer/keeper/mbt_relay_test.go # modules/apps/transfer/keeper/relay_test.go # modules/apps/transfer/spec/05_events.md # modules/apps/transfer/types/packet.pb.go # modules/apps/transfer/types/tx.pb.go # proto/ibc/applications/interchain_accounts/controller/v1/tx.proto
- Loading branch information
1 parent
d4aeb26
commit 001b498
Showing
24 changed files
with
504 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!-- | ||
order: 4 | ||
--> | ||
|
||
# Messages | ||
|
||
## `MsgTransfer` | ||
|
||
A fungible token cross chain transfer is achieved by using the `MsgTransfer`: | ||
|
||
```go | ||
type MsgTransfer struct { | ||
SourcePort string | ||
SourceChannel string | ||
Token sdk.Coin | ||
Sender string | ||
Receiver string | ||
TimeoutHeight ibcexported.Height | ||
TimeoutTimestamp uint64 | ||
Metadata []byte | ||
} | ||
``` | ||
|
||
This message is expected to fail if: | ||
|
||
- `SourcePort` is invalid (see [24-host naming requirements](https://github.com/cosmos/ibc/blob/master/spec/core/ics-024-host-requirements/README.md#paths-identifiers-separators). | ||
- `SourceChannel` is invalid (see [24-host naming requirements](https://github.com/cosmos/ibc/blob/master/spec/core/ics-024-host-requirements/README.md#paths-identifiers-separators)). | ||
- `Token` is invalid (denom is invalid or amount is negative) | ||
- `Token.Amount` is not positive. | ||
- `Token.Denom` is not a valid IBC denomination as per [ADR 001 - Coin Source Tracing](../../../docs/architecture/adr-001-coin-source-tracing.md). | ||
- `Sender` is empty. | ||
- `Receiver` is empty. | ||
- `TimeoutHeight` and `TimeoutTimestamp` are both zero. | ||
|
||
This message will send a fungible token to the counterparty chain represented by the counterparty Channel End connected to the Channel End with the identifiers `SourcePort` and `SourceChannel`. | ||
|
||
The denomination provided for transfer should correspond to the same denomination represented on this chain. The prefixes will be added as necessary upon by the receiving chain. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package fee_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types" | ||
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" | ||
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" | ||
ibctesting "github.com/cosmos/ibc-go/v6/testing" | ||
) | ||
|
||
// Integration test to ensure ics29 works with ics20 | ||
func (suite *FeeTestSuite) TestFeeTransfer() { | ||
path := ibctesting.NewPath(suite.chainA, suite.chainB) | ||
feeTransferVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: transfertypes.Version})) | ||
path.EndpointA.ChannelConfig.Version = feeTransferVersion | ||
path.EndpointB.ChannelConfig.Version = feeTransferVersion | ||
path.EndpointA.ChannelConfig.PortID = transfertypes.PortID | ||
path.EndpointB.ChannelConfig.PortID = transfertypes.PortID | ||
|
||
suite.coordinator.Setup(path) | ||
|
||
// set up coin & ics20 packet | ||
coin := ibctesting.TestCoin | ||
fee := types.Fee{ | ||
RecvFee: defaultRecvFee, | ||
AckFee: defaultAckFee, | ||
TimeoutFee: defaultTimeoutFee, | ||
} | ||
|
||
msgs := []sdk.Msg{ | ||
types.NewMsgPayPacketFee(fee, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, suite.chainA.SenderAccount.GetAddress().String(), nil), | ||
transfertypes.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 100), 0, nil), | ||
} | ||
res, err := suite.chainA.SendMsgs(msgs...) | ||
suite.Require().NoError(err) // message committed | ||
|
||
// after incentivizing the packets | ||
originalChainASenderAccountBalance := sdk.NewCoins(suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom)) | ||
|
||
packet, err := ibctesting.ParsePacketFromEvents(res.GetEvents()) | ||
suite.Require().NoError(err) | ||
|
||
// register counterparty address on chainB | ||
// relayerAddress is address of sender account on chainB, but we will use it on chainA | ||
// to differentiate from the chainA.SenderAccount for checking successful relay payouts | ||
relayerAddress := suite.chainB.SenderAccount.GetAddress() | ||
|
||
msgRegister := types.NewMsgRegisterCounterpartyPayee(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, suite.chainB.SenderAccount.GetAddress().String(), relayerAddress.String()) | ||
_, err = suite.chainB.SendMsgs(msgRegister) | ||
suite.Require().NoError(err) // message committed | ||
|
||
// relay packet | ||
err = path.RelayPacket(packet) | ||
suite.Require().NoError(err) // relay committed | ||
|
||
// ensure relayers got paid | ||
// relayer for forward relay: chainB.SenderAccount | ||
// relayer for reverse relay: chainA.SenderAccount | ||
|
||
// check forward relay balance | ||
suite.Require().Equal( | ||
fee.RecvFee, | ||
sdk.NewCoins(suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainB.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom)), | ||
) | ||
|
||
suite.Require().Equal( | ||
fee.AckFee.Add(fee.TimeoutFee...), // ack fee paid, timeout fee refunded | ||
sdk.NewCoins(suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom)).Sub(originalChainASenderAccountBalance[0])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.