Skip to content

Commit

Permalink
Avoid hitting GH rate limit and clean up logs (#1013)
Browse files Browse the repository at this point in the history
* clean up chains add

* remove word

* update Lens in mod file

* mod tidy

* mod tidy in ibctest

* handle feedback
  • Loading branch information
boojamya authored and agouin committed Nov 15, 2022
1 parent 3198e29 commit 5c6727b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 101 deletions.
151 changes: 69 additions & 82 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,105 +425,92 @@ func addChainFromURL(a *appState, chainName string, rawurl string) error {

func addChainsFromRegistry(ctx context.Context, a *appState, chains []string) error {
chainRegistry := registry.DefaultChainRegistry(a.Log)
allChains, err := chainRegistry.ListChains(ctx)
if err != nil {
return err
}
foundError := false

var existed, failed, added []string

for _, chain := range chains {
if _, ok := a.Config.Chains[chain]; ok {
a.Log.Warn(
"Chain already exists",
zap.String("chain", chain),
zap.String("source_link", chainRegistry.SourceLink()),
)
existed = append(existed, chain)
continue
}
found := false
for _, possibleChain := range allChains {
if chain == possibleChain {
found = true
}

if !found {
a.Log.Warn(
"Unable to find chain",
zap.String("chain", chain),
zap.String("source_link", chainRegistry.SourceLink()),
)
continue
}
chainInfo, err := chainRegistry.GetChain(ctx, chain)
if err != nil {
a.Log.Warn(
"Error retrieving chain",
zap.String("chain", chain),
zap.Error(err),
)
failed = append(failed, chain)
continue
}

chainInfo, err := chainRegistry.GetChain(ctx, chain)
if err != nil {
a.Log.Warn(
"Error retrieving chain",
zap.String("chain", chain),
zap.Error(err),
)
foundError = true
continue
}
chainConfig, err := chainInfo.GetChainConfig(ctx)
if err != nil {
a.Log.Warn(
"Error generating chain config",
zap.String("chain", chain),
zap.Error(err),
)
failed = append(failed, chain)
continue
}

chainConfig, err := chainInfo.GetChainConfig(ctx)
if err != nil {
a.Log.Warn(
"Error generating chain config",
zap.String("chain", chain),
zap.Error(err),
)
foundError = true
continue
}
// build the ChainProvider
pcfg := &cosmos.CosmosProviderConfig{
Key: chainConfig.Key,
ChainName: chainInfo.ChainName,
ChainID: chainConfig.ChainID,
RPCAddr: chainConfig.RPCAddr,
AccountPrefix: chainConfig.AccountPrefix,
KeyringBackend: chainConfig.KeyringBackend,
GasAdjustment: chainConfig.GasAdjustment,
GasPrices: chainConfig.GasPrices,
Debug: chainConfig.Debug,
Timeout: chainConfig.Timeout,
OutputFormat: chainConfig.OutputFormat,
SignModeStr: chainConfig.SignModeStr,
}

// build the ChainProvider
pcfg := &cosmos.CosmosProviderConfig{
Key: chainConfig.Key,
ChainName: chainInfo.ChainName,
ChainID: chainConfig.ChainID,
RPCAddr: chainConfig.RPCAddr,
AccountPrefix: chainConfig.AccountPrefix,
KeyringBackend: chainConfig.KeyringBackend,
GasAdjustment: chainConfig.GasAdjustment,
GasPrices: chainConfig.GasPrices,
Debug: chainConfig.Debug,
Timeout: chainConfig.Timeout,
OutputFormat: chainConfig.OutputFormat,
SignModeStr: chainConfig.SignModeStr,
}
prov, err := pcfg.NewProvider(
a.Log.With(zap.String("provider_type", "cosmos")),
a.HomePath, a.Debug, chainInfo.ChainName,
)
if err != nil {
a.Log.Warn(
"Failed to build ChainProvider",
zap.String("chain_id", chainConfig.ChainID),
zap.Error(err),
)
failed = append(failed, chain)
continue
}

prov, err := pcfg.NewProvider(
a.Log.With(zap.String("provider_type", "cosmos")),
a.HomePath, a.Debug, chainInfo.ChainName,
// add to config
c := relayer.NewChain(a.Log, prov, a.Debug)
if err = a.Config.AddChain(c); err != nil {
a.Log.Warn(
"Failed to add chain to config",
zap.String("chain", chain),
zap.Error(err),
)
if err != nil {
a.Log.Warn(
"Failed to build ChainProvider",
zap.String("chain_id", chainConfig.ChainID),
zap.Error(err),
)
foundError = true
continue
}
failed = append(failed, chain)
continue
}

// add to config
c := relayer.NewChain(a.Log, prov, a.Debug)
if err = a.Config.AddChain(c); err != nil {
a.Log.Warn(
"Failed to add chain to config",
zap.String("chain", chain),
zap.Error(err),
)
foundError = true
continue
}
added = append(added, chain)
// found the correct chain so move on to next chain in chains

// found the correct chain so move on to next chain in chains
break
}
}
if foundError {
return errors.New("some chain(s) failed to be added to config")
}
a.Log.Info("config update status",
zap.Any("added", added),
zap.Any("failed", failed),
zap.Any("already existed", existed),
)
return nil
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ require (
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
github.com/prometheus/client_golang v1.12.2
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.12.0
github.com/spf13/viper v1.13.0
github.com/strangelove-ventures/lens v0.5.2-0.20220902224051-3b64274cd999
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.21
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.22.0
go.uber.org/zap v1.23.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -90,7 +90,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -104,7 +104,7 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
Expand All @@ -121,7 +121,7 @@ require (
google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

Expand Down
21 changes: 10 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,8 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.0.2 h1:+jQXlF3scKIcSEKkdHzXhCTDLPFi5r1wnK6yPS+49Gw=
github.com/pelletier/go-toml/v2 v2.0.2/go.mod h1:MovirKjgVRESsAvNZlAjtFwV867yGuwRkXbG66OzopI=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
Expand Down Expand Up @@ -704,8 +704,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ=
github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI=
github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU=
github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw=
github.com/strangelove-ventures/lens v0.5.2-0.20220902224051-3b64274cd999 h1:7bswoPLTebSZP5aPkUFcv4kwknxXE5bWoM/qY5OPVDk=
github.com/strangelove-ventures/lens v0.5.2-0.20220902224051-3b64274cd999/go.mod h1:16K7X0BqE6WJOxdq/Q6WCGMGO7iUVmB6BI1wN7nq2Tg=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand All @@ -722,12 +722,11 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.4.0 h1:yAzM1+SmVcz5R4tXGsNMu1jUl2aOJXoiWUCEwwnGrvs=
github.com/subosito/gotenv v1.4.0/go.mod h1:mZd6rFysKEcUhUHXJk0C/08wAgyDBFuwEYL7vWWGaGo=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
Expand Down Expand Up @@ -796,8 +795,8 @@ go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95a
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.22.0 h1:Zcye5DUgBloQ9BaT4qc9BnjOFog5TvBSAGkJ3Nf70c0=
go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U=
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -1206,8 +1205,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI=
gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
Expand Down
2 changes: 1 addition & 1 deletion ibctest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/strangelove-ventures/ibctest/v3 v3.0.0-20221114184853-4ff8042c35cc
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.21
go.uber.org/zap v1.22.0
go.uber.org/zap v1.23.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
)

Expand Down
4 changes: 2 additions & 2 deletions ibctest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,8 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.22.0 h1:Zcye5DUgBloQ9BaT4qc9BnjOFog5TvBSAGkJ3Nf70c0=
go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U=
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down

0 comments on commit 5c6727b

Please sign in to comment.