From 63d58f166380b3473f205f2334f8a6a3a33ad8be Mon Sep 17 00:00:00 2001 From: PrathyushaLakkireddy Date: Tue, 19 Jan 2021 11:55:52 +0530 Subject: [PATCH 1/4] migrate messages from pathEnd.go to msgs.go --- cmd/raw.go | 14 ++--- relayer/channel-tx.go | 14 ++--- relayer/client-tx.go | 4 +- relayer/connection-tx.go | 6 +-- relayer/msgs.go | 109 +++++++++++++++++++++++++++++++++++++++ relayer/pathEnd.go | 108 -------------------------------------- 6 files changed, 128 insertions(+), 127 deletions(-) diff --git a/cmd/raw.go b/cmd/raw.go index b55f0f863..595f04e08 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -107,7 +107,7 @@ $ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)), return err } - return sendAndPrint([]sdk.Msg{chains[src].PathEnd.CreateClient(dstHeader, + return sendAndPrint([]sdk.Msg{chains[src].CreateClient(dstHeader, chains[dst].GetTrustingPeriod(), ubdPeriod, chains[src].MustGetAddress())}, chains[src], cmd) }, @@ -138,7 +138,7 @@ $ %s tx raw conn-init ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2`, return err } - return sendAndPrint([]sdk.Msg{chains[src].PathEnd.ConnInit(chains[dst].PathEnd, chains[src].MustGetAddress())}, + return sendAndPrint([]sdk.Msg{chains[src].ConnInit(chains[dst].PathEnd, chains[src].MustGetAddress())}, chains[src], cmd) }, } @@ -282,7 +282,7 @@ $ %s tx raw conn-confirm ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn return err } txs := []sdk.Msg{ - chains[src].PathEnd.ConnConfirm(dstState, chains[src].MustGetAddress()), + chains[src].ConnConfirm(dstState, chains[src].MustGetAddress()), chains[src].UpdateClient(updateHeader), } @@ -358,7 +358,7 @@ $ %s tx raw chan-init ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2 i return err } - return sendAndPrint([]sdk.Msg{chains[src].PathEnd.ChanInit(chains[dst].PathEnd, chains[src].MustGetAddress())}, + return sendAndPrint([]sdk.Msg{chains[src].ChanInit(chains[dst].PathEnd, chains[src].MustGetAddress())}, chains[src], cmd) }, } @@ -506,7 +506,7 @@ $ %s tx raw chan-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer tr } txs := []sdk.Msg{ chains[src].UpdateClient(updateHeader), - chains[src].PathEnd.ChanConfirm(dstChanState, chains[src].MustGetAddress()), + chains[src].ChanConfirm(dstChanState, chains[src].MustGetAddress()), } return sendAndPrint(txs, chains[src], cmd) @@ -575,7 +575,7 @@ $ %s tx raw chan-close-init ibc-0 ibcchan1 transfer`, appName, appName)), return err } - return sendAndPrint([]sdk.Msg{src.PathEnd.ChanCloseInit(src.MustGetAddress())}, src, cmd) + return sendAndPrint([]sdk.Msg{src.ChanCloseInit(src.MustGetAddress())}, src, cmd) }, } return cmd @@ -620,7 +620,7 @@ $ %s tx raw chan-close-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 trans } txs := []sdk.Msg{ chains[src].UpdateClient(updateHeader), - chains[src].PathEnd.ChanCloseConfirm(dstChanState, chains[src].MustGetAddress()), + chains[src].ChanCloseConfirm(dstChanState, chains[src].MustGetAddress()), } return sendAndPrint(txs, chains[src], cmd) diff --git a/relayer/channel-tx.go b/relayer/channel-tx.go index 375feeaad..619335de3 100644 --- a/relayer/channel-tx.go +++ b/relayer/channel-tx.go @@ -196,7 +196,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro } msgs = []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.PathEnd.ChanConfirm(dstChan, src.MustGetAddress()), + src.ChanConfirm(dstChan, src.MustGetAddress()), } last = true @@ -212,7 +212,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro } msgs = []sdk.Msg{ dst.UpdateClient(srcUpdateHeader), - dst.PathEnd.ChanConfirm(srcChan, dst.MustGetAddress()), + dst.ChanConfirm(srcChan, dst.MustGetAddress()), } last = true @@ -243,7 +243,7 @@ func InitializeChannel(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmclie // cosntruct OpenInit message to be submitted on source chain msgs := []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.PathEnd.ChanInit(dst.PathEnd, src.MustGetAddress()), + src.ChanInit(dst.PathEnd, src.MustGetAddress()), } res, success, err := src.SendMsgs(msgs) @@ -413,7 +413,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Src = append(out.Src, c.UpdateClient(dstUpdateHeader), - c.PathEnd.ChanCloseInit(c.MustGetAddress()), + c.ChanCloseInit(c.MustGetAddress()), ) } else if dstChan.Channel.State != chantypes.UNINITIALIZED { if dst.debug { @@ -421,7 +421,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Dst = append(out.Dst, dst.UpdateClient(srcUpdateHeader), - dst.PathEnd.ChanCloseInit(dst.MustGetAddress()), + dst.ChanCloseInit(dst.MustGetAddress()), ) } @@ -433,7 +433,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Dst = append(out.Dst, dst.UpdateClient(srcUpdateHeader), - dst.PathEnd.ChanCloseConfirm(srcChan, dst.MustGetAddress()), + dst.ChanCloseConfirm(srcChan, dst.MustGetAddress()), ) out.Last = true } @@ -446,7 +446,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Src = append(out.Src, c.UpdateClient(dstUpdateHeader), - c.PathEnd.ChanCloseConfirm(dstChan, c.MustGetAddress()), + c.ChanCloseConfirm(dstChan, c.MustGetAddress()), ) out.Last = true } diff --git a/relayer/client-tx.go b/relayer/client-tx.go index 632522d2e..fc1c6f165 100644 --- a/relayer/client-tx.go +++ b/relayer/client-tx.go @@ -33,7 +33,7 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) { return modified, err } msgs := []sdk.Msg{ - c.PathEnd.CreateClient( + c.CreateClient( dstH, dst.GetTrustingPeriod(), ubdPeriod, @@ -75,7 +75,7 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) { return modified, err } msgs := []sdk.Msg{ - dst.PathEnd.CreateClient( + dst.CreateClient( srcH, c.GetTrustingPeriod(), ubdPeriod, diff --git a/relayer/connection-tx.go b/relayer/connection-tx.go index 0ed8428b7..29fd8310b 100644 --- a/relayer/connection-tx.go +++ b/relayer/connection-tx.go @@ -194,7 +194,7 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e } msgs = []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.PathEnd.ConnConfirm(dstConn, src.MustGetAddress()), + src.ConnConfirm(dstConn, src.MustGetAddress()), } _, success, err = src.SendMsgs(msgs) if !success { @@ -210,7 +210,7 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e } msgs = []sdk.Msg{ dst.UpdateClient(srcUpdateHeader), - dst.PathEnd.ConnConfirm(srcConn, dst.MustGetAddress()), + dst.ConnConfirm(srcConn, dst.MustGetAddress()), } last = true _, success, err = dst.SendMsgs(msgs) @@ -240,7 +240,7 @@ func InitializeConnection(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmc // cosntruct OpenInit message to be submitted on source chain msgs := []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.PathEnd.ConnInit(dst.PathEnd, src.MustGetAddress()), + src.ConnInit(dst.PathEnd, src.MustGetAddress()), } res, success, err := src.SendMsgs(msgs) diff --git a/relayer/msgs.go b/relayer/msgs.go index a8008499c..ecc7f3fe3 100644 --- a/relayer/msgs.go +++ b/relayer/msgs.go @@ -1,12 +1,17 @@ package relayer import ( + "time" + 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" + 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" + light "github.com/tendermint/tendermint/light" ) // NOTE: we explicitly call 'MustGetAddress' before 'NewMsg...' @@ -156,3 +161,107 @@ func (c *Chain) MsgTransfer(dst *PathEnd, amount sdk.Coin, dstAddr string, timeoutTimestamp, ) } + +// CreateClient creates an sdk.Msg to update the client on src with consensus state from dst +func (c *Chain) CreateClient( + dstHeader *tmclient.Header, + trustingPeriod, unbondingPeriod time.Duration, + signer sdk.AccAddress) sdk.Msg { + if err := dstHeader.ValidateBasic(); err != nil { + panic(err) + } + + // Blank Client State + clientState := tmclient.NewClientState( + dstHeader.GetHeader().GetChainID(), + tmclient.NewFractionFromTm(light.DefaultTrustLevel), + trustingPeriod, + unbondingPeriod, + time.Minute*10, + dstHeader.GetHeight().(clienttypes.Height), + commitmenttypes.GetSDKSpecs(), + defaultUpgradePath, + false, + false, + ) + + msg, err := clienttypes.NewMsgCreateClient( + clientState, + dstHeader.ConsensusState(), + signer, + ) + + if err != nil { + panic(err) + } + if err = msg.ValidateBasic(); err != nil { + panic(err) + } + return msg +} + +// ConnInit creates a MsgConnectionOpenInit +func (c *Chain) ConnInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Msg { + var version *conntypes.Version + return conntypes.NewMsgConnectionOpenInit( + c.PathEnd.ClientID, + counterparty.ClientID, + defaultChainPrefix, + version, + defaultDelayPeriod, + signer, + ) +} + +// ConnConfirm creates a MsgConnectionOpenConfirm +func (c *Chain) ConnConfirm(counterpartyConnState *conntypes.QueryConnectionResponse, signer sdk.AccAddress) sdk.Msg { + return conntypes.NewMsgConnectionOpenConfirm( + c.PathEnd.ConnectionID, + counterpartyConnState.Proof, + counterpartyConnState.ProofHeight, + signer, + ) +} + +// ChanInit creates a MsgChannelOpenInit +func (c *Chain) ChanInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelOpenInit( + c.PathEnd.PortID, + c.PathEnd.Version, + c.PathEnd.GetOrder(), + []string{c.PathEnd.ConnectionID}, + counterparty.PortID, + signer, + ) +} + +// ChanConfirm creates a MsgChannelOpenConfirm +func (c *Chain) ChanConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelOpenConfirm( + c.PathEnd.PortID, + c.PathEnd.ChannelID, + dstChanState.Proof, + dstChanState.ProofHeight, + signer, + ) +} + +// ChanCloseInit creates a MsgChannelCloseInit +func (c *Chain) ChanCloseInit(signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelCloseInit( + c.PathEnd.PortID, + c.PathEnd.ChannelID, + signer, + ) +} + +// ChanCloseConfirm creates a MsgChannelCloseConfirm +func (c *Chain) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelCloseConfirm( + c.PathEnd.PortID, + c.PathEnd.ChannelID, + dstChanState.Proof, + dstChanState.ProofHeight, + signer, + ) +} diff --git a/relayer/pathEnd.go b/relayer/pathEnd.go index 9143c0978..3193a95a5 100644 --- a/relayer/pathEnd.go +++ b/relayer/pathEnd.go @@ -2,16 +2,12 @@ package relayer import ( "strings" - "time" 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" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types" - 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 @@ -69,110 +65,6 @@ func UnmarshalChain(pe PathEnd) *Chain { return nil } -// CreateClient creates an sdk.Msg to update the client on src with consensus state from dst -func (pe *PathEnd) CreateClient( - dstHeader *tmclient.Header, - trustingPeriod, unbondingPeriod time.Duration, - signer sdk.AccAddress) sdk.Msg { - if err := dstHeader.ValidateBasic(); err != nil { - panic(err) - } - - // Blank Client State - clientState := tmclient.NewClientState( - dstHeader.GetHeader().GetChainID(), - tmclient.NewFractionFromTm(light.DefaultTrustLevel), - trustingPeriod, - unbondingPeriod, - time.Minute*10, - dstHeader.GetHeight().(clienttypes.Height), - commitmenttypes.GetSDKSpecs(), - defaultUpgradePath, - false, - false, - ) - - msg, err := clienttypes.NewMsgCreateClient( - clientState, - dstHeader.ConsensusState(), - signer, - ) - - if err != nil { - panic(err) - } - if err = msg.ValidateBasic(); err != nil { - panic(err) - } - return msg -} - -// ConnInit creates a MsgConnectionOpenInit -func (pe *PathEnd) ConnInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Msg { - var version *conntypes.Version - return conntypes.NewMsgConnectionOpenInit( - pe.ClientID, - counterparty.ClientID, - defaultChainPrefix, - version, - defaultDelayPeriod, - signer, - ) -} - -// ConnConfirm creates a MsgConnectionOpenConfirm -func (pe *PathEnd) ConnConfirm(counterpartyConnState *conntypes.QueryConnectionResponse, signer sdk.AccAddress) sdk.Msg { - return conntypes.NewMsgConnectionOpenConfirm( - pe.ConnectionID, - counterpartyConnState.Proof, - counterpartyConnState.ProofHeight, - signer, - ) -} - -// ChanInit creates a MsgChannelOpenInit -func (pe *PathEnd) ChanInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Msg { - return chantypes.NewMsgChannelOpenInit( - pe.PortID, - pe.Version, - pe.GetOrder(), - []string{pe.ConnectionID}, - counterparty.PortID, - signer, - ) -} - -// ChanConfirm creates a MsgChannelOpenConfirm -func (pe *PathEnd) ChanConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { - return chantypes.NewMsgChannelOpenConfirm( - pe.PortID, - pe.ChannelID, - dstChanState.Proof, - dstChanState.ProofHeight, - signer, - ) -} - -// ChanCloseInit creates a MsgChannelCloseInit -func (pe *PathEnd) ChanCloseInit(signer sdk.AccAddress) sdk.Msg { - return chantypes.NewMsgChannelCloseInit( - pe.PortID, - pe.ChannelID, - signer, - ) -} - -// ChanCloseConfirm creates a MsgChannelCloseConfirm -func (pe *PathEnd) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { - return chantypes.NewMsgChannelCloseConfirm( - pe.PortID, - pe.ChannelID, - dstChanState.Proof, - dstChanState.ProofHeight, - signer, - ) -} - // 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 { From 6e49b8798442b63a04bd3ca7f81041cd01ac1f93 Mon Sep 17 00:00:00 2001 From: PrathyushaLakkireddy Date: Tue, 19 Jan 2021 12:04:36 +0530 Subject: [PATCH 2/4] removed todo from pathEnd.go --- relayer/pathEnd.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/relayer/pathEnd.go b/relayer/pathEnd.go index 3193a95a5..fb2ba8fc3 100644 --- a/relayer/pathEnd.go +++ b/relayer/pathEnd.go @@ -10,10 +10,6 @@ import ( commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types" ) -// 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) From f5ca796e6e2caf5b17489e675b745f15de984e06 Mon Sep 17 00:00:00 2001 From: PrathyushaLakkireddy Date: Wed, 20 Jan 2021 19:22:31 +0530 Subject: [PATCH 3/4] Remove signer as a passed in parameter and replaced it's usage with c.MustGetAddress() --- cmd/raw.go | 14 +++++++------- relayer/channel-tx.go | 14 +++++++------- relayer/client-tx.go | 2 -- relayer/connection-tx.go | 6 +++--- relayer/msgs.go | 29 ++++++++++++++--------------- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/cmd/raw.go b/cmd/raw.go index 595f04e08..58c32ae54 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -108,7 +108,7 @@ $ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)), } return sendAndPrint([]sdk.Msg{chains[src].CreateClient(dstHeader, - chains[dst].GetTrustingPeriod(), ubdPeriod, chains[src].MustGetAddress())}, + chains[dst].GetTrustingPeriod(), ubdPeriod)}, chains[src], cmd) }, } @@ -138,7 +138,7 @@ $ %s tx raw conn-init ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2`, return err } - return sendAndPrint([]sdk.Msg{chains[src].ConnInit(chains[dst].PathEnd, chains[src].MustGetAddress())}, + return sendAndPrint([]sdk.Msg{chains[src].ConnInit(chains[dst].PathEnd)}, chains[src], cmd) }, } @@ -282,7 +282,7 @@ $ %s tx raw conn-confirm ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn return err } txs := []sdk.Msg{ - chains[src].ConnConfirm(dstState, chains[src].MustGetAddress()), + chains[src].ConnConfirm(dstState), chains[src].UpdateClient(updateHeader), } @@ -358,7 +358,7 @@ $ %s tx raw chan-init ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2 i return err } - return sendAndPrint([]sdk.Msg{chains[src].ChanInit(chains[dst].PathEnd, chains[src].MustGetAddress())}, + return sendAndPrint([]sdk.Msg{chains[src].ChanInit(chains[dst].PathEnd)}, chains[src], cmd) }, } @@ -506,7 +506,7 @@ $ %s tx raw chan-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer tr } txs := []sdk.Msg{ chains[src].UpdateClient(updateHeader), - chains[src].ChanConfirm(dstChanState, chains[src].MustGetAddress()), + chains[src].ChanConfirm(dstChanState), } return sendAndPrint(txs, chains[src], cmd) @@ -575,7 +575,7 @@ $ %s tx raw chan-close-init ibc-0 ibcchan1 transfer`, appName, appName)), return err } - return sendAndPrint([]sdk.Msg{src.ChanCloseInit(src.MustGetAddress())}, src, cmd) + return sendAndPrint([]sdk.Msg{src.ChanCloseInit()}, src, cmd) }, } return cmd @@ -620,7 +620,7 @@ $ %s tx raw chan-close-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 trans } txs := []sdk.Msg{ chains[src].UpdateClient(updateHeader), - chains[src].ChanCloseConfirm(dstChanState, chains[src].MustGetAddress()), + chains[src].ChanCloseConfirm(dstChanState), } return sendAndPrint(txs, chains[src], cmd) diff --git a/relayer/channel-tx.go b/relayer/channel-tx.go index 619335de3..c6eb166f0 100644 --- a/relayer/channel-tx.go +++ b/relayer/channel-tx.go @@ -196,7 +196,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro } msgs = []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.ChanConfirm(dstChan, src.MustGetAddress()), + src.ChanConfirm(dstChan), } last = true @@ -212,7 +212,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro } msgs = []sdk.Msg{ dst.UpdateClient(srcUpdateHeader), - dst.ChanConfirm(srcChan, dst.MustGetAddress()), + dst.ChanConfirm(srcChan), } last = true @@ -243,7 +243,7 @@ func InitializeChannel(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmclie // cosntruct OpenInit message to be submitted on source chain msgs := []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.ChanInit(dst.PathEnd, src.MustGetAddress()), + src.ChanInit(dst.PathEnd), } res, success, err := src.SendMsgs(msgs) @@ -413,7 +413,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Src = append(out.Src, c.UpdateClient(dstUpdateHeader), - c.ChanCloseInit(c.MustGetAddress()), + c.ChanCloseInit(), ) } else if dstChan.Channel.State != chantypes.UNINITIALIZED { if dst.debug { @@ -421,7 +421,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Dst = append(out.Dst, dst.UpdateClient(srcUpdateHeader), - dst.ChanCloseInit(dst.MustGetAddress()), + dst.ChanCloseInit(), ) } @@ -433,7 +433,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Dst = append(out.Dst, dst.UpdateClient(srcUpdateHeader), - dst.ChanCloseConfirm(srcChan, dst.MustGetAddress()), + dst.ChanCloseConfirm(srcChan), ) out.Last = true } @@ -446,7 +446,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } out.Src = append(out.Src, c.UpdateClient(dstUpdateHeader), - c.ChanCloseConfirm(dstChan, c.MustGetAddress()), + c.ChanCloseConfirm(dstChan), ) out.Last = true } diff --git a/relayer/client-tx.go b/relayer/client-tx.go index fc1c6f165..6781bdba5 100644 --- a/relayer/client-tx.go +++ b/relayer/client-tx.go @@ -37,7 +37,6 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) { dstH, dst.GetTrustingPeriod(), ubdPeriod, - c.MustGetAddress(), ), } res, success, err := c.SendMsgs(msgs) @@ -79,7 +78,6 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) { srcH, c.GetTrustingPeriod(), ubdPeriod, - dst.MustGetAddress(), ), } res, success, err := dst.SendMsgs(msgs) diff --git a/relayer/connection-tx.go b/relayer/connection-tx.go index 29fd8310b..cef0176da 100644 --- a/relayer/connection-tx.go +++ b/relayer/connection-tx.go @@ -194,7 +194,7 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e } msgs = []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.ConnConfirm(dstConn, src.MustGetAddress()), + src.ConnConfirm(dstConn), } _, success, err = src.SendMsgs(msgs) if !success { @@ -210,7 +210,7 @@ func ExecuteConnectionStep(src, dst *Chain) (success, last, modified bool, err e } msgs = []sdk.Msg{ dst.UpdateClient(srcUpdateHeader), - dst.ConnConfirm(srcConn, dst.MustGetAddress()), + dst.ConnConfirm(srcConn), } last = true _, success, err = dst.SendMsgs(msgs) @@ -240,7 +240,7 @@ func InitializeConnection(src, dst *Chain, srcUpdateHeader, dstUpdateHeader *tmc // cosntruct OpenInit message to be submitted on source chain msgs := []sdk.Msg{ src.UpdateClient(dstUpdateHeader), - src.ConnInit(dst.PathEnd, src.MustGetAddress()), + src.ConnInit(dst.PathEnd), } res, success, err := src.SendMsgs(msgs) diff --git a/relayer/msgs.go b/relayer/msgs.go index ecc7f3fe3..fa5cb9e25 100644 --- a/relayer/msgs.go +++ b/relayer/msgs.go @@ -165,8 +165,7 @@ func (c *Chain) MsgTransfer(dst *PathEnd, amount sdk.Coin, dstAddr string, // CreateClient creates an sdk.Msg to update the client on src with consensus state from dst func (c *Chain) CreateClient( dstHeader *tmclient.Header, - trustingPeriod, unbondingPeriod time.Duration, - signer sdk.AccAddress) sdk.Msg { + trustingPeriod, unbondingPeriod time.Duration) sdk.Msg { if err := dstHeader.ValidateBasic(); err != nil { panic(err) } @@ -188,7 +187,7 @@ func (c *Chain) CreateClient( msg, err := clienttypes.NewMsgCreateClient( clientState, dstHeader.ConsensusState(), - signer, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) if err != nil { @@ -201,7 +200,7 @@ func (c *Chain) CreateClient( } // ConnInit creates a MsgConnectionOpenInit -func (c *Chain) ConnInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Msg { +func (c *Chain) ConnInit(counterparty *PathEnd) sdk.Msg { var version *conntypes.Version return conntypes.NewMsgConnectionOpenInit( c.PathEnd.ClientID, @@ -209,59 +208,59 @@ func (c *Chain) ConnInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Msg { defaultChainPrefix, version, defaultDelayPeriod, - signer, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) } // ConnConfirm creates a MsgConnectionOpenConfirm -func (c *Chain) ConnConfirm(counterpartyConnState *conntypes.QueryConnectionResponse, signer sdk.AccAddress) sdk.Msg { +func (c *Chain) ConnConfirm(counterpartyConnState *conntypes.QueryConnectionResponse) sdk.Msg { return conntypes.NewMsgConnectionOpenConfirm( c.PathEnd.ConnectionID, counterpartyConnState.Proof, counterpartyConnState.ProofHeight, - signer, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) } // ChanInit creates a MsgChannelOpenInit -func (c *Chain) ChanInit(counterparty *PathEnd, signer sdk.AccAddress) sdk.Msg { +func (c *Chain) ChanInit(counterparty *PathEnd) sdk.Msg { return chantypes.NewMsgChannelOpenInit( c.PathEnd.PortID, c.PathEnd.Version, c.PathEnd.GetOrder(), []string{c.PathEnd.ConnectionID}, counterparty.PortID, - signer, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) } // ChanConfirm creates a MsgChannelOpenConfirm -func (c *Chain) ChanConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { +func (c *Chain) ChanConfirm(dstChanState *chantypes.QueryChannelResponse) sdk.Msg { return chantypes.NewMsgChannelOpenConfirm( c.PathEnd.PortID, c.PathEnd.ChannelID, dstChanState.Proof, dstChanState.ProofHeight, - signer, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) } // ChanCloseInit creates a MsgChannelCloseInit -func (c *Chain) ChanCloseInit(signer sdk.AccAddress) sdk.Msg { +func (c *Chain) ChanCloseInit() sdk.Msg { return chantypes.NewMsgChannelCloseInit( c.PathEnd.PortID, c.PathEnd.ChannelID, - signer, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) } // ChanCloseConfirm creates a MsgChannelCloseConfirm -func (c *Chain) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { +func (c *Chain) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse) sdk.Msg { return chantypes.NewMsgChannelCloseConfirm( c.PathEnd.PortID, c.PathEnd.ChannelID, dstChanState.Proof, dstChanState.ProofHeight, - signer, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) } From 36d8828dc0299c849d284799b04e923415ff4a60 Mon Sep 17 00:00:00 2001 From: PrathyushaLakkireddy Date: Thu, 21 Jan 2021 11:58:11 +0530 Subject: [PATCH 4/4] Ordered messages --- relayer/msgs.go | 176 ++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/relayer/msgs.go b/relayer/msgs.go index fa5cb9e25..94640316d 100644 --- a/relayer/msgs.go +++ b/relayer/msgs.go @@ -24,6 +24,43 @@ import ( // file handling has been refactored. // https://github.com/cosmos/cosmos-sdk/issues/8332 +// CreateClient creates an sdk.Msg to update the client on src with consensus state from dst +func (c *Chain) CreateClient( + dstHeader *tmclient.Header, + trustingPeriod, unbondingPeriod time.Duration) sdk.Msg { + if err := dstHeader.ValidateBasic(); err != nil { + panic(err) + } + + // Blank Client State + clientState := tmclient.NewClientState( + dstHeader.GetHeader().GetChainID(), + tmclient.NewFractionFromTm(light.DefaultTrustLevel), + trustingPeriod, + unbondingPeriod, + time.Minute*10, + dstHeader.GetHeight().(clienttypes.Height), + commitmenttypes.GetSDKSpecs(), + defaultUpgradePath, + false, + false, + ) + + msg, err := clienttypes.NewMsgCreateClient( + clientState, + dstHeader.ConsensusState(), + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ) + + if err != nil { + panic(err) + } + if err = msg.ValidateBasic(); err != nil { + panic(err) + } + return msg +} + // 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 { @@ -40,6 +77,19 @@ func (c *Chain) UpdateClient(dstHeader ibcexported.Header) sdk.Msg { return msg } +// ConnInit creates a MsgConnectionOpenInit +func (c *Chain) ConnInit(counterparty *PathEnd) sdk.Msg { + var version *conntypes.Version + return conntypes.NewMsgConnectionOpenInit( + c.PathEnd.ClientID, + counterparty.ClientID, + defaultChainPrefix, + version, + defaultDelayPeriod, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ) +} + // ConnTry creates a MsgConnectionOpenTry func (c *Chain) ConnTry( counterparty *Chain, @@ -97,6 +147,28 @@ func (c *Chain) ConnAck( ), nil } +// ConnConfirm creates a MsgConnectionOpenConfirm +func (c *Chain) ConnConfirm(counterpartyConnState *conntypes.QueryConnectionResponse) sdk.Msg { + return conntypes.NewMsgConnectionOpenConfirm( + c.PathEnd.ConnectionID, + counterpartyConnState.Proof, + counterpartyConnState.ProofHeight, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ) +} + +// ChanInit creates a MsgChannelOpenInit +func (c *Chain) ChanInit(counterparty *PathEnd) sdk.Msg { + return chantypes.NewMsgChannelOpenInit( + c.PathEnd.PortID, + c.PathEnd.Version, + c.PathEnd.GetOrder(), + []string{c.PathEnd.ConnectionID}, + counterparty.PortID, + c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' + ) +} + // ChanTry creates a MsgChannelOpenTry func (c *Chain) ChanTry( counterparty *Chain, @@ -146,94 +218,6 @@ func (c *Chain) ChanAck( ), 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, - ) -} - -// CreateClient creates an sdk.Msg to update the client on src with consensus state from dst -func (c *Chain) CreateClient( - dstHeader *tmclient.Header, - trustingPeriod, unbondingPeriod time.Duration) sdk.Msg { - if err := dstHeader.ValidateBasic(); err != nil { - panic(err) - } - - // Blank Client State - clientState := tmclient.NewClientState( - dstHeader.GetHeader().GetChainID(), - tmclient.NewFractionFromTm(light.DefaultTrustLevel), - trustingPeriod, - unbondingPeriod, - time.Minute*10, - dstHeader.GetHeight().(clienttypes.Height), - commitmenttypes.GetSDKSpecs(), - defaultUpgradePath, - false, - false, - ) - - msg, err := clienttypes.NewMsgCreateClient( - clientState, - dstHeader.ConsensusState(), - c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' - ) - - if err != nil { - panic(err) - } - if err = msg.ValidateBasic(); err != nil { - panic(err) - } - return msg -} - -// ConnInit creates a MsgConnectionOpenInit -func (c *Chain) ConnInit(counterparty *PathEnd) sdk.Msg { - var version *conntypes.Version - return conntypes.NewMsgConnectionOpenInit( - c.PathEnd.ClientID, - counterparty.ClientID, - defaultChainPrefix, - version, - defaultDelayPeriod, - c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' - ) -} - -// ConnConfirm creates a MsgConnectionOpenConfirm -func (c *Chain) ConnConfirm(counterpartyConnState *conntypes.QueryConnectionResponse) sdk.Msg { - return conntypes.NewMsgConnectionOpenConfirm( - c.PathEnd.ConnectionID, - counterpartyConnState.Proof, - counterpartyConnState.ProofHeight, - c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' - ) -} - -// ChanInit creates a MsgChannelOpenInit -func (c *Chain) ChanInit(counterparty *PathEnd) sdk.Msg { - return chantypes.NewMsgChannelOpenInit( - c.PathEnd.PortID, - c.PathEnd.Version, - c.PathEnd.GetOrder(), - []string{c.PathEnd.ConnectionID}, - counterparty.PortID, - c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' - ) -} - // ChanConfirm creates a MsgChannelOpenConfirm func (c *Chain) ChanConfirm(dstChanState *chantypes.QueryChannelResponse) sdk.Msg { return chantypes.NewMsgChannelOpenConfirm( @@ -264,3 +248,19 @@ func (c *Chain) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse) s c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...' ) } + +// 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, + ) +}