Skip to content

Commit 5bb5a67

Browse files
jtieriboojamyajackzampolin
authored
Merge PR cosmos#569: Refactor & improve new path generation in the relayer
* use chain registry + formatting fixes * remove fetch commands and add chain and path fetching behind chains and paths cmd trees * actually fetch a chains assetlist.json file from chain registry * fix quick-start guide * small fixes to README.md * more small fixes to README.md * fix tabs in README.md * fix tabs in README.md * undo last changes * minor changes to readme * added ds_store * Merge PR cosmos#564: Add command for creating a new blank path * add command to create a new blank path in the config * add retries & cleanup CreateClients * use tagged lens version * add logging of txs back into relayer * add CreateClient & RelayMsg commands. Fix race conditions * make ibc update headers query work in parallel + small fixes * testing with updated lens repo * add better retries to connection creation * add better retries to client creation * add better retries to channel creation * fix lgtm bot warnings * fix broken tests * remove -race flag from tests * fix broken bash script testing environment * remove double import statement Co-authored-by: Dan Kanefsky <[email protected]> Co-authored-by: Jack Zampolin <[email protected]>
1 parent 32b2af9 commit 5bb5a67

14 files changed

+779
-148
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test-akash:
6969
@go test -mod=readonly -v -run TestAkashToGaiaRelaying ./test/...
7070

7171
test-short:
72-
@go test -mod=readonly -v -run TestOsmoToGaiaRelaying ./test/...
72+
@go test -mod=readonly -v -run TestOsmoToGaiaRelaying ./test/...
7373

7474
coverage:
7575
@echo "viewing test coverage..."

cmd/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ func initConfig(cmd *cobra.Command) error {
618618
for _, pcfg := range cfgWrapper.ProviderConfigs {
619619
prov, err := pcfg.Value.(provider.ProviderConfig).NewProvider(homePath, debug)
620620
if err != nil {
621-
return fmt.Errorf("Error while building ChainProviders. Err: %s\n", err.Error())
621+
return fmt.Errorf("Error while building ChainProviders. Err: %w\n", err)
622622
}
623623

624624
chain := &relayer.Chain{ChainProvider: prov}

cmd/tx.go

+139-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package cmd
22

33
import (
44
"fmt"
5+
"strconv"
56
"strings"
67
"time"
78

9+
"github.com/avast/retry-go"
810
"github.com/cosmos/cosmos-sdk/client/flags"
911
sdk "github.com/cosmos/cosmos-sdk/types"
12+
"github.com/cosmos/ibc-go/v2/modules/core/exported"
1013
"github.com/cosmos/relayer/relayer"
1114
"github.com/spf13/cobra"
1215
)
@@ -29,16 +32,19 @@ Most of these commands take a [path] argument. Make sure:
2932
linkCmd(),
3033
linkThenStartCmd(),
3134
relayMsgsCmd(),
35+
relayMsgCmd(),
3236
relayAcksCmd(),
3337
xfersend(),
3438
flags.LineBreak,
3539
createClientsCmd(),
40+
createClientCmd(),
3641
updateClientsCmd(),
3742
upgradeClientsCmd(),
3843
//upgradeChainCmd(),
3944
createConnectionCmd(),
4045
closeChannelCmd(),
4146
flags.LineBreak,
47+
4248
//sendCmd(),
4349
)
4450

@@ -146,6 +152,95 @@ func createClientsCmd() *cobra.Command {
146152
return overrideFlag(clientParameterFlags(cmd))
147153
}
148154

155+
func createClientCmd() *cobra.Command {
156+
cmd := &cobra.Command{
157+
Use: "client [src-chain-id] [dst-chain-id] [path-name]",
158+
Short: "create a client between two configured chains with a configured path",
159+
Long: "Creates a working ibc client for chain configured on each end of the" +
160+
" path by querying headers from each chain and then sending the corresponding create-client messages",
161+
Args: cobra.ExactArgs(3),
162+
Example: strings.TrimSpace(fmt.Sprintf(`$ %s transact clients demo-path`, appName)),
163+
RunE: func(cmd *cobra.Command, args []string) error {
164+
allowUpdateAfterExpiry, err := cmd.Flags().GetBool(flagUpdateAfterExpiry)
165+
if err != nil {
166+
return err
167+
}
168+
169+
allowUpdateAfterMisbehaviour, err := cmd.Flags().GetBool(flagUpdateAfterMisbehaviour)
170+
if err != nil {
171+
return err
172+
}
173+
174+
override, err := cmd.Flags().GetBool(flagOverride)
175+
if err != nil {
176+
return err
177+
}
178+
179+
src := args[0]
180+
dst := args[1]
181+
c, err := config.Chains.Gets(src, dst)
182+
if err != nil {
183+
return err
184+
}
185+
186+
pathName := args[2]
187+
path, err := config.Paths.Get(pathName)
188+
if err != nil {
189+
return err
190+
}
191+
192+
c[src].PathEnd = path.End(c[src].ChainID())
193+
c[dst].PathEnd = path.End(c[dst].ChainID())
194+
195+
// ensure that keys exist
196+
if exists := c[src].ChainProvider.KeyExists(c[src].ChainProvider.Key()); !exists {
197+
return fmt.Errorf("key %s not found on chain %s \n", c[src].ChainProvider.Key(), c[src].ChainID())
198+
}
199+
if exists := c[dst].ChainProvider.KeyExists(c[dst].ChainProvider.Key()); !exists {
200+
return fmt.Errorf("key %s not found on chain %s \n", c[dst].ChainProvider.Key(), c[dst].ChainID())
201+
}
202+
203+
// Query the latest heights on src and dst and retry if the query fails
204+
var srch, dsth int64
205+
if err = retry.Do(func() error {
206+
srch, dsth, err = relayer.QueryLatestHeights(c[src], c[dst])
207+
if srch == 0 || dsth == 0 || err != nil {
208+
return fmt.Errorf("failed to query latest heights. Err: %w", err)
209+
}
210+
return err
211+
}, relayer.RtyAtt, relayer.RtyDel, relayer.RtyErr); err != nil {
212+
return err
213+
}
214+
215+
// Query the light signed headers for src & dst at the heights srch & dsth, retry if the query fails
216+
var srcUpdateHeader, dstUpdateHeader exported.Header
217+
if err = retry.Do(func() error {
218+
srcUpdateHeader, dstUpdateHeader, err = relayer.GetLightSignedHeadersAtHeights(c[src], c[dst], srch, dsth)
219+
if err != nil {
220+
return fmt.Errorf("failed to query light signed headers. Err: %w", err)
221+
}
222+
return err
223+
}, relayer.RtyAtt, relayer.RtyDel, relayer.RtyErr, retry.OnRetry(func(n uint, err error) {
224+
c[src].LogRetryGetLightSignedHeader(n, err)
225+
srch, dsth, _ = relayer.QueryLatestHeights(c[src], c[dst])
226+
})); err != nil {
227+
return err
228+
}
229+
230+
modified, err := relayer.CreateClient(c[src], c[dst], srcUpdateHeader, dstUpdateHeader, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour, override)
231+
if modified {
232+
if err = overWriteConfig(config); err != nil {
233+
return err
234+
}
235+
}
236+
237+
return nil
238+
},
239+
}
240+
241+
return overrideFlag(clientParameterFlags(cmd))
242+
}
243+
149244
func updateClientsCmd() *cobra.Command {
150245
cmd := &cobra.Command{
151246
Use: "update-clients [path-name]",
@@ -407,7 +502,7 @@ $ %s tx connect demo-path`,
407502
}
408503

409504
// create channel if it isn't already created
410-
modified, err = c[src].CreateOpenChannels(c[dst], 3, to)
505+
modified, err = c[src].CreateOpenChannels(c[dst], retries, to)
411506
if modified {
412507
if err := overWriteConfig(config); err != nil {
413508
return err
@@ -452,6 +547,49 @@ $ %s tx link-then-start demo-path --timeout 5s`, appName, appName)),
452547
return overrideFlag(clientParameterFlags(strategyFlag(retryFlag(timeoutFlag(cmd)))))
453548
}
454549

550+
func relayMsgCmd() *cobra.Command {
551+
cmd := &cobra.Command{
552+
Use: "relay-packet [path-name] [seq-num]",
553+
Aliases: []string{"relay-pkt"},
554+
Short: "relay a non-relayed packet with a specific sequence number, in both directions",
555+
Args: cobra.ExactArgs(2),
556+
Example: strings.TrimSpace(fmt.Sprintf(`
557+
$ %s transact relay-packet demo-path 1
558+
$ %s tx relay-pkt demo-path 1`,
559+
appName, appName,
560+
)),
561+
RunE: func(cmd *cobra.Command, args []string) error {
562+
c, src, dst, err := config.ChainsFromPath(args[0])
563+
if err != nil {
564+
return err
565+
}
566+
567+
if err = ensureKeysExist(c); err != nil {
568+
return err
569+
}
570+
571+
maxTxSize, maxMsgLength, err := GetStartOptions(cmd)
572+
if err != nil {
573+
return err
574+
}
575+
576+
seqNum, err := strconv.Atoi(args[1])
577+
if err != nil {
578+
return err
579+
}
580+
581+
sp, err := relayer.UnrelayedSequences(c[src], c[dst])
582+
if err != nil {
583+
return err
584+
}
585+
586+
return relayer.RelayPacket(c[src], c[dst], sp, maxTxSize, maxMsgLength, uint64(seqNum))
587+
},
588+
}
589+
590+
return strategyFlag(cmd)
591+
}
592+
455593
func relayMsgsCmd() *cobra.Command {
456594
cmd := &cobra.Command{
457595
Use: "relay-packets [path-name]",

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222

2323
require (
2424
github.com/pkg/errors v0.9.1
25-
github.com/strangelove-ventures/lens v0.2.1
25+
github.com/strangelove-ventures/lens v0.2.2-0.20220131192754-f2a69f2e3fd7
2626
)
2727

2828
require (

go.sum

+28
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,36 @@ github.com/strangelove-ventures/lens v0.2.1-0.20220122022854-f56147e20e5d h1:p54
11191119
github.com/strangelove-ventures/lens v0.2.1-0.20220122022854-f56147e20e5d/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
11201120
github.com/strangelove-ventures/lens v0.2.1-0.20220122023000-6e6ff07a5193 h1:LAL3EP8RfxaEf+iZqHTpq5xmlKJkcZbDQVGutAJQB58=
11211121
github.com/strangelove-ventures/lens v0.2.1-0.20220122023000-6e6ff07a5193/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1122+
github.com/strangelove-ventures/lens v0.2.1-0.20220124194236-ba2d744c75fa h1:FN4EJIaG0vRqm8VgyzDxDowBC1hcQoVLl7lj0/cGUdM=
1123+
github.com/strangelove-ventures/lens v0.2.1-0.20220124194236-ba2d744c75fa/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1124+
github.com/strangelove-ventures/lens v0.2.1-0.20220124200714-c0e835fd6bc4 h1:aw972fGIxQ13w0OxCcIb6bHQqHsxJltRn6tw5X9PbWA=
1125+
github.com/strangelove-ventures/lens v0.2.1-0.20220124200714-c0e835fd6bc4/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1126+
github.com/strangelove-ventures/lens v0.2.1-0.20220124202932-3b0f30df4040 h1:LCpKzDyqazxdkj03psIsbJZMwehQe6jq3TCOJt3tPFQ=
1127+
github.com/strangelove-ventures/lens v0.2.1-0.20220124202932-3b0f30df4040/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1128+
github.com/strangelove-ventures/lens v0.2.1-0.20220124213244-c8de769cb83d h1:t6pwRMNdjRNkLGAQRE0Mfcmq6iybf5fDGVQBBYrQRY8=
1129+
github.com/strangelove-ventures/lens v0.2.1-0.20220124213244-c8de769cb83d/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
11221130
github.com/strangelove-ventures/lens v0.2.1 h1:naP3VyQKh9b3sYHZMecBmv4sjSRC1PQzPmKyBpSF5/k=
11231131
github.com/strangelove-ventures/lens v0.2.1/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1132+
github.com/strangelove-ventures/lens v0.2.2-0.20220125165849-21346dbd1f6b h1:xzOR0OlfOxwUaRivKUMm7RWPpAONXGP3POL2kw97vVE=
1133+
github.com/strangelove-ventures/lens v0.2.2-0.20220125165849-21346dbd1f6b/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1134+
github.com/strangelove-ventures/lens v0.2.2-0.20220125221701-305c589edb5d h1:fpi5gBJD7X1yS2yfNng4SxLqQMkv9InoObtdGrgWMSw=
1135+
github.com/strangelove-ventures/lens v0.2.2-0.20220125221701-305c589edb5d/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1136+
github.com/strangelove-ventures/lens v0.2.2-0.20220125222839-86536e89a85e h1:8qvfIhGxJNdSnOZz+7L7Zp9D00z6Td8mybYNoTXpt2o=
1137+
github.com/strangelove-ventures/lens v0.2.2-0.20220125222839-86536e89a85e/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1138+
github.com/strangelove-ventures/lens v0.2.2-0.20220125223041-5729e6a4a1e1 h1:KVNioTrEOQl9NvoqCyiRL0tK3i0OOKJj1MoATB+3HxE=
1139+
github.com/strangelove-ventures/lens v0.2.2-0.20220125223041-5729e6a4a1e1/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1140+
github.com/strangelove-ventures/lens v0.2.2-0.20220127175506-c30f1b75eb70 h1:SR02xBZ6VOn3VyMXsfdaBK1OsYrE9NBGBiDKYP1TGOc=
1141+
github.com/strangelove-ventures/lens v0.2.2-0.20220127175506-c30f1b75eb70/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1142+
github.com/strangelove-ventures/lens v0.2.2-0.20220127183102-acd44266fed9 h1:3YE+qiQQ/+efRM/aRrflXZBGVz5DPwsT2QP7vhygEu4=
1143+
github.com/strangelove-ventures/lens v0.2.2-0.20220127183102-acd44266fed9/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1144+
github.com/strangelove-ventures/lens v0.2.2-0.20220127184319-56d6f5e912c6 h1:TmT0iWbayW1+inQil6oXSqGghi8ZNFx0nHToUt0fXMg=
1145+
github.com/strangelove-ventures/lens v0.2.2-0.20220127184319-56d6f5e912c6/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1146+
github.com/strangelove-ventures/lens v0.2.2-0.20220128163830-0f63f3a94653 h1:NicvNuR8QkLvuXHywj9ZLrU8eHMhebUU0+HFEusba+Q=
1147+
github.com/strangelove-ventures/lens v0.2.2-0.20220128163830-0f63f3a94653/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1148+
github.com/strangelove-ventures/lens v0.2.2-0.20220131191229-2c7ba13ad8c8 h1:M5mLJ07qLKvD70SoeSkXSw2IIxEDO2/9Zh6dHKrK/l0=
1149+
github.com/strangelove-ventures/lens v0.2.2-0.20220131191229-2c7ba13ad8c8/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
1150+
github.com/strangelove-ventures/lens v0.2.2-0.20220131192754-f2a69f2e3fd7 h1:3vwNTIh39q4Vl8tkmV02lAS37SZ6WrkKX/GlsjdVqqg=
1151+
github.com/strangelove-ventures/lens v0.2.2-0.20220131192754-f2a69f2e3fd7/go.mod h1:QSKpnL9bDirjJsMApJoHmVU3ZBujFnbXsvY9d5JG8M8=
11241152
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
11251153
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
11261154
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=

relayer/chain.go

+72-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,37 @@ package relayer
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/avast/retry-go"
76
"net/url"
87
"os"
98
"strings"
109
"time"
1110

12-
"github.com/cosmos/cosmos-sdk/simapp/params"
11+
"github.com/avast/retry-go"
12+
"github.com/cosmos/cosmos-sdk/codec"
13+
"github.com/cosmos/cosmos-sdk/std"
14+
"github.com/cosmos/cosmos-sdk/types/module"
15+
"github.com/cosmos/cosmos-sdk/x/auth"
16+
"github.com/cosmos/cosmos-sdk/x/auth/tx"
17+
authz "github.com/cosmos/cosmos-sdk/x/authz/module"
18+
"github.com/cosmos/cosmos-sdk/x/bank"
19+
"github.com/cosmos/cosmos-sdk/x/capability"
20+
"github.com/cosmos/cosmos-sdk/x/crisis"
21+
"github.com/cosmos/cosmos-sdk/x/distribution"
22+
"github.com/cosmos/cosmos-sdk/x/gov"
23+
"github.com/cosmos/cosmos-sdk/x/mint"
24+
"github.com/cosmos/cosmos-sdk/x/slashing"
25+
"github.com/cosmos/cosmos-sdk/x/staking"
26+
"github.com/cosmos/cosmos-sdk/x/upgrade"
27+
"github.com/cosmos/ibc-go/v2/modules/apps/transfer"
28+
ibc "github.com/cosmos/ibc-go/v2/modules/core"
29+
30+
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
31+
simparams "github.com/cosmos/cosmos-sdk/simapp/params"
32+
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
33+
feegrant "github.com/cosmos/cosmos-sdk/x/feegrant/module"
34+
"github.com/cosmos/cosmos-sdk/x/params"
35+
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
36+
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
1337
clienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
1438
"github.com/cosmos/relayer/relayer/provider"
1539
"github.com/gogo/protobuf/proto"
@@ -21,6 +45,26 @@ var (
2145
RtyAtt = retry.Attempts(RtyAttNum)
2246
RtyDel = retry.Delay(time.Millisecond * 400)
2347
RtyErr = retry.LastErrorOnly(true)
48+
49+
ModuleBasics = []module.AppModuleBasic{
50+
auth.AppModuleBasic{},
51+
authz.AppModuleBasic{},
52+
bank.AppModuleBasic{},
53+
capability.AppModuleBasic{},
54+
gov.NewAppModuleBasic(
55+
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
56+
),
57+
crisis.AppModuleBasic{},
58+
distribution.AppModuleBasic{},
59+
feegrant.AppModuleBasic{},
60+
mint.AppModuleBasic{},
61+
params.AppModuleBasic{},
62+
slashing.AppModuleBasic{},
63+
staking.AppModuleBasic{},
64+
upgrade.AppModuleBasic{},
65+
transfer.AppModuleBasic{},
66+
ibc.AppModuleBasic{},
67+
}
2468
)
2569

2670
// Chain represents the necessary data for connecting to and identifying a chain and its counterparties
@@ -30,13 +74,34 @@ type Chain struct {
3074
Chainid string `yaml:"chain-id" json:"chain-id"`
3175
RPCAddr string `yaml:"rpc-addr" json:"rpc-addr"`
3276

33-
PathEnd *PathEnd `yaml:"-" json:"-"`
34-
Encoding params.EncodingConfig `yaml:"-" json:"-"`
77+
PathEnd *PathEnd `yaml:"-" json:"-"`
78+
Encoding simparams.EncodingConfig `yaml:"-" json:"-"`
3579

3680
logger log.Logger
3781
debug bool
3882
}
3983

84+
func MakeCodec(moduleBasics []module.AppModuleBasic) simparams.EncodingConfig {
85+
modBasic := module.NewBasicManager(moduleBasics...)
86+
encodingConfig := MakeCodecConfig()
87+
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
88+
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
89+
modBasic.RegisterLegacyAminoCodec(encodingConfig.Amino)
90+
modBasic.RegisterInterfaces(encodingConfig.InterfaceRegistry)
91+
return encodingConfig
92+
}
93+
94+
func MakeCodecConfig() simparams.EncodingConfig {
95+
interfaceRegistry := cdctypes.NewInterfaceRegistry()
96+
marshaler := codec.NewProtoCodec(interfaceRegistry)
97+
return simparams.EncodingConfig{
98+
InterfaceRegistry: interfaceRegistry,
99+
Marshaler: marshaler,
100+
TxConfig: tx.NewTxConfig(marshaler, tx.DefaultSignModes),
101+
Amino: codec.NewLegacyAmino(),
102+
}
103+
}
104+
40105
// ValidatePaths takes two chains and validates their paths
41106
func ValidatePaths(src, dst *Chain) error {
42107
if err := src.PathEnd.ValidateFull(); err != nil {
@@ -101,6 +166,9 @@ func (c *Chain) Init(logger log.Logger, debug bool) {
101166
if c.logger == nil {
102167
c.logger = defaultChainLogger()
103168
}
169+
170+
// TODO logging/encoding needs refactored
171+
c.Encoding = MakeCodec(ModuleBasics)
104172
}
105173

106174
func defaultChainLogger() log.Logger {

0 commit comments

Comments
 (0)