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

SendPacket prevents sends with frozen clients #7957

Merged
merged 2 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions x/ibc/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (k Keeper) SendPacket(
return clienttypes.ErrConsensusStateNotFound
}

// prevent accidental sends with clients that cannot be updated
if clientState.IsFrozen() {
return sdkerrors.Wrapf(clienttypes.ErrClientFrozen, "cannot send packet on a frozen client with ID %s", connectionEnd.GetClientID())
}

// check if packet timeouted on the receiving chain
latestHeight := clientState.GetLatestHeight()
timeoutHeight := packet.GetTimeoutHeight()
Expand Down
17 changes: 17 additions & 0 deletions x/ibc/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types"
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
ibcmock "github.com/cosmos/cosmos-sdk/x/ibc/testing/mock"
)
Expand Down Expand Up @@ -111,6 +112,22 @@ func (suite *KeeperTestSuite) TestSendPacket() {
packet = types.NewPacket(validPacketData, 1, channelA.PortID, channelA.ID, channelB.PortID, channelB.ID, timeoutHeight, disabledTimeoutTimestamp)
channelCap = suite.chainA.GetChannelCapability(channelA.PortID, channelA.ID)
}, false},
{"client state is frozen", func() {
_, _, connA, _, channelA, channelB := suite.coordinator.Setup(suite.chainA, suite.chainB, types.UNORDERED)

connection := suite.chainA.GetConnection(connA)
clientState := suite.chainA.GetClientState(connection.ClientId)
cs, ok := clientState.(*ibctmtypes.ClientState)
suite.Require().True(ok)

// freeze client
cs.FrozenHeight = clienttypes.NewHeight(0, 1)
suite.chainA.App.IBCKeeper.ClientKeeper.SetClientState(suite.chainA.GetContext(), connection.ClientId, cs)

packet = types.NewPacket(validPacketData, 1, channelA.PortID, channelA.ID, channelB.PortID, channelB.ID, timeoutHeight, disabledTimeoutTimestamp)
channelCap = suite.chainA.GetChannelCapability(channelA.PortID, channelA.ID)
}, false},

{"timeout height passed", func() {
clientA, _, _, _, channelA, channelB := suite.coordinator.Setup(suite.chainA, suite.chainB, types.UNORDERED)
// use client state latest height for timeout
Expand Down