Skip to content

Commit

Permalink
add is frozen client state check to send packet (#7957)
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
colin-axner and fedekunze authored Nov 17, 2020
1 parent e93b18e commit 0647d89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 0647d89

Please sign in to comment.