From ebdadaf7f1eeb688fe57089578e8fc4aded11c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 14 Jan 2021 11:44:35 +0100 Subject: [PATCH 1/4] fix config race condition bug --- Makefile | 3 +- relayer/chain.go | 1 + relayer/channel-tx.go | 34 ++++----- relayer/client-tx.go | 6 +- relayer/connection-tx.go | 26 +++---- relayer/msgs.go | 157 ++++++++++++++++++++++++++++++++++++++ relayer/naive-strategy.go | 10 +-- relayer/packet-tx.go | 4 +- relayer/pathEnd.go | 138 +-------------------------------- test/test_chains.go | 2 +- 10 files changed, 204 insertions(+), 177 deletions(-) create mode 100644 relayer/msgs.go diff --git a/Makefile b/Makefile index 0901e59cd..4ea8d0b8a 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,7 @@ test-gaia: @TEST_DEBUG=true go test -mod=readonly -v ./test/... -run TestGaia* test-akash: - @echo Temporarily Disabled -# @TEST_DEBUG=true go test -mod=readonly -v ./test/... -run TestAkash* + @TEST_DEBUG=true go test -mod=readonly -v ./test/... -run TestAkash* coverage: @echo "viewing test coverage..." diff --git a/relayer/chain.go b/relayer/chain.go index 518997f16..f3f14f51b 100644 --- a/relayer/chain.go +++ b/relayer/chain.go @@ -427,6 +427,7 @@ func (c *Chain) MustGetAddress() sdk.AccAddress { if err != nil { panic(err) } + return srcAddr } diff --git a/relayer/channel-tx.go b/relayer/channel-tx.go index 81186ab14..375feeaad 100644 --- a/relayer/channel-tx.go +++ b/relayer/channel-tx.go @@ -128,13 +128,13 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro logChannelStates(src, dst, srcChan, dstChan) } - openTry, err := src.PathEnd.ChanTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1, src.MustGetAddress()) + openTry, err := src.ChanTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, false, err } msgs = []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), openTry, } @@ -151,13 +151,13 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro logChannelStates(src, dst, srcChan, dstChan) } - openAck, err := src.PathEnd.ChanAck(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1, src.MustGetAddress()) + openAck, err := src.ChanAck(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, false, err } msgs = []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), openAck, } @@ -174,13 +174,13 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro logChannelStates(dst, src, dstChan, srcChan) } - openAck, err := dst.PathEnd.ChanAck(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1, src.MustGetAddress()) + openAck, err := dst.ChanAck(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, false, err } msgs = []sdk.Msg{ - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), openAck, } @@ -195,7 +195,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro logChannelStates(src, dst, srcChan, dstChan) } msgs = []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), src.PathEnd.ChanConfirm(dstChan, src.MustGetAddress()), } last = true @@ -211,7 +211,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro logChannelStates(dst, src, dstChan, srcChan) } msgs = []sdk.Msg{ - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), dst.PathEnd.ChanConfirm(srcChan, dst.MustGetAddress()), } last = true @@ -242,7 +242,7 @@ func InitializeChannel(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmclie // cosntruct OpenInit message to be submitted on source chain msgs := []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), src.PathEnd.ChanInit(dst.PathEnd, src.MustGetAddress()), } @@ -269,13 +269,13 @@ func InitializeChannel(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmclie } // open try on source chain - openTry, err := src.PathEnd.ChanTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1, src.MustGetAddress()) + openTry, err := src.ChanTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, err } msgs := []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), openTry, } res, success, err := src.SendMsgs(msgs) @@ -301,13 +301,13 @@ func InitializeChannel(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmclie } // open try on destination chain - openTry, err := dst.PathEnd.ChanTry(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1, dst.MustGetAddress()) + openTry, err := dst.ChanTry(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, err } msgs := []sdk.Msg{ - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), openTry, } res, success, err := dst.SendMsgs(msgs) @@ -412,7 +412,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { logChannelStates(c, dst, srcChan, dstChan) } out.Src = append(out.Src, - c.PathEnd.UpdateClient(dstUpdateHeader, c.MustGetAddress()), + c.UpdateClient(dstUpdateHeader), c.PathEnd.ChanCloseInit(c.MustGetAddress()), ) } else if dstChan.Channel.State != chantypes.UNINITIALIZED { @@ -420,7 +420,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { logChannelStates(dst, c, dstChan, srcChan) } out.Dst = append(out.Dst, - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), dst.PathEnd.ChanCloseInit(dst.MustGetAddress()), ) } @@ -432,7 +432,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { logChannelStates(dst, c, dstChan, srcChan) } out.Dst = append(out.Dst, - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), dst.PathEnd.ChanCloseConfirm(srcChan, dst.MustGetAddress()), ) out.Last = true @@ -445,7 +445,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { logChannelStates(c, dst, srcChan, dstChan) } out.Src = append(out.Src, - c.PathEnd.UpdateClient(dstUpdateHeader, c.MustGetAddress()), + c.UpdateClient(dstUpdateHeader), c.PathEnd.ChanCloseConfirm(dstChan, c.MustGetAddress()), ) out.Last = true diff --git a/relayer/client-tx.go b/relayer/client-tx.go index 418ced3cd..632522d2e 100644 --- a/relayer/client-tx.go +++ b/relayer/client-tx.go @@ -127,8 +127,8 @@ func (c *Chain) UpdateClients(dst *Chain) (err error) { return err } - clients.Src = append(clients.Src, c.PathEnd.UpdateClient(dstUH, c.MustGetAddress())) - clients.Dst = append(clients.Dst, dst.PathEnd.UpdateClient(srcUH, dst.MustGetAddress())) + clients.Src = append(clients.Src, c.UpdateClient(dstUH)) + clients.Dst = append(clients.Dst, dst.UpdateClient(srcUH)) // Send msgs to both chains if clients.Ready() { @@ -180,7 +180,7 @@ func (c *Chain) UpgradeClients(dst *Chain) error { upgradeMsg := &clienttypes.MsgUpgradeClient{c.PathEnd.ClientID, clientState, consensusState, proofUpgradeClient, proofUpgradeConsensusState, c.MustGetAddress().String()} msgs := []sdk.Msg{ - c.PathEnd.UpdateClient(dstUpdateHeader, c.MustGetAddress()), + c.UpdateClient(dstUpdateHeader), upgradeMsg, } diff --git a/relayer/connection-tx.go b/relayer/connection-tx.go index d012b2e41..0ed8428b7 100644 --- a/relayer/connection-tx.go +++ b/relayer/connection-tx.go @@ -129,13 +129,13 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e logConnectionStates(src, dst, srcConn, dstConn) } - openTry, err := src.PathEnd.ConnTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1, src.MustGetAddress()) + openTry, err := src.ConnTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, false, err } msgs = []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), openTry, } _, success, err = src.SendMsgs(msgs) @@ -151,13 +151,13 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e logConnectionStates(src, dst, srcConn, dstConn) } - openAck, err := src.PathEnd.ConnAck(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1, src.MustGetAddress()) + openAck, err := src.ConnAck(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, false, err } msgs = []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), openAck, } _, success, err = src.SendMsgs(msgs) @@ -173,13 +173,13 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e logConnectionStates(dst, src, dstConn, srcConn) } - openAck, err := dst.PathEnd.ConnAck(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1, dst.MustGetAddress()) + openAck, err := dst.ConnAck(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, false, err } msgs = []sdk.Msg{ - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), openAck, } _, success, err = dst.SendMsgs(msgs) @@ -193,7 +193,7 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e logConnectionStates(src, dst, srcConn, dstConn) } msgs = []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), src.PathEnd.ConnConfirm(dstConn, src.MustGetAddress()), } _, success, err = src.SendMsgs(msgs) @@ -209,7 +209,7 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e logConnectionStates(dst, src, dstConn, srcConn) } msgs = []sdk.Msg{ - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), dst.PathEnd.ConnConfirm(srcConn, dst.MustGetAddress()), } last = true @@ -239,7 +239,7 @@ func InitializeConnection(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmc // cosntruct OpenInit message to be submitted on source chain msgs := []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), src.PathEnd.ConnInit(dst.PathEnd, src.MustGetAddress()), } @@ -265,13 +265,13 @@ func InitializeConnection(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmc // TODO: update logging } - openTry, err := src.PathEnd.ConnTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1, src.MustGetAddress()) + openTry, err := src.ConnTry(dst, dstUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, err } msgs := []sdk.Msg{ - src.PathEnd.UpdateClient(dstUpdateHeader, src.MustGetAddress()), + src.UpdateClient(dstUpdateHeader), openTry, } res, success, err := src.SendMsgs(msgs) @@ -296,13 +296,13 @@ func InitializeConnection(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmc // TODO: update logging } - openTry, err := dst.PathEnd.ConnTry(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1, dst.MustGetAddress()) + openTry, err := dst.ConnTry(src, srcUpdateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return false, false, err } msgs := []sdk.Msg{ - dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), + dst.UpdateClient(srcUpdateHeader), openTry, } res, success, err := dst.SendMsgs(msgs) diff --git a/relayer/msgs.go b/relayer/msgs.go new file mode 100644 index 000000000..6704b764c --- /dev/null +++ b/relayer/msgs.go @@ -0,0 +1,157 @@ +package relayer + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + transfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + conntypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" + ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" +) + +// NOTE: we explicitly call 'MustGetAddress' before 'NewMsg...' +// to ensure the correct config file is being used to generate +// the account prefix. 'NewMsg...' functions take an AccAddress +// rather than a string. The 'address.String()' function uses +// the currently set config file. Querying a counterparty would +// swap the config file. 'MustGetAddress' sets the config file +// correctly. Do not change this ordering until the SDK config +// file handling has been refactored. + +// UpdateClient creates an sdk.Msg to update the client on src with data pulled from dst +func (c *Chain) UpdateClient(dstHeader ibcexported.Header) sdk.Msg { + if err := dstHeader.ValidateBasic(); err != nil { + panic(err) + } + msg, err := clienttypes.NewMsgUpdateClient( + c.PathEnd.ClientID, + dstHeader, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ) + if err != nil { + panic(err) + } + return msg +} + +// ConnTry creates a MsgConnectionOpenTry +func (c *Chain) ConnTry( + counterparty *Chain, + height uint64, +) (sdk.Msg, error) { + clientState, clientStateProof, consensusStateProof, connStateProof, proofHeight, err := counterparty.GenerateConnHandshakeProof(height) + if err != nil { + return nil, err + } + + // TODO: Get DelayPeriod from counterparty connection rather than using default value + msg := conntypes.NewMsgConnectionOpenTry( + c.PathEnd.ConnectionID, + c.PathEnd.ClientID, + counterparty.PathEnd.ConnectionID, + counterparty.PathEnd.ClientID, + clientState, + defaultChainPrefix, + conntypes.ExportedVersionsToProto(conntypes.GetCompatibleVersions()), + defaultDelayPeriod, + connStateProof, + clientStateProof, + consensusStateProof, + proofHeight, + clientState.GetLatestHeight().(clienttypes.Height), + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ) + if err := msg.ValidateBasic(); err != nil { + return nil, err + } + return msg, nil +} + +// ConnAck creates a MsgConnectionOpenAck +func (c *Chain) ConnAck( + counterparty *Chain, + height uint64, +) (sdk.Msg, error) { + clientState, clientStateProof, consensusStateProof, connStateProof, proofHeight, err := counterparty.GenerateConnHandshakeProof(height) + if err != nil { + return nil, err + } + + return conntypes.NewMsgConnectionOpenAck( + c.PathEnd.ConnectionID, + counterparty.PathEnd.ConnectionID, + clientState, + connStateProof, + clientStateProof, + consensusStateProof, + proofHeight, + clientState.GetLatestHeight().(clienttypes.Height), + conntypes.DefaultIBCVersion, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ), nil +} + +// ChanTry creates a MsgChannelOpenTry +func (c *Chain) ChanTry( + counterparty *Chain, + height uint64, +) (sdk.Msg, error) { + // obtain proof from counterparty chain + counterpartyChannelRes, err := counterparty.QueryChannel(int64(height)) + if err != nil { + return nil, err + } + + return chantypes.NewMsgChannelOpenTry( + c.PathEnd.PortID, + c.PathEnd.ChannelID, + c.PathEnd.Version, + counterpartyChannelRes.Channel.Ordering, + []string{c.PathEnd.ConnectionID}, + counterparty.PathEnd.PortID, + counterparty.PathEnd.ChannelID, + counterpartyChannelRes.Channel.Version, + counterpartyChannelRes.Proof, + counterpartyChannelRes.ProofHeight, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + + ), nil +} + +// ChanAck creates a MsgChannelOpenAck +func (c *Chain) ChanAck( + counterparty *Chain, + height uint64, +) (sdk.Msg, error) { + // obtain proof from counterparty chain + counterpartyChannelRes, err := counterparty.QueryChannel(int64(height)) + if err != nil { + return nil, err + } + + return chantypes.NewMsgChannelOpenAck( + c.PathEnd.PortID, + c.PathEnd.ChannelID, + counterparty.PathEnd.ChannelID, + counterpartyChannelRes.Channel.Version, + counterpartyChannelRes.Proof, + counterpartyChannelRes.ProofHeight, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ), nil +} + +// 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, + c.PathEnd.ChannelID, + amount, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + dstAddr, + clienttypes.NewHeight(version, timeoutHeight), + timeoutTimestamp, + ) +} diff --git a/relayer/naive-strategy.go b/relayer/naive-strategy.go index 0a2a114bf..9a0d16b8e 100644 --- a/relayer/naive-strategy.go +++ b/relayer/naive-strategy.go @@ -354,7 +354,7 @@ func (nrs *NaiveStrategy) sendTxFromEventPackets(src, dst *Chain, rlyPackets []r // instantiate the RelayMsgs with the appropriate update client txs := &RelayMsgs{ Src: []sdk.Msg{ - src.PathEnd.UpdateClient(updateHeader, src.MustGetAddress()), + src.UpdateClient(updateHeader), }, Dst: []sdk.Msg{}, MaxTxSize: nrs.MaxTxSize, @@ -442,7 +442,7 @@ func (nrs *NaiveStrategy) RelayAcknowledgements(src, dst *Chain, sp *RelaySequen if err != nil { return err } - msgs.Dst = append([]sdk.Msg{dst.PathEnd.UpdateClient(updateHeader, dst.MustGetAddress())}, msgs.Dst...) + msgs.Dst = append([]sdk.Msg{dst.UpdateClient(updateHeader)}, msgs.Dst...) } if len(msgs.Src) != 0 { @@ -451,7 +451,7 @@ func (nrs *NaiveStrategy) RelayAcknowledgements(src, dst *Chain, sp *RelaySequen if err != nil { return err } - msgs.Src = append([]sdk.Msg{src.PathEnd.UpdateClient(updateHeader, src.MustGetAddress())}, msgs.Src...) + msgs.Src = append([]sdk.Msg{src.UpdateClient(updateHeader)}, msgs.Src...) } // send messages to their respective chains @@ -551,7 +551,7 @@ func (nrs *NaiveStrategy) RelayPackets(src, dst *Chain, sp *RelaySequences, sh * if err != nil { return err } - msgs.Dst = append([]sdk.Msg{dst.PathEnd.UpdateClient(updateHeader, dst.MustGetAddress())}, msgs.Dst...) + msgs.Dst = append([]sdk.Msg{dst.UpdateClient(updateHeader)}, msgs.Dst...) } if len(msgs.Src) != 0 { @@ -560,7 +560,7 @@ func (nrs *NaiveStrategy) RelayPackets(src, dst *Chain, sp *RelaySequences, sh * if err != nil { return err } - msgs.Src = append([]sdk.Msg{src.PathEnd.UpdateClient(updateHeader, src.MustGetAddress())}, msgs.Src...) + msgs.Src = append([]sdk.Msg{src.UpdateClient(updateHeader)}, msgs.Src...) } // send messages to their respective chains diff --git a/relayer/packet-tx.go b/relayer/packet-tx.go index 4ad31d0a1..2a4e33b7e 100644 --- a/relayer/packet-tx.go +++ b/relayer/packet-tx.go @@ -38,8 +38,8 @@ func (c *Chain) SendTransferMsg(dst *Chain, amount sdk.Coin, dstAddr fmt.Stringe // MsgTransfer will call SendPacket on src chain txs := RelayMsgs{ - Src: []sdk.Msg{c.PathEnd.MsgTransfer( - dst.PathEnd, amount, dstAddrString, c.MustGetAddress(), timeoutHeight, timeoutTimestamp, + Src: []sdk.Msg{c.MsgTransfer( + dst.PathEnd, amount, dstAddrString, timeoutHeight, timeoutTimestamp, )}, Dst: []sdk.Msg{}, } diff --git a/relayer/pathEnd.go b/relayer/pathEnd.go index db4c1a494..9143c0978 100644 --- a/relayer/pathEnd.go +++ b/relayer/pathEnd.go @@ -10,11 +10,14 @@ import ( conntypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types" - ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" "github.com/tendermint/tendermint/light" ) +// TODO: migrate all message construction methods to msgs.go and use the chain +// to construct them. +// https://github.com/cosmos/relayer/issues/368 + var ( defaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc")) defaultDelayPeriod = uint64(0) @@ -66,22 +69,6 @@ func UnmarshalChain(pe PathEnd) *Chain { return nil } -// UpdateClient creates an sdk.Msg to update the client on src with data pulled from dst -func (pe *PathEnd) UpdateClient(dstHeader ibcexported.Header, signer sdk.AccAddress) sdk.Msg { - if err := dstHeader.ValidateBasic(); err != nil { - panic(err) - } - msg, err := clienttypes.NewMsgUpdateClient( - pe.ClientID, - dstHeader, - signer, - ) - if err != nil { - panic(err) - } - return msg -} - // CreateClient creates an sdk.Msg to update the client on src with consensus state from dst func (pe *PathEnd) CreateClient( dstHeader *tmclient.Header, @@ -133,65 +120,6 @@ func (pe *PathEnd) ConnInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Ms ) } -// ConnTry creates a MsgConnectionOpenTry -func (pe *PathEnd) ConnTry( - counterparty *Chain, - height uint64, - signer sdk.AccAddress, -) (sdk.Msg, error) { - clientState, clientStateProof, consensusStateProof, connStateProof, proofHeight, err := counterparty.GenerateConnHandshakeProof(height) - if err != nil { - return nil, err - } - - // TODO: Get DelayPeriod from counterparty connection rather than using default value - msg := conntypes.NewMsgConnectionOpenTry( - pe.ConnectionID, - pe.ClientID, - counterparty.PathEnd.ConnectionID, - counterparty.PathEnd.ClientID, - clientState, - defaultChainPrefix, - conntypes.ExportedVersionsToProto(conntypes.GetCompatibleVersions()), - defaultDelayPeriod, - connStateProof, - clientStateProof, - consensusStateProof, - proofHeight, - clientState.GetLatestHeight().(clienttypes.Height), - signer, - ) - if err := msg.ValidateBasic(); err != nil { - return nil, err - } - return msg, nil -} - -// ConnAck creates a MsgConnectionOpenAck -func (pe *PathEnd) ConnAck( - counterparty *Chain, - height uint64, - signer sdk.AccAddress, -) (sdk.Msg, error) { - clientState, clientStateProof, consensusStateProof, connStateProof, proofHeight, err := counterparty.GenerateConnHandshakeProof(height) - if err != nil { - return nil, err - } - - return conntypes.NewMsgConnectionOpenAck( - pe.ConnectionID, - counterparty.PathEnd.ConnectionID, - clientState, - connStateProof, - clientStateProof, - consensusStateProof, - proofHeight, - clientState.GetLatestHeight().(clienttypes.Height), - conntypes.DefaultIBCVersion, - signer, - ), nil -} - // ConnConfirm creates a MsgConnectionOpenConfirm func (pe *PathEnd) ConnConfirm(counterpartyConnState *conntypes.QueryConnectionResponse, signer sdk.AccAddress) sdk.Msg { return conntypes.NewMsgConnectionOpenConfirm( @@ -214,48 +142,6 @@ func (pe *PathEnd) ChanInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Ms ) } -// ChanTry creates a MsgChannelOpenTry -func (pe *PathEnd) ChanTry(counterparty *Chain, height uint64, signer sdk.AccAddress) (sdk.Msg, error) { - // obtain proof from counterparty chain - counterpartyChannelRes, err := counterparty.QueryChannel(int64(height)) - if err != nil { - return nil, err - } - - return chantypes.NewMsgChannelOpenTry( - pe.PortID, - pe.ChannelID, - pe.Version, - counterpartyChannelRes.Channel.Ordering, - []string{pe.ConnectionID}, - counterparty.PathEnd.PortID, - counterparty.PathEnd.ChannelID, - counterpartyChannelRes.Channel.Version, - counterpartyChannelRes.Proof, - counterpartyChannelRes.ProofHeight, - signer, - ), nil -} - -// ChanAck creates a MsgChannelOpenAck -func (pe *PathEnd) ChanAck(counterparty *Chain, height uint64, signer sdk.AccAddress) (sdk.Msg, error) { - // obtain proof from counterparty chain - counterpartyChannelRes, err := counterparty.QueryChannel(int64(height)) - if err != nil { - return nil, err - } - - return chantypes.NewMsgChannelOpenAck( - pe.PortID, - pe.ChannelID, - counterparty.PathEnd.ChannelID, - counterpartyChannelRes.Channel.Version, - counterpartyChannelRes.Proof, - counterpartyChannelRes.ProofHeight, - signer, - ), nil -} - // ChanConfirm creates a MsgChannelOpenConfirm func (pe *PathEnd) ChanConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { return chantypes.NewMsgChannelOpenConfirm( @@ -287,22 +173,6 @@ func (pe *PathEnd) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse ) } -// MsgTransfer creates a new transfer message -func (pe *PathEnd) MsgTransfer(dst *PathEnd, amount sdk.Coin, dstAddr string, - signer sdk.AccAddress, timeoutHeight, timeoutTimestamp uint64) sdk.Msg { - - version := clienttypes.ParseChainID(dst.ChainID) - return transfertypes.NewMsgTransfer( - pe.PortID, - pe.ChannelID, - amount, - signer, - dstAddr, - clienttypes.NewHeight(version, timeoutHeight), - timeoutTimestamp, - ) -} - // 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 { diff --git a/test/test_chains.go b/test/test_chains.go index 93a64d821..5904e5e63 100644 --- a/test/test_chains.go +++ b/test/test_chains.go @@ -34,7 +34,7 @@ var ( // 3 second relayer timeout works well with these block times akashTestConfig = testChainConfig{ dockerImage: "jackzampolin/akashtest", - dockerTag: "jack_update-sdk", + dockerTag: "jack_update-ibc-args", timeout: 3 * time.Second, rpcPort: "26657", accountPrefix: "akash", From a036e0b0f30098dfb2539d2489658cf11a6101e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 14 Jan 2021 12:07:17 +0100 Subject: [PATCH 2/4] fix build and link sdk issue --- cmd/raw.go | 24 ++++++++++++------------ relayer/msgs.go | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/raw.go b/cmd/raw.go index e5084bff4..b55f0f863 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -70,7 +70,7 @@ $ %s tx raw uc ibc-0 ibc-1 ibconeclient`, appName, appName)), if err != nil { return err } - return sendAndPrint([]sdk.Msg{chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress())}, + return sendAndPrint([]sdk.Msg{chains[src].UpdateClient(updateHeader)}, chains[src], cmd) }, } @@ -177,13 +177,13 @@ $ %s tx raw conn-try ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2`, if err != nil { return err } - openTry, err := chains[src].PathEnd.ConnTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress()) + openTry, err := chains[src].ConnTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return err } txs := []sdk.Msg{ - chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), + chains[src].UpdateClient(updateHeader), openTry, } @@ -226,13 +226,13 @@ $ %s tx raw conn-ack ibc-0 ibc-1 ibconeclient ibczeroclient ibcconn1 ibcconn2`, return err } - openAck, err := chains[src].PathEnd.ConnAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress()) + openAck, err := chains[src].ConnAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return err } txs := []sdk.Msg{ - chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), + chains[src].UpdateClient(updateHeader), openAck, } @@ -283,7 +283,7 @@ $ %s tx raw conn-confirm ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn } txs := []sdk.Msg{ chains[src].PathEnd.ConnConfirm(dstState, chains[src].MustGetAddress()), - chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), + chains[src].UpdateClient(updateHeader), } return sendAndPrint(txs, chains[src], cmd) @@ -399,13 +399,13 @@ $ %s tx raw chan-try ibc-0 ibc-1 ibczeroclient ibcconn0 ibcchan1 ibcchan2 transf return err } - openTry, err := chains[src].PathEnd.ChanTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress()) + openTry, err := chains[src].ChanTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return err } txs := []sdk.Msg{ - chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), + chains[src].UpdateClient(updateHeader), openTry, } @@ -450,13 +450,13 @@ $ %s tx raw chan-ack ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer transf return err } - openAck, err := chains[src].PathEnd.ChanAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress()) + openAck, err := chains[src].ChanAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1) if err != nil { return err } txs := []sdk.Msg{ - chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), + chains[src].UpdateClient(updateHeader), openAck, } @@ -505,7 +505,7 @@ $ %s tx raw chan-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer tr return err } txs := []sdk.Msg{ - chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), + chains[src].UpdateClient(updateHeader), chains[src].PathEnd.ChanConfirm(dstChanState, chains[src].MustGetAddress()), } @@ -619,7 +619,7 @@ $ %s tx raw chan-close-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 trans return err } txs := []sdk.Msg{ - chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), + chains[src].UpdateClient(updateHeader), chains[src].PathEnd.ChanCloseConfirm(dstChanState, chains[src].MustGetAddress()), } diff --git a/relayer/msgs.go b/relayer/msgs.go index 6704b764c..a8008499c 100644 --- a/relayer/msgs.go +++ b/relayer/msgs.go @@ -17,6 +17,7 @@ import ( // swap the config file. 'MustGetAddress' sets the config file // correctly. Do not change this ordering until the SDK config // file handling has been refactored. +// https://github.com/cosmos/cosmos-sdk/issues/8332 // UpdateClient creates an sdk.Msg to update the client on src with data pulled from dst func (c *Chain) UpdateClient(dstHeader ibcexported.Header) sdk.Msg { From 45c97b829c649bae003dd4c5d193d2294ff39542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 14 Jan 2021 12:09:32 +0100 Subject: [PATCH 3/4] add back akash test --- .github/workflows/akash-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/akash-tests.yml b/.github/workflows/akash-tests.yml index 035336929..66a608af5 100644 --- a/.github/workflows/akash-tests.yml +++ b/.github/workflows/akash-tests.yml @@ -3,7 +3,7 @@ name: TESTING - akash to gaia integration on: push: branches: - - disabled_until_new_akash_build + - master jobs: build: From c09ab44857daf5d7415e0670fd33073edd6446b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 14 Jan 2021 12:11:21 +0100 Subject: [PATCH 4/4] akash test on pr --- .github/workflows/akash-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/akash-tests.yml b/.github/workflows/akash-tests.yml index 66a608af5..6bcd4dc00 100644 --- a/.github/workflows/akash-tests.yml +++ b/.github/workflows/akash-tests.yml @@ -1,6 +1,7 @@ name: TESTING - akash to gaia integration on: +- pull request: push: branches: - master