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

fix: Use name instead id for chain name #16

Merged
merged 1 commit into from
Oct 2, 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
55 changes: 36 additions & 19 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
---
rpc:
- chainId: archway-1
- chainName: archway
chainId: archway-1
url: https://rpc.mainnet.archway.io:443
- chainId: agoric-3
- chainName: agoric
chainId: agoric-3
url: https://main.rpc.agoric.net:443
- chainId: axelar-dojo-1
- chainName: axelar
chainId: axelar-dojo-1
url: https://axelar-rpc.polkachu.com:443
- chainId: axelar-testnet-lisbon-3
- chainName: axelartestnet
chainId: axelar-testnet-lisbon-3
url: https://rpc-axelar-testnet.imperator.co:443
- chainId: constantine-3
- chainName: archwaytestnet
chainId: constantine-3
url: https://rpc.constantine.archway.tech:443
- chainId: cosmoshub-4
- chainName: bitcanna
chainId: bitcanna-1
url: https://rpc.bitcanna.io:443
- chainName: cosmoshub
chainId: cosmoshub-4
url: https://cosmoshub-rpc.stakely.io:443
- chainId: jackal-1
- chainName: jackal
chainId: jackal-1
url: https://jackal-rpc.polkachu.com:443
- chainId: juno-1
- chainName: juno
chainId: juno-1
url: https://juno-rpc.polkachu.com:443
- chainId: kaiyo-1
- chainName: kujira
chainId: kaiyo-1
url: https://kujira-rpc.polkachu.com:443
- chainId: noble-1
- chainName: noble
chainId: noble-1
url: https://noble-rpc.polkachu.com:443
- chainId: nois-1
- chainName: nois
chainId: nois-1
url: https://nois-rpc.polkachu.com:443
- chainId: osmo-test-5
- chainName: osmosistestnet
chainId: osmo-test-5
url: https://rpc.osmotest5.osmosis.zone:443
- chainId: osmosis-1
- chainName: osmosis
chainId: osmosis-1
url: https://osmosis-rpc.stakely.io:443
- chainId: quicksilver-2
- chainName: quicksilver
chainId: quicksilver-2
url: https://rpc.quicksilver.zone:443
- chainId: sandbox-01
- chainName: akashtestnet
chainId: sandbox-01
url: https://rpc.sandbox-01.aksh.pw:443
- chainId: theta-testnet-001
url: https://rpc.sentry-01.theta-testnet.polypore.xyz:443
- chainId: umee-1
- chainName: umee
chainId: umee-1
url: https://rpc-umee.mzonder.com:443

github:
Expand All @@ -42,5 +59,5 @@ github:

accounts:
- address: archway1l2al7y78500h5akvgt8exwnkpmf2zmk8ky9ht3
chainId: constantine-3
chainName: archwaytestnet
denom: aconst
37 changes: 0 additions & 37 deletions pkg/account/account.go

This file was deleted.

16 changes: 8 additions & 8 deletions pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"
"sync"

"github.com/archway-network/relayer_exporter/pkg/account"
"github.com/archway-network/relayer_exporter/pkg/config"
"github.com/archway-network/relayer_exporter/pkg/ibc"
log "github.com/archway-network/relayer_exporter/pkg/logger"
"github.com/cosmos/relayer/v2/relayer"
Expand Down Expand Up @@ -33,13 +33,13 @@ var (
)

type IBCClientsCollector struct {
RPCs map[string]string
RPCs *map[string]config.RPC
Paths []*relayer.IBCdata
}

type WalletBalanceCollector struct {
RPCs map[string]string
Accounts []account.Account
RPCs *map[string]config.RPC
Accounts []config.Account
}

func (cc IBCClientsCollector) Describe(ch chan<- *prometheus.Desc) {
Expand Down Expand Up @@ -70,14 +70,14 @@ func (cc IBCClientsCollector) Collect(ch chan<- prometheus.Metric) {
clientExpiry,
prometheus.GaugeValue,
float64(ci.ChainAClientExpiration.Unix()),
[]string{path.Chain1.ChainName, path.Chain1.ClientID, path.Chain2.ChainName, status}...,
[]string{(*cc.RPCs)[path.Chain1.ChainName].ChainID, path.Chain1.ClientID, (*cc.RPCs)[path.Chain2.ChainName].ChainID, status}...,
)

ch <- prometheus.MustNewConstMetric(
clientExpiry,
prometheus.GaugeValue,
float64(ci.ChainBClientExpiration.Unix()),
[]string{path.Chain2.ChainName, path.Chain2.ClientID, path.Chain1.ChainName, status}...,
[]string{(*cc.RPCs)[path.Chain2.ChainName].ChainID, path.Chain2.ClientID, (*cc.RPCs)[path.Chain1.ChainName].ChainID, status}...,
)
}(p)
}
Expand All @@ -99,7 +99,7 @@ func (wb WalletBalanceCollector) Collect(ch chan<- prometheus.Metric) {
for _, a := range wb.Accounts {
wg.Add(1)

go func(account account.Account) {
go func(account config.Account) {
defer wg.Done()

balance := 0.0
Expand All @@ -119,7 +119,7 @@ func (wb WalletBalanceCollector) Collect(ch chan<- prometheus.Metric) {
walletBalance,
prometheus.GaugeValue,
balance,
[]string{account.Address, account.ChainID, account.Denom, status}...,
[]string{account.Address, (*wb.RPCs)[account.ChainName].ChainID, account.Denom, status}...,
)
}(a)
}
Expand Down
48 changes: 39 additions & 9 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,34 @@ import (
"os"
"strings"

"cosmossdk.io/math"
"github.com/caarlos0/env/v9"
"github.com/cosmos/relayer/v2/relayer"
"github.com/google/go-github/v55/github"
"gopkg.in/yaml.v3"

"github.com/archway-network/relayer_exporter/pkg/account"
"github.com/archway-network/relayer_exporter/pkg/chain"
log "github.com/archway-network/relayer_exporter/pkg/logger"
)

const ibcPathSuffix = ".json"

type Account struct {
Address string `yaml:"address"`
Denom string `yaml:"denom"`
ChainName string `yaml:"chainName"`
Balance math.Int
}

type RPC struct {
ChainID string `yaml:"chainId"`
URL string `yaml:"url"`
ChainName string `yaml:"chainName"`
ChainID string `yaml:"chainId"`
URL string `yaml:"url"`
}

type Config struct {
Accounts []account.Account `yaml:"accounts"`
RPCs []RPC `yaml:"rpc"`
Accounts []Account `yaml:"accounts"`
RPCs []RPC `yaml:"rpc"`
GitHub struct {
Org string `yaml:"org"`
Repo string `yaml:"repo"`
Expand All @@ -33,14 +42,35 @@ type Config struct {
} `yaml:"github"`
}

func (c *Config) GetRPCsMap() map[string]string {
rpcs := map[string]string{}
func (a *Account) GetBalance(rpcs *map[string]RPC) error {
chain, err := chain.PrepChain(chain.Info{
ChainID: (*rpcs)[a.ChainName].ChainID,
RPCAddr: (*rpcs)[a.ChainName].URL,
})
if err != nil {
return err
}

ctx := context.Background()

coins, err := chain.ChainProvider.QueryBalanceWithAddress(ctx, a.Address)
if err != nil {
return err
}

a.Balance = coins.AmountOf(a.Denom)

return nil
}

func (c *Config) GetRPCsMap() *map[string]RPC {
rpcs := map[string]RPC{}

for _, rpc := range c.RPCs {
rpcs[rpc.ChainID] = rpc.URL
rpcs[rpc.ChainName] = rpc
}

return rpcs
return &rpcs
}

func (c *Config) IBCPaths() ([]*relayer.IBCdata, error) {
Expand Down
26 changes: 18 additions & 8 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@ import (
func TestGetRPCsMap(t *testing.T) {
rpcs := []RPC{
{
ChainID: "archway-1",
URL: "https://rpc.mainnet.archway.io:443",
ChainName: "archway",
ChainID: "archway-1",
URL: "https://rpc.mainnet.archway.io:443",
},
{
ChainID: "constantine-3",
URL: "https://rpc.constantine.archway.tech:443",
ChainName: "archwaytestnet",
ChainID: "constantine-3",
URL: "https://rpc.constantine.archway.tech:443",
},
}

cfg := Config{RPCs: rpcs}

exp := map[string]string{
"archway-1": "https://rpc.mainnet.archway.io:443",
"constantine-3": "https://rpc.constantine.archway.tech:443",
exp := map[string]RPC{
"archway": {
ChainName: "archway",
ChainID: "archway-1",
URL: "https://rpc.mainnet.archway.io:443",
},
"archwaytestnet": {
ChainName: "archwaytestnet",
ChainID: "constantine-3",
URL: "https://rpc.constantine.archway.tech:443",
},
}

res := cfg.GetRPCsMap()

assert.Equal(t, exp, res)
assert.Equal(t, &exp, res)
}
11 changes: 6 additions & 5 deletions pkg/ibc/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/archway-network/relayer_exporter/pkg/chain"
"github.com/archway-network/relayer_exporter/pkg/config"
"github.com/cosmos/relayer/v2/relayer"
)

Expand All @@ -18,12 +19,12 @@ type ClientsInfo struct {
ChainBClientExpiration time.Time
}

func GetClientsInfo(ibc *relayer.IBCdata, rpcs map[string]string) (ClientsInfo, error) {
func GetClientsInfo(ibc *relayer.IBCdata, rpcs *map[string]config.RPC) (ClientsInfo, error) {
clientsInfo := ClientsInfo{}

cdA := chain.Info{
ChainID: ibc.Chain1.ChainName,
RPCAddr: rpcs[ibc.Chain1.ChainName],
ChainID: (*rpcs)[ibc.Chain1.ChainName].ChainID,
RPCAddr: (*rpcs)[ibc.Chain1.ChainName].URL,
ClientID: ibc.Chain1.ClientID,
}

Expand All @@ -35,8 +36,8 @@ func GetClientsInfo(ibc *relayer.IBCdata, rpcs map[string]string) (ClientsInfo,
clientsInfo.ChainA = chainA

cdB := chain.Info{
ChainID: ibc.Chain2.ChainName,
RPCAddr: rpcs[ibc.Chain2.ChainName],
ChainID: (*rpcs)[ibc.Chain2.ChainName].ChainID,
RPCAddr: (*rpcs)[ibc.Chain2.ChainName].URL,
ClientID: ibc.Chain2.ClientID,
}

Expand Down