Skip to content

Commit

Permalink
improvements: clean code (#32)
Browse files Browse the repository at this point in the history
* refactor and log improvements

* add test cases

* use existing logger instead of adding new one

* consolidate contexts

* add config validations
  • Loading branch information
shahbazn committed Dec 12, 2023
1 parent 69c7fc6 commit 96f9837
Show file tree
Hide file tree
Showing 13 changed files with 555 additions and 364 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*.so
*.dylib

# vscode
.vscode

# direnv
.envrc

# Test binary, built with `go test -c`
*.test

Expand Down
15 changes: 11 additions & 4 deletions cmd/relayer_exporter/relayer_exporter.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main

import (
"context"
"flag"
"fmt"
"net/http"
"os"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"

"github.com/archway-network/relayer_exporter/pkg/collector"
"github.com/archway-network/relayer_exporter/pkg/config"
Expand Down Expand Up @@ -45,20 +47,25 @@ func main() {

log.Info(
fmt.Sprintf(
"Getting IBC paths from %s/%s/%s on GitHub",
"Github IBC registry: %s/%s",
cfg.GitHub.Org,
cfg.GitHub.Repo,
cfg.GitHub.IBCDir,
),
zap.String("Mainnet Directory", cfg.GitHub.IBCDir),
zap.String("Testnet Directory", cfg.GitHub.TestnetsIBCDir),
)

ctx := context.Background()
// TODO: Add a feature to refresh paths at configured interval
paths, err := cfg.IBCPaths()
paths, err := cfg.IBCPaths(ctx)
if err != nil {
log.Fatal(err.Error())
}

rpcs := cfg.GetRPCsMap()
rpcs, err := cfg.GetRPCsMap(paths)
if err != nil {
log.Fatal(err.Error())
}

ibcCollector := collector.IBCCollector{
RPCs: rpcs,
Expand Down
78 changes: 48 additions & 30 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
---
github:
org: archway-network
repo: networks
dir: _IBC
testnetsDir: testnets/_IBC
rpc:
# mainnets
- chainName: archway
chainId: archway-1
url: https://rpc.mainnet.archway.io:443
- chainName: agoric
chainId: agoric-3
url: https://main.rpc.agoric.net:443
url: https://agoric.rpc.kjnodes.com:443
- chainName: axelar
chainId: axelar-dojo-1
url: https://axelar-rpc.polkachu.com:443
- chainName: axelartestnet
chainId: axelar-testnet-lisbon-3
url: https://rpc-axelar-testnet.imperator.co:443
- chainName: archwaytestnet
chainId: constantine-3
url: https://rpc.constantine.archway.tech:443
url: https://rpc-1.axelar.nodes.guru:443
- chainName: bitcanna
chainId: bitcanna-1
url: https://rpc.bitcanna.io:443
- chainName: cosmoshub
chainId: cosmoshub-4
url: https://cosmoshub-rpc.stakely.io:443
- chainName: decentr
chainId: mainnet-3
url: https://poseidon.mainnet.decentr.xyz:443
- chainName: jackal
chainId: jackal-1
url: https://jackal-rpc.polkachu.com:443
Expand All @@ -29,45 +31,61 @@ rpc:
url: https://juno-rpc.publicnode.com:443
- chainName: kujira
chainId: kaiyo-1
url: https://kujira-rpc.polkachu.com:443
url: https://kujira-rpc.publicnode.com:443
- chainName: noble
chainId: noble-1
url: https://noble-rpc.polkachu.com:443
- chainName: nois
chainId: nois-1
url: https://nois.rpc.kjnodes.com:443
- chainName: osmosistestnet
chainId: osmo-test-5
url: https://rpc.osmotest5.osmosis.zone:443
- chainName: omniflixhub
chainId: omniflixhub-1
url: https://omniflix.kingnodes.com:443
- chainName: osmosis
chainId: osmosis-1
url: https://osmosis-rpc.stakely.io:443
- chainName: quicksilver
chainId: quicksilver-2
url: https://rpc.quicksilver.zone:443
- chainName: akashtestnet
chainId: sandbox-01
url: https://rpc.sandbox-01.aksh.pw:443
- chainName: umee
chainId: umee-1
url: https://rpc-umee.mzonder.com:443
- chainName: gravitybridge
chainId: gravity-bridge-3
url: https://gravitychain.io:26657
- chainName: omniflixhub
chainId: omniflixhub-1
url: https://rpc-omniflix.mzonder.com:443
- chainName: decentr
chainId: mainnet-3
url: https://poseidon.mainnet.decentr.xyz:443
- chainName: secretnetwork
chainId: secret-4
url: https://rpc.secret.express:443
- chainName: terra2
chainId: phoenix-1
url: https://terra-rpc.stakely.io:443
- chainName: comdex
chainId: comdex-1
url: https://rpc.comdex.one:443
- chainName: neutron
chainId: neutron-1
url: https://rpc-kralum.neutron-1.neutron.org:443
- chainName: stargaze
chainId: stargaze-1
url: https://rpc.stargaze-apis.com:443

github:
org: archway-network
repo: networks
dir: _IBC
testnetsDir: testnets/_IBC
# testnets
- chainName: archwaytestnet
chainId: constantine-3
url: https://rpc.constantine.archway.tech:443
- chainName: axelartestnet
chainId: axelar-testnet-lisbon-3
url: https://axelar-testnet-rpc.qubelabs.io:443
- chainName: osmosistestnet
chainId: osmo-test-5
url: https://rpc.osmotest5.osmosis.zone:443

accounts:
- address: archway1l2al7y78500h5akvgt8exwnkpmf2zmk8ky9ht3
chainName: archwaytestnet
denom: aconst
# Foundation
- address: archway1gpyqzc0aerc85cpk2cm8ec6zkc95x5yqrakskv
chainName: archway
denom: aarch
# PhiLabs
- address: archway1ktka5q3cnsy3ar7qwj2huzz6qj9q4ys7h74l9y
chainName: archway
denom: aarch
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/caarlos0/env/v9 v9.0.0
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/cosmos/relayer/v2 v2.4.1
github.com/go-playground/validator/v10 v10.16.0
github.com/google/go-github/v55 v55.0.0
github.com/prometheus/client_golang v1.15.0
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -73,9 +74,12 @@ require (
github.com/ethereum/go-ethereum v1.10.26 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
Expand Down Expand Up @@ -116,6 +120,7 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.7.16 // indirect
Expand Down
19 changes: 13 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand All @@ -486,13 +488,17 @@ github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KE
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down Expand Up @@ -772,8 +778,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
Expand Down Expand Up @@ -1026,6 +1032,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
Expand Down
10 changes: 4 additions & 6 deletions pkg/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package chain
import (
"context"

log "github.com/archway-network/relayer_exporter/pkg/logger"
"github.com/cosmos/relayer/v2/relayer"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
"go.uber.org/zap"
)

const (
Expand All @@ -20,9 +20,7 @@ type Info struct {
Timeout string
}

func PrepChain(info Info) (*relayer.Chain, error) {
logger := zap.NewNop()

func PrepChain(ctx context.Context, info Info) (*relayer.Chain, error) {
timeout := rpcTimeout
if info.Timeout != "" {
timeout = info.Timeout
Expand All @@ -40,12 +38,12 @@ func PrepChain(info Info) (*relayer.Chain, error) {
return nil, err
}

err = provider.Init(context.Background())
err = provider.Init(ctx)
if err != nil {
return nil, err
}

chain := relayer.NewChain(logger, provider, false)
chain := relayer.NewChain(log.GetLogger(), provider, false)

err = chain.SetPath(&relayer.PathEnd{ClientID: info.ClientID})
if err != nil {
Expand Down
Loading

0 comments on commit 96f9837

Please sign in to comment.