Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements: clean code #32

Merged
merged 12 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validating a config is a nice feature but what if someone wants to use the exporter only for some of the paths? Maybe we should introduce a flag to validate and terminate exporter by default but give also an option to log a warning and continue if some RPCs are missing in the config. It will make an exporter useful for someone using it only for cosmos_wallet_balance metric

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to have a flag but perhaps warrants a separate PR when the need arrives? I would like to keep the scope of this PR limited to current usecase

}

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