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

fix: updating timeout to use clienttypes.Height instead of uint64 #483

Merged
merged 4 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions relayer/ibc-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ func (c *Chain) InjectTrustedFields(dst *Chain, header *tmclient.Header) (*tmcli
}

// MustGetHeight takes the height inteface and returns the actual height
func MustGetHeight(h ibcexported.Height) uint64 {
func MustGetHeight(h ibcexported.Height) clienttypes.Height {
height, ok := h.(clienttypes.Height)
if !ok {
panic("height is not an instance of height! wtf")
panic("height is not an instance of height!")
}
return height.GetRevisionHeight()
return height
}
10 changes: 3 additions & 7 deletions relayer/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ func (c *Chain) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse) s
// MsgTransfer creates a new transfer message
func (c *Chain) MsgTransfer(dst *PathEnd, amount sdk.Coin, dstAddr string,
timeoutHeight, timeoutTimestamp uint64) sdk.Msg {

version := clienttypes.ParseChainID(dst.ChainID)
return transfertypes.NewMsgTransfer(
c.PathEnd.PortID,
Expand Down Expand Up @@ -366,7 +365,6 @@ func (c *Chain) MsgRelayRecvPacket(counterparty *Chain, packet *relayMsgRecvPack
return nil, fmt.Errorf("receive packet [%s]seq{%d} has no associated proofs", c.ChainID, packet.seq)
}

version := clienttypes.ParseChainID(c.ChainID)
msg := chantypes.NewMsgRecvPacket(
chantypes.NewPacket(
packet.packetData,
Expand All @@ -375,7 +373,7 @@ func (c *Chain) MsgRelayRecvPacket(counterparty *Chain, packet *relayMsgRecvPack
counterparty.PathEnd.ChannelID,
c.PathEnd.PortID,
c.PathEnd.ChannelID,
clienttypes.NewHeight(version, packet.timeout),
packet.timeout,
packet.timeoutStamp,
),
comRes.Proof,
Expand Down Expand Up @@ -428,7 +426,6 @@ func (c *Chain) MsgRelayAcknowledgement(counterparty *Chain, packet *relayMsgPac
return nil, fmt.Errorf("ack packet [%s]seq{%d} has no associated proofs", counterparty.ChainID, packet.seq)
}

version := clienttypes.ParseChainID(counterparty.ChainID)
msg := chantypes.NewMsgAcknowledgement(
chantypes.NewPacket(
packet.packetData,
Expand All @@ -437,7 +434,7 @@ func (c *Chain) MsgRelayAcknowledgement(counterparty *Chain, packet *relayMsgPac
c.PathEnd.ChannelID,
counterparty.PathEnd.PortID,
counterparty.PathEnd.ChannelID,
clienttypes.NewHeight(version, packet.timeout),
packet.timeout,
packet.timeoutStamp,
),
packet.ack,
Expand Down Expand Up @@ -493,7 +490,6 @@ func (c *Chain) MsgRelayTimeout(counterparty *Chain, packet *relayMsgTimeout) (m
return nil, fmt.Errorf("timeout packet [%s]seq{%d} has no associated proofs", c.ChainID, packet.seq)
}

version := clienttypes.ParseChainID(counterparty.ChainID)
msg := chantypes.NewMsgTimeout(
chantypes.NewPacket(
packet.packetData,
Expand All @@ -502,7 +498,7 @@ func (c *Chain) MsgRelayTimeout(counterparty *Chain, packet *relayMsgTimeout) (m
c.PathEnd.ChannelID,
counterparty.PathEnd.PortID,
counterparty.PathEnd.ChannelID,
clienttypes.NewHeight(version, packet.timeout),
packet.timeout,
packet.timeoutStamp,
),
packet.seq,
Expand Down
14 changes: 10 additions & 4 deletions relayer/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package relayer
import (
"fmt"
"strconv"
"strings"

retry "github.com/avast/retry-go"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -693,7 +692,11 @@ func relayPacketsFromResultTx(src, dst *Chain, res *ctypes.ResultTx) ([]relayPac
rp.packetData = p.Value
}
if string(p.Key) == toHeightTag {
timeout, _ := strconv.ParseUint(strings.Split(string(p.Value), "-")[1], 10, 64)
timeout, err := clienttypes.ParseHeight(string(p.Value))
if err != nil {
return nil, nil, err
}

rp.timeout = timeout
}
if string(p.Key) == toTSTag {
Expand All @@ -714,7 +717,7 @@ func relayPacketsFromResultTx(src, dst *Chain, res *ctypes.ResultTx) ([]relayPac

switch {
// If the packet has a timeout height, and it has been reached, return a timeout packet
case rp.timeout != 0 && block.GetHeight().GetRevisionHeight() >= rp.timeout:
case !rp.timeout.IsZero() != 0 && block.GetHeight().GTE(rp.timeout):
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
timeoutPackets = append(timeoutPackets, rp.timeoutPacket())
// If the packet has a timeout timestamp and it has been reached, return a timeout packet
case rp.timeoutStamp != 0 && block.GetTime().UnixNano() >= int64(rp.timeoutStamp):
Expand Down Expand Up @@ -775,7 +778,10 @@ func acknowledgementsFromResultTx(src, dst *PathEnd,
rp.packetData = p.Value
}
if string(p.Key) == toHeightTag {
timeout, _ := strconv.ParseUint(strings.Split(string(p.Value), "-")[1], 10, 64)
timeout, err := clienttypes.ParseHeight(string(p.Value))
if err != nil {
return nil, err
}
rp.timeout = timeout
}
if string(p.Key) == toTSTag {
Expand Down
5 changes: 2 additions & 3 deletions relayer/pathEnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ func UnmarshalChain(pe PathEnd) *Chain {

// NewPacket returns a new packet from src to dist w
func (pe *PathEnd) NewPacket(dst *PathEnd, sequence uint64, packetData []byte,
timeoutHeight, timeoutStamp uint64) chantypes.Packet {
version := clienttypes.ParseChainID(dst.ChainID)
timeoutHeight clienttypes.Height, timeoutStamp uint64) chantypes.Packet {
return chantypes.NewPacket(
packetData,
sequence,
pe.PortID,
pe.ChannelID,
dst.PortID,
dst.ChannelID,
clienttypes.NewHeight(version, timeoutHeight),
timeoutHeight,
timeoutStamp,
)
}
Expand Down
23 changes: 10 additions & 13 deletions relayer/relayPackets.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ type relayPacket interface {
FetchCommitResponse(src, dst *Chain) error
Data() []byte
Seq() uint64
Timeout() uint64
Timeout() clienttypes.Height
}

type relayMsgTimeout struct {
packetData []byte
seq uint64
timeout uint64
timeout clienttypes.Height
timeoutStamp uint64
dstRecvRes *chantypes.QueryPacketReceiptResponse

Expand All @@ -35,7 +35,7 @@ func (rp *relayMsgTimeout) Seq() uint64 {
return rp.seq
}

func (rp *relayMsgTimeout) Timeout() uint64 {
func (rp *relayMsgTimeout) Timeout() clienttypes.Height {
return rp.timeout
}

Expand Down Expand Up @@ -76,7 +76,6 @@ func (rp *relayMsgTimeout) Msg(src, dst *Chain) (sdk.Msg, error) {
if rp.dstRecvRes == nil {
return nil, fmt.Errorf("timeout packet [%s]seq{%d} has no associated proofs", src.ChainID, rp.seq)
}
version := clienttypes.ParseChainID(dst.ChainID)
msg := chantypes.NewMsgTimeout(
chantypes.NewPacket(
rp.packetData,
Expand All @@ -85,7 +84,7 @@ func (rp *relayMsgTimeout) Msg(src, dst *Chain) (sdk.Msg, error) {
src.PathEnd.ChannelID,
dst.PathEnd.PortID,
dst.PathEnd.ChannelID,
clienttypes.NewHeight(version, rp.timeout),
rp.timeout,
rp.timeoutStamp,
),
rp.seq,
Expand All @@ -99,7 +98,7 @@ func (rp *relayMsgTimeout) Msg(src, dst *Chain) (sdk.Msg, error) {
type relayMsgRecvPacket struct {
packetData []byte
seq uint64
timeout uint64
timeout clienttypes.Height
timeoutStamp uint64
dstComRes *chantypes.QueryPacketCommitmentResponse

Expand All @@ -125,7 +124,7 @@ func (rp *relayMsgRecvPacket) Seq() uint64 {
return rp.seq
}

func (rp *relayMsgRecvPacket) Timeout() uint64 {
func (rp *relayMsgRecvPacket) Timeout() clienttypes.Height {
return rp.timeout
}

Expand Down Expand Up @@ -166,15 +165,14 @@ func (rp *relayMsgRecvPacket) Msg(src, dst *Chain) (sdk.Msg, error) {
if rp.dstComRes == nil {
return nil, fmt.Errorf("receive packet [%s]seq{%d} has no associated proofs", src.ChainID, rp.seq)
}
version := clienttypes.ParseChainID(src.ChainID)
packet := chantypes.NewPacket(
rp.packetData,
rp.seq,
dst.PathEnd.PortID,
dst.PathEnd.ChannelID,
src.PathEnd.PortID,
src.PathEnd.ChannelID,
clienttypes.NewHeight(version, rp.timeout),
rp.timeout,
rp.timeoutStamp,
)
msg := chantypes.NewMsgRecvPacket(
Expand All @@ -190,7 +188,7 @@ type relayMsgPacketAck struct {
packetData []byte
ack []byte
seq uint64
timeout uint64
timeout clienttypes.Height
timeoutStamp uint64
dstComRes *chantypes.QueryPacketAcknowledgementResponse

Expand All @@ -203,15 +201,14 @@ func (rp *relayMsgPacketAck) Data() []byte {
func (rp *relayMsgPacketAck) Seq() uint64 {
return rp.seq
}
func (rp *relayMsgPacketAck) Timeout() uint64 {
func (rp *relayMsgPacketAck) Timeout() clienttypes.Height {
return rp.timeout
}

func (rp *relayMsgPacketAck) Msg(src, dst *Chain) (sdk.Msg, error) {
if rp.dstComRes == nil {
return nil, fmt.Errorf("ack packet [%s]seq{%d} has no associated proofs", src.ChainID, rp.seq)
}
version := clienttypes.ParseChainID(dst.ChainID)
msg := chantypes.NewMsgAcknowledgement(
chantypes.NewPacket(
rp.packetData,
Expand All @@ -220,7 +217,7 @@ func (rp *relayMsgPacketAck) Msg(src, dst *Chain) (sdk.Msg, error) {
src.PathEnd.ChannelID,
dst.PathEnd.PortID,
dst.PathEnd.ChannelID,
clienttypes.NewHeight(version, rp.timeout),
rp.timeout,
rp.timeoutStamp,
),
rp.ack,
Expand Down