x/ibc: Implement Timeout Timestamp (#6022)
* add timeout timestamp to packet and timestamp to consensus state * add timeout timestamp event attribute * update various issues with adding timestamp * fix tests, add default timeout timestamp * add unit test and minor fixes * remove unnecessary code * code review fix * Update x/ibc/03-connection/keeper/keeper.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/ibc/02-client/exported/exported.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/ibc/04-channel/types/packet.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/ibc/07-tendermint/types/consensus_state.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * return time.Time in error message Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
61753c8cf1
commit
f6e9ee7623
|
@ -103,6 +103,9 @@ type ConsensusState interface {
|
|||
// which is used for key-value pair verification.
|
||||
GetRoot() commitmentexported.Root
|
||||
|
||||
// GetTimestamp returns the timestamp (in nanoseconds) of the consensus state
|
||||
GetTimestamp() uint64
|
||||
|
||||
ValidateBasic() error
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,23 @@ func (k Keeper) SetConnection(ctx sdk.Context, connectionID string, connection t
|
|||
store.Set(ibctypes.KeyConnection(connectionID), bz)
|
||||
}
|
||||
|
||||
// GetTimestampAtHeight returns the timestamp in nanoseconds of the consensus state at the
|
||||
// given height.
|
||||
func (k Keeper) GetTimestampAtHeight(ctx sdk.Context, connection types.ConnectionEnd, height uint64) (uint64, error) {
|
||||
consensusState, found := k.clientKeeper.GetClientConsensusState(
|
||||
ctx, connection.GetClientID(), height,
|
||||
)
|
||||
|
||||
if !found {
|
||||
return 0, sdkerrors.Wrapf(
|
||||
clienttypes.ErrConsensusStateNotFound,
|
||||
"clientID (%s), height (%d)", connection.GetClientID(), height,
|
||||
)
|
||||
}
|
||||
|
||||
return consensusState.GetTimestamp(), nil
|
||||
}
|
||||
|
||||
// GetClientConnectionPaths returns all the connection paths stored under a
|
||||
// particular client
|
||||
func (k Keeper) GetClientConnectionPaths(ctx sdk.Context, clientID string) ([]string, bool) {
|
||||
|
|
|
@ -36,7 +36,13 @@ const (
|
|||
|
||||
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2
|
||||
ubdPeriod time.Duration = time.Hour * 24 * 7 * 3
|
||||
maxClockDrift time.Duration = time.Second * 10
|
||||
maxClockDrift time.Duration = time.Second * 10
|
||||
|
||||
nextTimestamp = 10 // increment used for the next header's timestamp
|
||||
)
|
||||
|
||||
var (
|
||||
timestamp = time.Now() // starting timestamp for the client test chain
|
||||
)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
|
@ -124,6 +130,42 @@ func (suite KeeperTestSuite) TestGetAllConnections() {
|
|||
suite.Require().ElementsMatch(expConnections, connections)
|
||||
}
|
||||
|
||||
// TestGetTimestampAtHeight verifies if the clients on each chain return the correct timestamp
|
||||
// for the other chain.
|
||||
func (suite *KeeperTestSuite) TestGetTimestampAtHeight() {
|
||||
cases := []struct {
|
||||
msg string
|
||||
malleate func()
|
||||
expPass bool
|
||||
}{
|
||||
{"verification success", func() {
|
||||
suite.chainA.CreateClient(suite.chainB)
|
||||
}, true},
|
||||
{"client state not found", func() {}, false},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
|
||||
suite.SetupTest() // reset
|
||||
|
||||
tc.malleate()
|
||||
// create and store a connection to chainB on chainA
|
||||
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.OPEN)
|
||||
|
||||
actualTimestamp, err := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetTimestampAtHeight(
|
||||
suite.chainA.GetContext(), connection, uint64(suite.chainB.Header.Height),
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.msg)
|
||||
suite.Require().EqualValues(uint64(suite.chainB.Header.Time.UnixNano()), actualTimestamp)
|
||||
} else {
|
||||
suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestChain is a testing struct that wraps a simapp with the latest Header, Vals and Signers
|
||||
// It also contains a field called ClientID. This is the clientID that *other* chains use
|
||||
// to refer to this TestChain. For simplicity's sake it is also the chainID on the TestChain Header
|
||||
|
@ -146,9 +188,8 @@ func NewTestChain(clientID string) *TestChain {
|
|||
validator := tmtypes.NewValidator(pubKey, 1)
|
||||
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
|
||||
signers := []tmtypes.PrivValidator{privVal}
|
||||
now := time.Now()
|
||||
|
||||
header := ibctmtypes.CreateTestHeader(clientID, 1, now, valSet, signers)
|
||||
header := ibctmtypes.CreateTestHeader(clientID, 1, timestamp, valSet, signers)
|
||||
|
||||
return &TestChain{
|
||||
ClientID: clientID,
|
||||
|
@ -321,7 +362,7 @@ func (chain *TestChain) createChannel(
|
|||
|
||||
func nextHeader(chain *TestChain) ibctmtypes.Header {
|
||||
return ibctmtypes.CreateTestHeader(chain.Header.ChainID, chain.Header.Height+1,
|
||||
time.Now(), chain.Vals, chain.Signers)
|
||||
chain.Header.Time.Add(nextTimestamp), chain.Vals, chain.Signers)
|
||||
}
|
||||
|
||||
func prefixedClientKey(clientID string, key []byte) []byte {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
// QueryPacket returns a packet from the store
|
||||
func QueryPacket(
|
||||
ctx context.CLIContext, portID, channelID string,
|
||||
sequence, timeout uint64, prove bool,
|
||||
sequence, timeoutHeight, timeoutTimestamp uint64, prove bool,
|
||||
) (types.PacketResponse, error) {
|
||||
req := abci.RequestQuery{
|
||||
Path: "store/ibc/key",
|
||||
|
@ -39,7 +39,8 @@ func QueryPacket(
|
|||
channelID,
|
||||
destPortID,
|
||||
destChannelID,
|
||||
timeout,
|
||||
timeoutHeight,
|
||||
timeoutTimestamp,
|
||||
)
|
||||
|
||||
// FIXME: res.Height+1 is hack, fix later
|
||||
|
|
|
@ -27,6 +27,7 @@ type CounterpartyI interface {
|
|||
type PacketI interface {
|
||||
GetSequence() uint64
|
||||
GetTimeoutHeight() uint64
|
||||
GetTimeoutTimestamp() uint64
|
||||
GetSourcePort() string
|
||||
GetSourceChannel() string
|
||||
GetDestPort() string
|
||||
|
|
|
@ -46,7 +46,12 @@ const (
|
|||
|
||||
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2
|
||||
ubdPeriod time.Duration = time.Hour * 24 * 7 * 3
|
||||
maxClockDrift time.Duration = time.Second * 10
|
||||
maxClockDrift time.Duration = time.Second * 10
|
||||
|
||||
timeoutHeight = 100
|
||||
timeoutTimestamp = 100
|
||||
disabledTimeoutTimestamp = 0
|
||||
disabledTimeoutHeight = 0
|
||||
)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
|
@ -194,6 +199,12 @@ func commitNBlocks(chain *TestChain, n int) {
|
|||
}
|
||||
}
|
||||
|
||||
// commit current block and start the next block with the provided time
|
||||
func commitBlockWithNewTimestamp(chain *TestChain, timestamp int64) {
|
||||
chain.App.Commit()
|
||||
chain.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: chain.App.LastBlockHeight() + 1, Time: time.Unix(timestamp, 0)}})
|
||||
}
|
||||
|
||||
// nolint: unused
|
||||
func queryProof(chain *TestChain, key []byte) (commitmenttypes.MerkleProof, uint64) {
|
||||
res := chain.App.Query(abci.RequestQuery{
|
||||
|
|
|
@ -3,6 +3,7 @@ package keeper
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
@ -16,7 +17,7 @@ import (
|
|||
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
|
||||
)
|
||||
|
||||
// SendPacket is called by a module in order to send an IBC packet on a channel
|
||||
// SendPacket is called by a module in order to send an IBC packet on a channel
|
||||
// end owned by the calling module to the corresponding module on the counterparty
|
||||
// chain.
|
||||
func (k Keeper) SendPacket(
|
||||
|
@ -77,8 +78,24 @@ func (k Keeper) SendPacket(
|
|||
}
|
||||
|
||||
// check if packet timeouted on the receiving chain
|
||||
if clientState.GetLatestHeight() >= packet.GetTimeoutHeight() {
|
||||
return sdkerrors.Wrap(types.ErrPacketTimeout, "timeout already passed ond the receiving chain")
|
||||
latestHeight := clientState.GetLatestHeight()
|
||||
if packet.GetTimeoutHeight() != 0 && latestHeight >= packet.GetTimeoutHeight() {
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrPacketTimeout,
|
||||
"receiving chain block height >= packet timeout height (%d >= %d)", latestHeight, packet.GetTimeoutHeight(),
|
||||
)
|
||||
}
|
||||
|
||||
latestTimestamp, err := k.connectionKeeper.GetTimestampAtHeight(ctx, connectionEnd, latestHeight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if packet.GetTimeoutTimestamp() != 0 && latestTimestamp >= packet.GetTimeoutTimestamp() {
|
||||
return sdkerrors.Wrapf(
|
||||
types.ErrPacketTimeout,
|
||||
"receiving chain block timestamp >= packet timeout timestamp (%s >= %s)", time.Unix(0, int64(latestTimestamp)), time.Unix(0, int64(packet.GetTimeoutTimestamp())),
|
||||
)
|
||||
}
|
||||
|
||||
nextSequenceSend, found := k.GetNextSequenceSend(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
|
||||
|
@ -103,7 +120,8 @@ func (k Keeper) SendPacket(
|
|||
sdk.NewEvent(
|
||||
types.EventTypeSendPacket,
|
||||
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeout, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
|
||||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
|
||||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
|
||||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
|
||||
|
@ -167,8 +185,19 @@ func (k Keeper) RecvPacket(
|
|||
}
|
||||
|
||||
// check if packet timeouted by comparing it with the latest height of the chain
|
||||
if uint64(ctx.BlockHeight()) >= packet.GetTimeoutHeight() {
|
||||
return nil, types.ErrPacketTimeout
|
||||
if packet.GetTimeoutHeight() != 0 && uint64(ctx.BlockHeight()) >= packet.GetTimeoutHeight() {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
types.ErrPacketTimeout,
|
||||
"block height >= packet timeout height (%d >= %d)", uint64(ctx.BlockHeight()), packet.GetTimeoutHeight(),
|
||||
)
|
||||
}
|
||||
|
||||
// check if packet timeouted by comparing it with the latest timestamp of the chain
|
||||
if packet.GetTimeoutTimestamp() != 0 && uint64(ctx.BlockTime().UnixNano()) >= packet.GetTimeoutTimestamp() {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
types.ErrPacketTimeout,
|
||||
"block timestamp >= packet timeout timestamp (%s >= %s)", ctx.BlockTime(), time.Unix(0, int64(packet.GetTimeoutTimestamp())),
|
||||
)
|
||||
}
|
||||
|
||||
if err := k.connectionKeeper.VerifyPacketCommitment(
|
||||
|
@ -243,7 +272,8 @@ func (k Keeper) PacketExecuted(
|
|||
types.EventTypeRecvPacket,
|
||||
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())),
|
||||
sdk.NewAttribute(types.AttributeKeyAck, string(acknowledgement)),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeout, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
|
||||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
|
||||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
|
||||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
|
||||
|
@ -330,7 +360,8 @@ func (k Keeper) AcknowledgePacket(
|
|||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
types.EventTypeAcknowledgePacket,
|
||||
sdk.NewAttribute(types.AttributeKeyTimeout, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
|
||||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
|
||||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
|
||||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
|
||||
|
@ -445,7 +476,8 @@ func (k Keeper) CleanupPacket(
|
|||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
types.EventTypeCleanupPacket,
|
||||
sdk.NewAttribute(types.AttributeKeyTimeout, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
|
||||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
|
||||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
|
||||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
|
||||
|
|
|
@ -19,66 +19,73 @@ func (suite *KeeperTestSuite) TestSendPacket() {
|
|||
var channelCap *capability.Capability
|
||||
testCases := []testCase{
|
||||
{"success", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 1)
|
||||
}, true},
|
||||
{"packet basic validation failed", func() {
|
||||
packet = types.NewPacket(mockFailPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockFailPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
}, false},
|
||||
{"channel not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
}, false},
|
||||
{"channel closed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet dest port ≠ channel counterparty port", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, testPort3, counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, testPort3, counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet dest channel ID ≠ channel counterparty channel ID", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), testChannel3, 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), testChannel3, timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection is UNINITIALIZED", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.UNINITIALIZED)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"client state not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"timeout height passed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
commitNBlocks(suite.chainB, 10)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"timeout timestamp passed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), disabledTimeoutHeight, timeoutTimestamp)
|
||||
commitBlockWithNewTimestamp(suite.chainB, timeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"next sequence send not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"next sequence wrong", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 5)
|
||||
}, false},
|
||||
{"channel capability not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
|
@ -125,40 +132,46 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
|
|||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDB)
|
||||
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort2, testChannel2, 1)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort2, testChannel2, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort2, testChannel2, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), testPort2, testChannel2, 1, types.CommitPacket(packet))
|
||||
|
||||
}, true},
|
||||
{"channel not found", func() {}, false},
|
||||
{"channel not open", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.INIT, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source port ≠ channel counterparty port", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort3, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source channel ID ≠ channel counterparty channel ID", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not OPEN", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.INIT)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"timeout passed", func() {
|
||||
{"timeout height passed", func() {
|
||||
commitNBlocks(suite.chainB, 10)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"timeout timestamp passed", func() {
|
||||
commitBlockWithNewTimestamp(suite.chainB, timeoutTimestamp)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), disabledTimeoutHeight, timeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"validation failed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
|
@ -196,31 +209,31 @@ func (suite *KeeperTestSuite) TestPacketExecuted() {
|
|||
var channelCap *capability.Capability
|
||||
testCases := []testCase{
|
||||
{"success: UNORDERED", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.UNORDERED, testConnectionIDA)
|
||||
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1)
|
||||
}, true},
|
||||
{"success: ORDERED", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1)
|
||||
}, true},
|
||||
{"channel not found", func() {}, false},
|
||||
{"channel not OPEN", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.CLOSED, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"next sequence receive not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet sequence ≠ next sequence receive", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 5)
|
||||
}, false},
|
||||
{"capability not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.UNORDERED, testConnectionIDA)
|
||||
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1)
|
||||
channelCap = capability.NewCapability(3)
|
||||
|
@ -260,7 +273,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
|
|||
|
||||
testCases := []testCase{
|
||||
{"success", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainA.CreateClient(suite.chainB)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
|
@ -272,33 +285,33 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
|
|||
}, true},
|
||||
{"channel not found", func() {}, false},
|
||||
{"channel not open", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source port ≠ channel counterparty port", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source channel ID ≠ channel counterparty channel ID", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not OPEN", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.INIT)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet hasn't been sent", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet ack verification failed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
|
||||
|
@ -342,7 +355,7 @@ func (suite *KeeperTestSuite) TestCleanupPacket() {
|
|||
testCases := []testCase{
|
||||
{"success", func() {
|
||||
nextSeqRecv = 10
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainA.CreateClient(suite.chainB)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
|
@ -354,47 +367,47 @@ func (suite *KeeperTestSuite) TestCleanupPacket() {
|
|||
}, true},
|
||||
{"channel not found", func() {}, false},
|
||||
{"channel not open", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source port ≠ channel counterparty port", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source channel ID ≠ channel counterparty channel ID", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not OPEN", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.INIT)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet already received ", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet hasn't been sent", func() {
|
||||
nextSeqRecv = 10
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"next seq receive verification failed", func() {
|
||||
nextSeqRecv = 10
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
|
||||
}, false},
|
||||
{"packet ack verification failed", func() {
|
||||
nextSeqRecv = 10
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
|
||||
|
|
|
@ -66,9 +66,15 @@ func (k Keeper) TimeoutPacket(
|
|||
)
|
||||
}
|
||||
|
||||
// check that timeout height has passed on the other end
|
||||
if proofHeight < packet.GetTimeoutHeight() {
|
||||
return nil, types.ErrPacketTimeout
|
||||
// check that timeout height or timeout timestamp has passed on the other end
|
||||
proofTimestamp, err := k.connectionKeeper.GetTimestampAtHeight(ctx, connectionEnd, proofHeight)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if (packet.GetTimeoutHeight() == 0 || proofHeight < packet.GetTimeoutHeight()) &&
|
||||
(packet.GetTimeoutTimestamp() == 0 || proofTimestamp < packet.GetTimeoutTimestamp()) {
|
||||
return nil, sdkerrors.Wrap(types.ErrPacketTimeout, "packet timeout has not been reached for height or timestamp")
|
||||
}
|
||||
|
||||
// check that packet has not been received
|
||||
|
@ -83,7 +89,6 @@ func (k Keeper) TimeoutPacket(
|
|||
return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
|
||||
}
|
||||
|
||||
var err error
|
||||
switch channel.Ordering {
|
||||
case exported.ORDERED:
|
||||
// check that the recv sequence is as claimed
|
||||
|
@ -110,7 +115,8 @@ func (k Keeper) TimeoutPacket(
|
|||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
types.EventTypeTimeoutPacket,
|
||||
sdk.NewAttribute(types.AttributeKeyTimeout, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
|
||||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
|
||||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
|
||||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
|
||||
|
@ -247,7 +253,8 @@ func (k Keeper) TimeoutOnClose(
|
|||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
types.EventTypeTimeoutPacket,
|
||||
sdk.NewAttribute(types.AttributeKeyTimeout, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, fmt.Sprintf("%d", packet.GetTimeoutHeight())),
|
||||
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
|
||||
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
|
||||
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
|
||||
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
|
||||
|
|
|
@ -21,7 +21,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
|
|||
testCases := []testCase{
|
||||
{"success", func() {
|
||||
nextSeqRecv = 1
|
||||
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 1)
|
||||
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 1, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainA.CreateClient(suite.chainB)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
|
@ -32,48 +32,48 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
|
|||
}, true},
|
||||
{"channel not found", func() {}, false},
|
||||
{"channel not open", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source port ≠ channel counterparty port", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet source channel ID ≠ channel counterparty channel ID", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"timeout", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet already received ", func() {
|
||||
nextSeqRecv = 2
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet hasn't been sent", func() {
|
||||
nextSeqRecv = 1
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"next seq receive verification failed", func() {
|
||||
nextSeqRecv = 1
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
|
||||
}, false},
|
||||
{"packet ack verification failed", func() {
|
||||
nextSeqRecv = 1
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
|
||||
|
@ -111,12 +111,12 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
|
|||
var chanCap *capability.Capability
|
||||
testCases := []testCase{
|
||||
{"success ORDERED", func() {
|
||||
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 3)
|
||||
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 3, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, true},
|
||||
{"channel not found", func() {}, false},
|
||||
{"incorrect capability", func() {
|
||||
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 3)
|
||||
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 3, disabledTimeoutTimestamp)
|
||||
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
chanCap = capability.NewCapability(1)
|
||||
}, false},
|
||||
|
@ -157,7 +157,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
|
|||
|
||||
testCases := []testCase{
|
||||
{"success", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainA.CreateClient(suite.chainB)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
|
@ -169,24 +169,24 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
|
|||
}, true},
|
||||
{"channel not found", func() {}, false},
|
||||
{"packet dest port ≠ channel counterparty port", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet dest channel ID ≠ channel counterparty channel ID", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"connection not found", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"packet hasn't been sent", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
}, false},
|
||||
{"channel verification failed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
|
||||
|
@ -194,7 +194,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
|
|||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv)
|
||||
}, false},
|
||||
{"next seq receive verification failed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
|
||||
|
@ -202,7 +202,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
|
|||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv)
|
||||
}, false},
|
||||
{"packet ack verification failed", func() {
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 100)
|
||||
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
|
||||
suite.chainB.CreateClient(suite.chainA)
|
||||
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
|
||||
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
|
||||
|
|
|
@ -20,14 +20,15 @@ const (
|
|||
EventTypeCleanupPacket = "cleanup_packet"
|
||||
EventTypeTimeoutPacket = "timeout_packet"
|
||||
|
||||
AttributeKeyData = "packet_data"
|
||||
AttributeKeyAck = "packet_ack"
|
||||
AttributeKeyTimeout = "packet_timeout"
|
||||
AttributeKeySequence = "packet_sequence"
|
||||
AttributeKeySrcPort = "packet_src_port"
|
||||
AttributeKeySrcChannel = "packet_src_channel"
|
||||
AttributeKeyDstPort = "packet_dst_port"
|
||||
AttributeKeyDstChannel = "packet_dst_channel"
|
||||
AttributeKeyData = "packet_data"
|
||||
AttributeKeyAck = "packet_ack"
|
||||
AttributeKeyTimeoutHeight = "packet_timeout_height"
|
||||
AttributeKeyTimeoutTimestamp = "packet_timeout_timestamp"
|
||||
AttributeKeySequence = "packet_sequence"
|
||||
AttributeKeySrcPort = "packet_src_port"
|
||||
AttributeKeySrcChannel = "packet_src_channel"
|
||||
AttributeKeyDstPort = "packet_dst_port"
|
||||
AttributeKeyDstChannel = "packet_dst_channel"
|
||||
)
|
||||
|
||||
// IBC channel events vars
|
||||
|
|
|
@ -18,6 +18,11 @@ type ClientKeeper interface {
|
|||
// ConnectionKeeper expected account IBC connection keeper
|
||||
type ConnectionKeeper interface {
|
||||
GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, bool)
|
||||
GetTimestampAtHeight(
|
||||
ctx sdk.Context,
|
||||
connection connectiontypes.ConnectionEnd,
|
||||
height uint64,
|
||||
) (uint64, error)
|
||||
VerifyChannelState(
|
||||
ctx sdk.Context,
|
||||
connection connectionexported.ConnectionI,
|
||||
|
|
|
@ -354,13 +354,15 @@ func (suite *MsgTestSuite) TestMsgChannelCloseConfirm() {
|
|||
|
||||
// define variables used for testing
|
||||
var (
|
||||
timeout = uint64(100)
|
||||
timeoutHeight = uint64(100)
|
||||
timeoutTimestamp = uint64(100)
|
||||
disabledTimeout = uint64(0)
|
||||
validPacketData = []byte("testdata")
|
||||
unknownPacketData = []byte("unknown")
|
||||
invalidAckData = []byte("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
|
||||
|
||||
packet = NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, 100)
|
||||
unknownPacket = NewPacket(unknownPacketData, 0, portid, chanid, cpportid, cpchanid, 100)
|
||||
packet = NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp)
|
||||
unknownPacket = NewPacket(unknownPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp)
|
||||
invalidAck = invalidAckData
|
||||
|
||||
emptyProof = commitmenttypes.MerkleProof{Proof: nil}
|
||||
|
@ -425,7 +427,7 @@ func TestMsgPacketGetSignBytes(t *testing.T) {
|
|||
res := msg.GetSignBytes()
|
||||
|
||||
expected := fmt.Sprintf(
|
||||
`{"type":"ibc/channel/MsgPacket","value":{"packet":{"data":%s,"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid","timeout_height":"100"},"proof":{"type":"ibc/commitment/MerkleProof","value":{"proof":{"ops":[]}}},"proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}}`,
|
||||
`{"type":"ibc/channel/MsgPacket","value":{"packet":{"data":%s,"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid","timeout_height":"100","timeout_timestamp":"100"},"proof":{"type":"ibc/commitment/MerkleProof","value":{"proof":{"ops":[]}}},"proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}}`,
|
||||
string(msg.GetDataSignBytes()),
|
||||
)
|
||||
require.Equal(t, expected, string(res))
|
||||
|
|
|
@ -35,6 +35,7 @@ type Packet struct {
|
|||
DestinationPort string `json:"destination_port" yaml:"destination_port"` // identifies the port on the receiving chain.
|
||||
DestinationChannel string `json:"destination_channel" yaml:"destination_channel"` // identifies the channel end on the receiving chain.
|
||||
TimeoutHeight uint64 `json:"timeout_height" yaml:"timeout_height"` // block height after which the packet times out
|
||||
TimeoutTimestamp uint64 `json:"timeout_timestamp" yaml:"timeout_timestamp"` // block timestamp (in nanoseconds) after which the packet times out
|
||||
}
|
||||
|
||||
// NewPacket creates a new Packet instance
|
||||
|
@ -42,7 +43,7 @@ func NewPacket(
|
|||
data []byte,
|
||||
sequence uint64, sourcePort, sourceChannel,
|
||||
destinationPort, destinationChannel string,
|
||||
timeoutHeight uint64,
|
||||
timeoutHeight uint64, timeoutTimestamp uint64,
|
||||
) Packet {
|
||||
return Packet{
|
||||
Data: data,
|
||||
|
@ -52,6 +53,7 @@ func NewPacket(
|
|||
DestinationPort: destinationPort,
|
||||
DestinationChannel: destinationChannel,
|
||||
TimeoutHeight: timeoutHeight,
|
||||
TimeoutTimestamp: timeoutTimestamp,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,6 +78,9 @@ func (p Packet) GetData() []byte { return p.Data }
|
|||
// GetTimeoutHeight implements PacketI interface
|
||||
func (p Packet) GetTimeoutHeight() uint64 { return p.TimeoutHeight }
|
||||
|
||||
// GetTimeoutTimestamp implements PacketI interface
|
||||
func (p Packet) GetTimeoutTimestamp() uint64 { return p.TimeoutTimestamp }
|
||||
|
||||
// ValidateBasic implements PacketI interface
|
||||
func (p Packet) ValidateBasic() error {
|
||||
if err := host.DefaultPortIdentifierValidator(p.SourcePort); err != nil {
|
||||
|
@ -105,8 +110,8 @@ func (p Packet) ValidateBasic() error {
|
|||
if p.Sequence == 0 {
|
||||
return sdkerrors.Wrap(ErrInvalidPacket, "packet sequence cannot be 0")
|
||||
}
|
||||
if p.TimeoutHeight == 0 {
|
||||
return sdkerrors.Wrap(ErrInvalidPacket, "packet timeout cannot be 0")
|
||||
if p.TimeoutHeight == 0 && p.TimeoutTimestamp == 0 {
|
||||
return sdkerrors.Wrap(ErrInvalidPacket, "packet timeout height and packet timeout timestamp cannot both be 0")
|
||||
}
|
||||
if len(p.Data) == 0 {
|
||||
return sdkerrors.Wrap(ErrInvalidPacket, "packet data bytes cannot be empty")
|
||||
|
|
|
@ -12,13 +12,16 @@ func TestPacketValidateBasic(t *testing.T) {
|
|||
expPass bool
|
||||
errMsg string
|
||||
}{
|
||||
{NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeout), true, ""},
|
||||
{NewPacket(validPacketData, 0, portid, chanid, cpportid, cpchanid, timeout), false, "invalid sequence"},
|
||||
{NewPacket(validPacketData, 1, invalidPort, chanid, cpportid, cpchanid, timeout), false, "invalid source port"},
|
||||
{NewPacket(validPacketData, 1, portid, invalidChannel, cpportid, cpchanid, timeout), false, "invalid source channel"},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, invalidPort, cpchanid, timeout), false, "invalid destination port"},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, cpportid, invalidChannel, timeout), false, "invalid destination channel"},
|
||||
{NewPacket(unknownPacketData, 1, portid, chanid, cpportid, cpchanid, timeout), true, ""},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""},
|
||||
{NewPacket(validPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid sequence"},
|
||||
{NewPacket(validPacketData, 1, invalidPort, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source port"},
|
||||
{NewPacket(validPacketData, 1, portid, invalidChannel, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source channel"},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, invalidPort, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid destination port"},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, cpportid, invalidChannel, timeoutHeight, timeoutTimestamp), false, "invalid destination channel"},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, disabledTimeout), false, "disabled both timeout height and timestamp"},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, timeoutTimestamp), true, "disabled timeout height, valid timeout timestamp"},
|
||||
{NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, disabledTimeout), true, "disabled timeout timestamp, valid timeout height"},
|
||||
{NewPacket(unknownPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
|
|
|
@ -34,9 +34,9 @@ func (cs ConsensusState) GetHeight() uint64 {
|
|||
return cs.Height
|
||||
}
|
||||
|
||||
// GetTimestamp returns block time at which the consensus state was stored
|
||||
func (cs ConsensusState) GetTimestamp() time.Time {
|
||||
return cs.Timestamp
|
||||
// GetTimestamp returns block time in nanoseconds at which the consensus state was stored
|
||||
func (cs ConsensusState) GetTimestamp() uint64 {
|
||||
return uint64(cs.Timestamp.UnixNano())
|
||||
}
|
||||
|
||||
// ValidateBasic defines a basic validation for the tendermint consensus state.
|
||||
|
@ -53,5 +53,8 @@ func (cs ConsensusState) ValidateBasic() error {
|
|||
if cs.Timestamp.IsZero() {
|
||||
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be zero Unix time")
|
||||
}
|
||||
if cs.Timestamp.UnixNano() < 0 {
|
||||
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be negative Unix time")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -12,20 +12,21 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
DefaultPacketTimeout = keeper.DefaultPacketTimeout
|
||||
EventTypeTimeout = types.EventTypeTimeout
|
||||
EventTypePacket = types.EventTypePacket
|
||||
EventTypeChannelClose = types.EventTypeChannelClose
|
||||
AttributeKeyReceiver = types.AttributeKeyReceiver
|
||||
AttributeKeyValue = types.AttributeKeyValue
|
||||
AttributeKeyRefundReceiver = types.AttributeKeyRefundReceiver
|
||||
AttributeKeyRefundValue = types.AttributeKeyRefundValue
|
||||
AttributeKeyAckSuccess = types.AttributeKeyAckSuccess
|
||||
AttributeKeyAckError = types.AttributeKeyAckError
|
||||
ModuleName = types.ModuleName
|
||||
StoreKey = types.StoreKey
|
||||
RouterKey = types.RouterKey
|
||||
QuerierRoute = types.QuerierRoute
|
||||
DefaultPacketTimeoutHeight = keeper.DefaultPacketTimeoutHeight
|
||||
DefaultPacketTimeoutTimestamp = keeper.DefaultPacketTimeoutTimestamp
|
||||
EventTypeTimeout = types.EventTypeTimeout
|
||||
EventTypePacket = types.EventTypePacket
|
||||
EventTypeChannelClose = types.EventTypeChannelClose
|
||||
AttributeKeyReceiver = types.AttributeKeyReceiver
|
||||
AttributeKeyValue = types.AttributeKeyValue
|
||||
AttributeKeyRefundReceiver = types.AttributeKeyRefundReceiver
|
||||
AttributeKeyRefundValue = types.AttributeKeyRefundValue
|
||||
AttributeKeyAckSuccess = types.AttributeKeyAckSuccess
|
||||
AttributeKeyAckError = types.AttributeKeyAckError
|
||||
ModuleName = types.ModuleName
|
||||
StoreKey = types.StoreKey
|
||||
RouterKey = types.RouterKey
|
||||
QuerierRoute = types.QuerierRoute
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -17,9 +17,14 @@ import (
|
|||
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
|
||||
)
|
||||
|
||||
// DefaultPacketTimeout is the default packet timeout relative to the current block height
|
||||
const (
|
||||
DefaultPacketTimeout = 1000 // NOTE: in blocks
|
||||
// DefaultPacketTimeoutHeight is the default packet timeout height relative
|
||||
// to the current block height. The timeout is disabled when set to 0.
|
||||
DefaultPacketTimeoutHeight = 1000 // NOTE: in blocks
|
||||
|
||||
// DefaultPacketTimeoutTimestamp is the default packet timeout timestamp relative
|
||||
// to the current block timestamp. The timeout is disabled when set to 0.
|
||||
DefaultPacketTimeoutTimestamp = 0 // NOTE: in nanoseconds
|
||||
)
|
||||
|
||||
// Keeper defines the IBC transfer keeper
|
||||
|
|
|
@ -134,7 +134,8 @@ func (k Keeper) createOutgoingPacket(
|
|||
sourceChannel,
|
||||
destinationPort,
|
||||
destinationChannel,
|
||||
destHeight+DefaultPacketTimeout,
|
||||
destHeight+DefaultPacketTimeoutHeight,
|
||||
DefaultPacketTimeoutTimestamp,
|
||||
)
|
||||
|
||||
return k.channelKeeper.SendPacket(ctx, channelCap, packet)
|
||||
|
|
|
@ -141,7 +141,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
|
|||
}, true},
|
||||
}
|
||||
|
||||
packet := channeltypes.NewPacket(data.GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 100)
|
||||
packet := channeltypes.NewPacket(data.GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 100, 0)
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
|
@ -196,7 +196,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() {
|
|||
}, false, false},
|
||||
}
|
||||
|
||||
packet := channeltypes.NewPacket(data.GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 100)
|
||||
packet := channeltypes.NewPacket(data.GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 100, 0)
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
|
@ -266,7 +266,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() {
|
|||
}, true, false},
|
||||
}
|
||||
|
||||
packet := channeltypes.NewPacket(data.GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 100)
|
||||
packet := channeltypes.NewPacket(data.GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 100, 0)
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
|
|
|
@ -87,7 +87,7 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketOrdered() {
|
|||
suite.chainA.App.IBCKeeper.ChannelKeeper,
|
||||
))
|
||||
|
||||
packet := channel.NewPacket(newPacket(12345).GetData(), 1, portid, chanid, cpportid, cpchanid, 100)
|
||||
packet := channel.NewPacket(newPacket(12345).GetData(), 1, portid, chanid, cpportid, cpchanid, 100, 0)
|
||||
|
||||
ctx := suite.chainA.GetContext()
|
||||
cctx, _ := ctx.CacheContext()
|
||||
|
@ -146,7 +146,7 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketUnordered() {
|
|||
|
||||
var packet channeltypes.Packet
|
||||
for i := 0; i < 5; i++ {
|
||||
packet = channel.NewPacket(newPacket(uint64(i)).GetData(), uint64(i), portid, chanid, cpportid, cpchanid, 100)
|
||||
packet = channel.NewPacket(newPacket(uint64(i)).GetData(), uint64(i), portid, chanid, cpportid, cpchanid, 100, 0)
|
||||
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), packet.SourcePort, packet.SourceChannel, uint64(i), channeltypes.CommitPacket(packet))
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketUnordered() {
|
|||
|
||||
for i := 10; i >= 0; i-- {
|
||||
cctx, write := suite.chainA.GetContext().CacheContext()
|
||||
packet = channel.NewPacket(newPacket(uint64(i)).GetData(), uint64(i), portid, chanid, cpportid, cpchanid, 100)
|
||||
packet = channel.NewPacket(newPacket(uint64(i)).GetData(), uint64(i), portid, chanid, cpportid, cpchanid, 100, 0)
|
||||
packetCommitmentPath := ibctypes.PacketCommitmentPath(packet.SourcePort, packet.SourceChannel, uint64(i))
|
||||
proof, proofHeight := queryProof(suite.chainB, packetCommitmentPath)
|
||||
msg := channel.NewMsgPacket(packet, proof, uint64(proofHeight), addr1)
|
||||
|
|
Loading…
Reference in New Issue