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

chore: update send packet api #3573

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7cb99a0
add protos
charleenfei Apr 26, 2023
7ed438a
Merge branch '04-channel-upgrades' into charly/upgrade_try_protos
charleenfei Apr 26, 2023
2018ef6
update msgs and msg testing
charleenfei Apr 26, 2023
59c3c16
msg_server
charleenfei Apr 26, 2023
63e209a
update pr comments
charleenfei Apr 26, 2023
53054b9
update field name
charleenfei Apr 26, 2023
e65fabb
Merge branch 'charly/upgrade_try_protos' into charly/upgrade_try_msgs…
charleenfei Apr 26, 2023
dd8e5aa
update field name
charleenfei Apr 26, 2023
406ded2
update pr comments
charleenfei Apr 27, 2023
f96a20f
Merge branch 'charly/upgrade_try_protos' into charly/upgrade_try_msgs…
charleenfei Apr 27, 2023
405c3f0
add util function for HasPassed, tests for UpgradeTimeout
charleenfei Apr 27, 2023
9f43f1d
linter
charleenfei Apr 27, 2023
82ae892
update pr comments
charleenfei Apr 27, 2023
885d2c0
Merge branch 'charly/upgrade_try_msgserver' into charly/timeout_util_…
charleenfei May 2, 2023
8ee716c
Merge branch '04-channel-upgrades' into charly/timeout_util_function
charleenfei May 2, 2023
6e9f074
.
charleenfei May 2, 2023
83d1a83
update unit test
charleenfei May 3, 2023
55dc5b4
lint
charleenfei May 3, 2023
db18c44
update func api
charleenfei May 3, 2023
76ca1fe
lint
charleenfei May 3, 2023
6ceef0e
Merge branch '04-channel-upgrades' into charly/timeout_util_function
charleenfei May 3, 2023
0f7fe20
pr review
charleenfei May 3, 2023
954181e
Merge branch 'charly/timeout_util_function' of github.com:cosmos/ibc-…
charleenfei May 3, 2023
9e6afb1
add timeout methods
charleenfei May 10, 2023
81f3330
rename upgrade timeout
charleenfei May 10, 2023
89379ef
update protodoc
charleenfei May 10, 2023
3bcbb5e
merge
charleenfei May 10, 2023
14acb62
Merge branch 'charly/rename_upgrade_timeout' into charly/timeout_util…
charleenfei May 10, 2023
566e1d6
util functions
charleenfei May 10, 2023
1ac3ece
update protodoc in generated pb
charleenfei May 10, 2023
7de1412
Merge branch 'charly/rename_upgrade_timeout' into charly/timeout_util…
charleenfei May 10, 2023
0ee912b
update
charleenfei May 10, 2023
3797dea
lint
charleenfei May 10, 2023
662eccd
update send packet api
charleenfei May 10, 2023
889d830
Merge branch '04-channel-upgrades' into charly/timeout_util_function
charleenfei May 16, 2023
058da60
update
charleenfei May 16, 2023
97dfb6d
Merge branch '04-channel-upgrades' into charly/timeout_util_function
charleenfei May 16, 2023
5b8bf04
Merge branch '04-channel-upgrades' into charly/update_send_packet_api
charleenfei May 16, 2023
b29e55d
merge artifact
charleenfei May 16, 2023
cf76f8a
lint
charleenfei May 16, 2023
f58b770
fix e2e
charleenfei May 16, 2023
f3544dd
typo
charleenfei May 16, 2023
63ffea7
update tests
charleenfei May 17, 2023
bb5c363
update endpoint.go
charleenfei May 17, 2023
97114b7
update some tests
charleenfei May 17, 2023
e5d5d72
update tests
charleenfei May 17, 2023
935f55a
Merge branch 'charly/timeout_util_function' into charly/update_send_p…
charleenfei May 17, 2023
9f92ef1
fix tests
charleenfei May 17, 2023
5c8f148
linter
charleenfei May 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/tests/core/04-channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *ChannelUpgradeTestSuite) TestChannelUpgrade() {
rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)

t.Run("channel upgrade init", func(t *testing.T) {
upgradeTimeout := channeltypes.NewUpgradeTimeout(clienttypes.NewHeight(0, 10000), 0)
upgradeTimeout := channeltypes.NewTimeout(clienttypes.NewHeight(0, 10000), 0)
upgradeFields := channeltypes.NewUpgradeFields(channeltypes.UNORDERED, channelA.ConnectionHops, `{"fee_version":"ics29-1","app_version":"ics20-1"}`)
msgChanUpgradeInit := channeltypes.NewMsgChannelUpgradeInit(
channelA.PortID, channelA.ChannelID, upgradeFields, upgradeTimeout, rlyWallet.FormattedAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
Expand Down Expand Up @@ -256,8 +255,7 @@ func (im IBCMiddleware) SendPacket(
chanCap *capabilitytypes.Capability,
sourcePort string,
sourceChannel string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
timeout channeltypes.Timeout,
data []byte,
) (uint64, error) {
panic("SendPacket not supported for ICA controller module. Please use SendTx")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketDa
return 0, errorsmod.Wrap(err, "invalid interchain account packet data")
}

sequence, err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, clienttypes.ZeroHeight(), timeoutTimestamp, icaPacketData.GetBytes())
timeout := channeltypes.NewTimeout(clienttypes.ZeroHeight(), timeoutTimestamp)
sequence, err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, timeout, icaPacketData.GetBytes())
if err != nil {
return 0, err
}
Expand Down
6 changes: 2 additions & 4 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
Expand Down Expand Up @@ -351,11 +350,10 @@ func (im IBCMiddleware) SendPacket(
chanCap *capabilitytypes.Capability,
sourcePort string,
sourceChannel string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
timeout channeltypes.Timeout,
data []byte,
) (uint64, error) {
return im.keeper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
return im.keeper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeout, data)
}

// WriteAcknowledgement implements the ICS4 Wrapper interface
Expand Down
6 changes: 4 additions & 2 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() {
"packet already timed out",
func() {
timeoutHeight := clienttypes.GetSelfHeight(suite.chainB.GetContext())
timeout := channeltypes.NewTimeout(timeoutHeight, 0)

// try to incentivize a packet which is timed out
sequence, err := suite.path.EndpointA.SendPacket(timeoutHeight, 0, ibctesting.MockPacketData)
sequence, err := suite.path.EndpointA.SendPacket(timeout, ibctesting.MockPacketData)
suite.Require().NoError(err)

// need to update chainA's client representing chainB to prove missing ack
Expand Down Expand Up @@ -512,9 +513,10 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() {
suite.coordinator.Setup(suite.path) // setup channel

timeoutHeight := clienttypes.NewHeight(clienttypes.ParseChainID(suite.chainB.ChainID), 100)
timeout := channeltypes.NewTimeout(timeoutHeight, 0)

// send a packet to incentivize
sequence, err := suite.path.EndpointA.SendPacket(timeoutHeight, 0, ibctesting.MockPacketData)
sequence, err := suite.path.EndpointA.SendPacket(timeout, ibctesting.MockPacketData)
suite.Require().NoError(err)
packetID := channeltypes.NewPacketID(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, sequence)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, packetID.Sequence, packetID.PortId, packetID.ChannelId, suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, timeoutHeight, 0)
Expand Down
6 changes: 2 additions & 4 deletions modules/apps/29-fee/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
)
Expand All @@ -19,11 +18,10 @@ func (k Keeper) SendPacket(
chanCap *capabilitytypes.Capability,
sourcePort string,
sourceChannel string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
timeout channeltypes.Timeout,
data []byte,
) (uint64, error) {
return k.ics4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
return k.ics4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeout, data)
}

// WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function
Expand Down
3 changes: 2 additions & 1 deletion modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func (k Keeper) sendTransfer(
fullDenomPath, token.Amount.String(), sender.String(), receiver, memo,
)

sequence, err := k.ics4Wrapper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData.GetBytes())
timeout := channeltypes.NewTimeout(timeoutHeight, timeoutTimestamp)
sequence, err := k.ics4Wrapper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeout, packetData.GetBytes())
if err != nil {
return 0, err
}
Expand Down
15 changes: 10 additions & 5 deletions modules/core/03-connection/keeper/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, 0, ibctesting.MockPacketData)
timeout := channeltypes.NewTimeout(defaultTimeoutHeight, 0)
sequence, err := path.EndpointA.SendPacket(timeout, ibctesting.MockPacketData)
suite.Require().NoError(err)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)

Expand Down Expand Up @@ -435,7 +436,8 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() {
suite.coordinator.Setup(path)

// send and receive packet
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, 0, ibctesting.MockPacketData)
timeout := channeltypes.NewTimeout(defaultTimeoutHeight, 0)
sequence, err := path.EndpointA.SendPacket(timeout, ibctesting.MockPacketData)
suite.Require().NoError(err)

// increment receiving chain's (chainB) time by 2 hour to always pass receive
Expand Down Expand Up @@ -540,7 +542,8 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() {
suite.coordinator.Setup(path)

// send, only receive in malleate if applicable
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, 0, ibctesting.MockPacketData)
timeout := channeltypes.NewTimeout(defaultTimeoutHeight, 0)
sequence, err := path.EndpointA.SendPacket(timeout, ibctesting.MockPacketData)
suite.Require().NoError(err)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)

Expand Down Expand Up @@ -641,7 +644,9 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() {
suite.coordinator.Setup(path)

// send and receive packet
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, 0, ibctesting.MockPacketData)
timeout := channeltypes.NewTimeout(defaultTimeoutHeight, 0)

sequence, err := path.EndpointA.SendPacket(timeout, ibctesting.MockPacketData)
suite.Require().NoError(err)

// increment receiving chain's (chainB) time by 2 hour to always pass receive
Expand Down Expand Up @@ -889,7 +894,7 @@ func (suite *KeeperTestSuite) TestVerifyUpgrade() {

upgrade = channeltypes.NewUpgrade(
channeltypes.NewUpgradeFields(channeltypes.UNORDERED, []string{path.EndpointA.ConnectionID}, "v1.0.0"),
channeltypes.NewUpgradeTimeout(clienttypes.ZeroHeight(), 100000),
channeltypes.NewTimeout(clienttypes.ZeroHeight(), 100000),
0,
)

Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() {

expectedUpgrade = types.NewUpgrade(
types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, mock.Version),
types.NewUpgradeTimeout(clienttypes.ZeroHeight(), 1000000),
types.NewTimeout(clienttypes.ZeroHeight(), 1000000),
1,
)

Expand Down
16 changes: 10 additions & 6 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func (k Keeper) SendPacket(
channelCap *capabilitytypes.Capability,
sourcePort string,
sourceChannel string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
timeout types.Timeout,
data []byte,
) (uint64, error) {
channel, found := k.GetChannel(ctx, sourcePort, sourceChannel)
Expand Down Expand Up @@ -54,7 +53,7 @@ func (k Keeper) SendPacket(

// construct packet from given fields and channel state
packet := types.NewPacket(data, sequence, sourcePort, sourceChannel,
channel.Counterparty.PortId, channel.Counterparty.ChannelId, timeoutHeight, timeoutTimestamp)
channel.Counterparty.PortId, channel.Counterparty.ChannelId, timeout.Height, timeout.Timestamp)

if err := packet.ValidateBasic(); err != nil {
return 0, errorsmod.Wrap(err, "constructed packet failed basic validation")
Expand All @@ -77,10 +76,15 @@ func (k Keeper) SendPacket(

// check if packet is timed out on the receiving chain
latestHeight := clientState.GetLatestHeight()
if !timeoutHeight.IsZero() && latestHeight.GTE(timeoutHeight) {
timeoutHeight, ok := latestHeight.(clienttypes.Height)
if !ok {
return 0, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "invalid height type %T, expected %T", latestHeight, clienttypes.Height{})
}

if !timeout.IsZeroHeight() && !timeout.AfterHeight(timeoutHeight) {
return 0, errorsmod.Wrapf(
types.ErrPacketTimeout,
"receiving chain block height >= packet timeout height (%s >= %s)", latestHeight, timeoutHeight,
"receiving chain block height >= packet timeout height (%s >= %s)", latestHeight, timeout.Height,
)
}

Expand All @@ -101,7 +105,7 @@ func (k Keeper) SendPacket(
k.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1)
k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment)

emitSendPacketEvent(ctx, packet, channel, timeoutHeight)
emitSendPacketEvent(ctx, packet, channel, timeout.Height)

k.Logger(ctx).Info(
"packet sent",
Expand Down
Loading