Skip to content

Commit

Permalink
migrate messages from pathEnd.go to msgs.go (#378)
Browse files Browse the repository at this point in the history
* migrate messages from pathEnd.go to msgs.go

* removed todo from pathEnd.go

* Remove signer as a passed in parameter and replaced it's usage with c.MustGetAddress()

* Ordered messages
  • Loading branch information
PrathyushaLakkireddy authored Jan 21, 2021
1 parent 0e00510 commit 07fad96
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 120 deletions.
17 changes: 8 additions & 9 deletions cmd/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ $ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)),
false,
)

return sendAndPrint([]sdk.Msg{chains[src].PathEnd.CreateClient(
clientState, dstHeader,
chains[src].MustGetAddress())},
return sendAndPrint([]sdk.Msg{chains[src].CreateClient(
clientState, dstHeader)},
chains[src], cmd)
},
}
Expand Down Expand Up @@ -157,7 +156,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], cmd)
},
}
Expand Down Expand Up @@ -301,7 +300,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].UpdateClient(updateHeader),
}

Expand Down Expand Up @@ -377,7 +376,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], cmd)
},
}
Expand Down Expand Up @@ -525,7 +524,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),
}

return sendAndPrint(txs, chains[src], cmd)
Expand Down Expand Up @@ -594,7 +593,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, cmd)
},
}
return cmd
Expand Down Expand Up @@ -639,7 +638,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),
}

return sendAndPrint(txs, chains[src], cmd)
Expand Down
14 changes: 7 additions & 7 deletions relayer/channel-tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
last = true

Expand All @@ -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),
}
last = true

Expand Down Expand Up @@ -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),
}

res, success, err := src.SendMsgs(msgs)
Expand Down Expand Up @@ -413,15 +413,15 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) {
}
out.Src = append(out.Src,
c.UpdateClient(dstUpdateHeader),
c.PathEnd.ChanCloseInit(c.MustGetAddress()),
c.ChanCloseInit(),
)
} else if dstChan.Channel.State != chantypes.UNINITIALIZED {
if dst.debug {
logChannelStates(dst, c, dstChan, srcChan)
}
out.Dst = append(out.Dst,
dst.UpdateClient(srcUpdateHeader),
dst.PathEnd.ChanCloseInit(dst.MustGetAddress()),
dst.ChanCloseInit(),
)
}

Expand All @@ -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),
)
out.Last = true
}
Expand All @@ -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),
)
out.Last = true
}
Expand Down
6 changes: 2 additions & 4 deletions relayer/client-tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) {
clientID, found := FindMatchingClient(c, dst, clientState)
if !found {
msgs := []sdk.Msg{
c.PathEnd.CreateClient(
c.CreateClient(
clientState,
dstH,
c.MustGetAddress(),
),
}

Expand Down Expand Up @@ -123,10 +122,9 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) {
clientID, found := FindMatchingClient(dst, c, clientState)
if !found {
msgs := []sdk.Msg{
dst.PathEnd.CreateClient(
dst.CreateClient(
clientState,
srcH,
dst.MustGetAddress(),
),
}

Expand Down
6 changes: 3 additions & 3 deletions relayer/connection-tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
_, success, err = src.SendMsgs(msgs)
if !success {
Expand All @@ -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),
}
last = true
_, success, err = dst.SendMsgs(msgs)
Expand Down Expand Up @@ -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),
}

res, success, err := src.SendMsgs(msgs)
Expand Down
91 changes: 91 additions & 0 deletions relayer/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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"
ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types"
)

// NOTE: we explicitly call 'MustGetAddress' before 'NewMsg...'
Expand All @@ -19,6 +20,30 @@ 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(
clientState *tmclient.ClientState,
dstHeader *tmclient.Header) sdk.Msg {

if err := dstHeader.ValidateBasic(); err != nil {
panic(err)
}

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 {
Expand All @@ -35,6 +60,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,
Expand Down Expand Up @@ -92,6 +130,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,
Expand Down Expand Up @@ -141,6 +201,37 @@ func (c *Chain) ChanAck(
), nil
}

// ChanConfirm creates a MsgChannelOpenConfirm
func (c *Chain) ChanConfirm(dstChanState *chantypes.QueryChannelResponse) sdk.Msg {
return chantypes.NewMsgChannelOpenConfirm(
c.PathEnd.PortID,
c.PathEnd.ChannelID,
dstChanState.Proof,
dstChanState.ProofHeight,
c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...'
)
}

// ChanCloseInit creates a MsgChannelCloseInit
func (c *Chain) ChanCloseInit() sdk.Msg {
return chantypes.NewMsgChannelCloseInit(
c.PathEnd.PortID,
c.PathEnd.ChannelID,
c.MustGetAddress(), // 'MustGetAddress' must be called directly before calling 'NewMsg...'
)
}

// ChanCloseConfirm creates a MsgChannelCloseConfirm
func (c *Chain) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse) sdk.Msg {
return chantypes.NewMsgChannelCloseConfirm(
c.PathEnd.PortID,
c.PathEnd.ChannelID,
dstChanState.Proof,
dstChanState.ProofHeight,
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 {
Expand Down
Loading

0 comments on commit 07fad96

Please sign in to comment.