Skip to content

Commit

Permalink
refactor update message construction (#431)
Browse files Browse the repository at this point in the history
* refactor connection handshake update messages

* refactor channel update msg handling

* fix chain id for timeout

* fix build

* refactor state based relaying (fixes update client bug on retries) (#435)

* bump sdk version to v0.41.3 (#430)

* bump sdk version

* bump SDK to v0.41.3

* inital work for refactoring state based relaying

* Modify relayPacketFromSequence

* update tendermint client to not prune light blocks (#437)

* Address comments and fix lint issues

* Fix lint issues

* Remove onRtyErr (lint issue)

* typo fix (#438)

* disable tm pruning (#441)

* update release naming (#442)

* Implement swagger docs and fix path validation (#434)

* Add swagger setup

* Add some routes docs and swagger ui

* Add few more route docs

* Add swagger docs for remaining routes

* Fix golint issues

* Fix unused lint issues

* check chain-id in AddChain

* add a light client database lock (#447)

Add a lock to prevent multiple processes from attempting to access the light client database at the same time. This typically resulted in unnecessary errors or even panics

* Close database connection even if second error triggers (#449)

Co-authored-by: Mark <[email protected]>

* address comments

Co-authored-by: akhilkumarpilli <[email protected]>
Co-authored-by: Afanti <[email protected]>
Co-authored-by: Akhil Kumar P <[email protected]>
Co-authored-by: Mark | Microtick <[email protected]>
Co-authored-by: Mark <[email protected]>

Co-authored-by: akhilkumarpilli <[email protected]>
Co-authored-by: Afanti <[email protected]>
Co-authored-by: Akhil Kumar P <[email protected]>
Co-authored-by: Mark | Microtick <[email protected]>
Co-authored-by: Mark <[email protected]>
  • Loading branch information
6 people authored Mar 22, 2021
1 parent b10766c commit 30b7ce5
Show file tree
Hide file tree
Showing 6 changed files with 401 additions and 286 deletions.
100 changes: 24 additions & 76 deletions cmd/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ $ %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)},
msgs, err := chains[src].ConnInit(chains[dst])
if err != nil {
return err
}

return sendAndPrint(msgs,
chains[src], cmd)
},
}
Expand Down Expand Up @@ -182,22 +187,12 @@ $ %s tx raw conn-try ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2`,
return err
}

updateMsg, err := chains[src].UpdateClient(chains[dst])
if err != nil {
return err
}

openTry, err := chains[src].ConnTry(chains[dst])
msgs, err := chains[src].ConnTry(chains[dst])
if err != nil {
return err
}

txs := []sdk.Msg{
updateMsg,
openTry,
}

return sendAndPrint(txs, chains[src], cmd)
return sendAndPrint(msgs, chains[src], cmd)
},
}
return cmd
Expand Down Expand Up @@ -226,22 +221,12 @@ $ %s tx raw conn-ack ibc-0 ibc-1 ibconeclient ibczeroclient ibcconn1 ibcconn2`,
return err
}

updateMsg, err := chains[src].UpdateClient(chains[dst])
msgs, err := chains[src].ConnAck(chains[dst])
if err != nil {
return err
}

openAck, err := chains[src].ConnAck(chains[dst])
if err != nil {
return err
}

txs := []sdk.Msg{
updateMsg,
openAck,
}

return sendAndPrint(txs, chains[src], cmd)
return sendAndPrint(msgs, chains[src], cmd)
},
}
return cmd
Expand Down Expand Up @@ -270,24 +255,12 @@ $ %s tx raw conn-confirm ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn
return err
}

updateMsg, err := chains[src].UpdateClient(chains[dst])
msgs, err := chains[src].ConnConfirm(chains[dst])
if err != nil {
return err
}

// NOTE: We query connection at height - 1 because of the way tendermint returns
// proofs the commit for height n is contained in the header of height n + 1
dstState, err := chains[dst].QueryConnection(int64(chains[dst].MustGetLatestLightHeight()) - 1)
if err != nil {
return err
}

txs := []sdk.Msg{
updateMsg,
chains[src].ConnConfirm(dstState),
}

return sendAndPrint(txs, chains[src], cmd)
return sendAndPrint(msgs, chains[src], cmd)
},
}
return cmd
Expand Down Expand Up @@ -360,7 +333,12 @@ ibcconn1 ibcconn2 ibcchan1 ibcchan2 transfer transfer ordered`, appName)),
return err
}

return sendAndPrint([]sdk.Msg{chains[src].ChanInit(chains[dst].PathEnd)},
msgs, err := chains[src].ChanInit(chains[dst])
if err != nil {
return err
}

return sendAndPrint(msgs,
chains[src], cmd)
},
}
Expand Down Expand Up @@ -391,22 +369,12 @@ $ %s tx raw chan-try ibc-0 ibc-1 ibczeroclient ibcconn0 ibcchan1 ibcchan2 transf
return err
}

updateMsg, err := chains[src].UpdateClient(chains[dst])
msgs, err := chains[src].ChanTry(chains[dst])
if err != nil {
return err
}

openTry, err := chains[src].ChanTry(chains[dst])
if err != nil {
return err
}

txs := []sdk.Msg{
updateMsg,
openTry,
}

return sendAndPrint(txs, chains[src], cmd)
return sendAndPrint(msgs, chains[src], cmd)
},
}
return cmd
Expand Down Expand Up @@ -437,22 +405,12 @@ $ %s tx raw chan-ack ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer transf
return err
}

updateMsg, err := chains[src].UpdateClient(chains[dst])
if err != nil {
return err
}

openAck, err := chains[src].ChanAck(chains[dst])
msgs, err := chains[src].ChanAck(chains[dst])
if err != nil {
return err
}

txs := []sdk.Msg{
updateMsg,
openAck,
}

return sendAndPrint(txs, chains[src], cmd)
return sendAndPrint(msgs, chains[src], cmd)
},
}
return cmd
Expand Down Expand Up @@ -482,22 +440,12 @@ $ %s tx raw chan-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer tr
return err
}

updateMsg, err := chains[src].UpdateClient(chains[dst])
msgs, err := chains[src].ChanConfirm(chains[dst])
if err != nil {
return err
}

dstChanState, err := chains[dst].QueryChannel(int64(chains[dst].MustGetLatestLightHeight()) - 1)
if err != nil {
return err
}

txs := []sdk.Msg{
updateMsg,
chains[src].ChanConfirm(dstChanState),
}

return sendAndPrint(txs, chains[src], cmd)
return sendAndPrint(msgs, chains[src], cmd)
},
}
return cmd
Expand Down
79 changes: 21 additions & 58 deletions relayer/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
)

Expand Down Expand Up @@ -79,26 +78,14 @@ func (c *Chain) CreateOpenChannels(dst *Chain, maxRetries uint64, to time.Durati
// file. The booleans return indicate if the message was successfully
// executed and if this was the last handshake step.
func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err error) {
// variables needed to determine the current handshake step
var (
srcChan, dstChan *chantypes.QueryChannelResponse
msgs []sdk.Msg
)

srcUpdateMsg, err := src.UpdateClient(dst)
if err != nil {
return false, false, false, err
}

dstUpdateMsg, err := dst.UpdateClient(src)
if err != nil {
if _, _, err := UpdateLightClients(src, dst); err != nil {
return false, false, false, err
}

// if either identifier is missing, an existing channel that matches the required fields
// is chosen or a new channel is created.
if src.PathEnd.ChannelID == "" || dst.PathEnd.ChannelID == "" {
success, modified, err := InitializeChannel(src, dst, srcUpdateMsg, dstUpdateMsg)
success, modified, err := InitializeChannel(src, dst)
if err != nil {
return false, false, false, err
}
Expand All @@ -107,7 +94,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro
}

// Query Channel data from src and dst
srcChan, dstChan, err = QueryChannelPair(src, dst, int64(src.MustGetLatestLightHeight())-1,
srcChan, dstChan, err := QueryChannelPair(src, dst, int64(src.MustGetLatestLightHeight())-1,
int64(dst.MustGetLatestLightHeight()-1))
if err != nil {
return false, false, false, err
Expand All @@ -123,16 +110,11 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro
logChannelStates(src, dst, srcChan, dstChan)
}

openTry, err := src.ChanTry(dst)
msgs, err := src.ChanTry(dst)
if err != nil {
return false, false, false, err
}

msgs = []sdk.Msg{
srcUpdateMsg,
openTry,
}

_, success, err = src.SendMsgs(msgs)
if !success {
return false, false, false, err
Expand All @@ -147,16 +129,11 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro
logChannelStates(src, dst, srcChan, dstChan)
}

openAck, err := src.ChanAck(dst)
msgs, err := src.ChanAck(dst)
if err != nil {
return false, false, false, err
}

msgs = []sdk.Msg{
srcUpdateMsg,
openAck,
}

_, success, err = src.SendMsgs(msgs)
if !success {
return false, false, false, err
Expand All @@ -170,16 +147,11 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro
logChannelStates(dst, src, dstChan, srcChan)
}

openAck, err := dst.ChanAck(src)
msgs, err := dst.ChanAck(src)
if err != nil {
return false, false, false, err
}

msgs = []sdk.Msg{
dstUpdateMsg,
openAck,
}

_, success, err = dst.SendMsgs(msgs)
if !success {
return false, false, false, err
Expand All @@ -191,10 +163,11 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro
logChannelStates(src, dst, srcChan, dstChan)
}

msgs = []sdk.Msg{
srcUpdateMsg,
src.ChanConfirm(dstChan),
msgs, err := src.ChanConfirm(dst)
if err != nil {
return false, false, false, err
}

last = true

_, success, err = src.SendMsgs(msgs)
Expand All @@ -208,17 +181,18 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro
logChannelStates(dst, src, dstChan, srcChan)
}

msgs = []sdk.Msg{
dstUpdateMsg,
dst.ChanConfirm(srcChan),
msgs, err := dst.ChanConfirm(src)
if err != nil {
return false, false, false, err
}
last = true

_, success, err = dst.SendMsgs(msgs)
if !success {
return false, false, false, err
}

last = true

case srcChan.Channel.State == chantypes.OPEN && dstChan.Channel.State == chantypes.OPEN:
last = true

Expand All @@ -231,9 +205,7 @@ func ExecuteChannelStep(src, dst *Chain) (success, last, modified bool, err erro
// The identifiers set in the PathEnd's are used to determine which channel ends need to be
// initialized. The PathEnds are updated upon a successful transaction.
// NOTE: This function may need to be called twice if neither channel exists.
func InitializeChannel(
src, dst *Chain, srcUpdateMsg, dstUpdateMsg sdk.Msg,
) (success, modified bool, err error) {
func InitializeChannel(src, dst *Chain) (success, modified bool, err error) {
switch {

// OpenInit on source
Expand All @@ -246,10 +218,9 @@ func InitializeChannel(

channelID, found := FindMatchingChannel(src, dst)
if !found {
// construct OpenInit message to be submitted on source chain
msgs := []sdk.Msg{
srcUpdateMsg,
src.ChanInit(dst.PathEnd),
msgs, err := src.ChanInit(dst)
if err != nil {
return false, false, err
}

res, success, err := src.SendMsgs(msgs)
Expand Down Expand Up @@ -279,15 +250,11 @@ func InitializeChannel(
channelID, found := FindMatchingChannel(src, dst)
if !found {
// open try on source chain
openTry, err := src.ChanTry(dst)
msgs, err := src.ChanTry(dst)
if err != nil {
return false, false, err
}

msgs := []sdk.Msg{
srcUpdateMsg,
openTry,
}
res, success, err := src.SendMsgs(msgs)
if !success {
return false, false, err
Expand Down Expand Up @@ -315,15 +282,11 @@ func InitializeChannel(
channelID, found := FindMatchingChannel(dst, src)
if !found {
// open try on destination chain
openTry, err := dst.ChanTry(src)
msgs, err := dst.ChanTry(src)
if err != nil {
return false, false, err
}

msgs := []sdk.Msg{
dstUpdateMsg,
openTry,
}
res, success, err := dst.SendMsgs(msgs)
if !success {
return false, false, err
Expand Down
Loading

0 comments on commit 30b7ce5

Please sign in to comment.