Skip to content

Commit

Permalink
chore: handle merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jim380 committed Sep 17, 2023
2 parents 8e12c30 + 47f06b8 commit cc9993e
Show file tree
Hide file tree
Showing 26 changed files with 478 additions and 175 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# FROM golang:1.15
FROM golang:alpine3.13 AS build-env
FROM golang:1.20-alpine AS build-env

# Set up dependencies
ENV PACKAGES bash curl make git libc-dev gcc linux-headers eudev-dev python3
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# FROM golang:1.15
FROM golang:alpine3.13 AS build-env
FROM golang:1.20-alpine AS build-env

# Set up dependencies
ENV PACKAGES bash curl make git libc-dev gcc linux-headers eudev-dev python3
Expand Down
24 changes: 23 additions & 1 deletion config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"fmt"
"log"
"strings"

sdktypes "github.com/cosmos/cosmos-sdk/types"
"github.com/jim380/Cendermint/utils"
Expand All @@ -12,6 +13,7 @@ import (

type Config struct {
Chain string
SDKVersion string
OperatorAddr string
RestAddr string
RpcAddr string
Expand Down Expand Up @@ -58,7 +60,7 @@ func (config Config) CheckInputs(chainList map[string][]string) {
}
}

// TODO add more robust checks
// TO-DO add more robust checks
if config.OperatorAddr == "" {
log.Fatal("Operator address was not provided")
}
Expand Down Expand Up @@ -159,3 +161,23 @@ func GetChainList() map[string][]string {

return chainList
}

func (config Config) IsLegacySDKVersion() bool {
var legacy bool = false

if strings.Contains(config.SDKVersion, "0.45") {
legacy = true
}

return legacy
}

func (config Config) IsGravityBridgeEnabled() bool {
var enabled bool = false

if config.Chain == "gravity" || config.Chain == "umee" {
enabled = true
}

return enabled
}
17 changes: 8 additions & 9 deletions exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

func Start(chain string, port string, logger *zap.Logger) {
func Start(config *config.Config, port string, logger *zap.Logger) {
http.Handle("/metrics", promhttp.Handler())
go Run(chain, logger)
go Run(config, logger)

err := http.ListenAndServe(":"+port, nil)
if err != nil {
Expand All @@ -26,38 +26,37 @@ func Start(chain string, port string, logger *zap.Logger) {

}

func Run(chain string, log *zap.Logger) {
func Run(cfg *config.Config, log *zap.Logger) {
cl := config.GetChainList()
denomList := config.GetDenomList(chain, cl)
denomList := config.GetDenomList(cfg.Chain, cl)

registerGauges(denomList)
counterVecs := registerLabels()

pollInterval, _ := strconv.Atoi(os.Getenv("POLL_INTERVAL"))
ticker := time.NewTicker(1 * time.Second).C
// ticker2 := time.NewTicker(40 * time.Second).C

go func() {
for {
var block rest.Blocks
block.GetInfo()
block.GetInfo(*cfg)

currentBlockHeight, _ := strconv.ParseInt(block.Block.Header.Height, 10, 64)
if previousBlockHeight != currentBlockHeight {
fmt.Println("--------------------------- Start ---------------------------")
block.GetLastBlockTimestamp(currentBlockHeight)
block.GetLastBlockTimestamp(*cfg, currentBlockHeight)
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Last block timestamp", block.Block.Header.LastTimestamp))
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Current block timestamp", block.Block.Header.Timestamp))
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Current block height", fmt.Sprint(currentBlockHeight)))
select {
case <-ticker:
// fetch info from REST
restData := rest.GetData(chain, currentBlockHeight, block, denomList[0])
restData := rest.GetData(cfg, currentBlockHeight, block, denomList[0])
SetMetric(currentBlockHeight, restData, log)
// case <-ticker2:
// takes ~5-6 blocks to return results per request
// tends to halt the node too. Caution !!!
// restData := rest.GetDelegationsData(chain, currentBlockHeight, block, denomList[0])
// restData := rest.GetDelegationsData(cfg, chain, currentBlockHeight, block, denomList[0])
// SetMetric(currentBlockHeight, restData, log)
}

Expand Down
16 changes: 8 additions & 8 deletions exporter/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// gauges/labels <-> value
func SetMetric(currentBlock int64, restData *rest.RESTData, log *zap.Logger) {
operAddr := rest.OperAddr
consPubKey := restData.Validators.ConsPubKey
consPubKey := restData.Validator.ConsPubKey
consAddr := restData.Validatorsets[consPubKey.Key][0]

// chain
Expand Down Expand Up @@ -51,17 +51,17 @@ func SetMetric(currentBlock int64, restData *rest.RESTData, log *zap.Logger) {

// validator info
metricData.Validator.VotingPower = utils.StringToFloat64(restData.Validatorsets[consPubKey.Key][1])
metricData.Validator.JailStatus = utils.BoolToFloat64(restData.Validators.Jailed)
metricData.Validator.MinSelfDelegation = utils.StringToFloat64(restData.Validators.MinSelfDelegation)
metricData.Validator.JailStatus = utils.BoolToFloat64(restData.Validator.Jailed)
metricData.Validator.MinSelfDelegation = utils.StringToFloat64(restData.Validator.MinSelfDelegation)
// validator delegation
metricData.Validator.Delegation.Shares = utils.StringToFloat64(restData.Validators.DelegatorShares)
metricData.Validator.Delegation.Shares = utils.StringToFloat64(restData.Validator.DelegatorShares)
metricData.Validator.Delegation.Ratio = metricData.Validator.Delegation.Shares / metricData.Network.Staking.BondedTokens
// metricData.Validator.Delegation.DelegatorCount = restData.Delegations.DelegationCount
// metricData.Validator.Delegation.Self = restData.Delegations.SelfDelegation
// validator commission
metricData.Validator.Commission.Rate = utils.StringToFloat64(restData.Validators.Commission.Commission.Rate)
metricData.Validator.Commission.MaxRate = utils.StringToFloat64(restData.Validators.Commission.Commission.Max_rate)
metricData.Validator.Commission.MaxChangeRate = utils.StringToFloat64(restData.Validators.Commission.Commission.Max_change_rate)
metricData.Validator.Commission.Rate = utils.StringToFloat64(restData.Validator.Commission.Commission.Rate)
metricData.Validator.Commission.MaxRate = utils.StringToFloat64(restData.Validator.Commission.Commission.Max_rate)
metricData.Validator.Commission.MaxChangeRate = utils.StringToFloat64(restData.Validator.Commission.Commission.Max_change_rate)
// validator signing
metricData.Validator.Commit.PrecommitStatus = restData.Commit.ValidatorPrecommitStatus
metricData.Validator.Proposer.Status = restData.Commit.ValidatorProposingStatus
Expand Down Expand Up @@ -129,7 +129,7 @@ func SetMetric(currentBlock int64, restData *rest.RESTData, log *zap.Logger) {

// labels node
metricData.Network.ChainID = restData.Commit.ChainId
metricData.Validator.Moniker = restData.Validators.Description.Moniker
metricData.Validator.Moniker = restData.Validator.Description.Moniker
metricData.Network.NodeInfo.Moniker = restData.NodeInfo.Default.Moniker
metricData.Network.NodeInfo.NodeID = restData.NodeInfo.Default.NodeID
metricData.Network.NodeInfo.TMVersion = restData.NodeInfo.Default.TMVersion
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -70,5 +70,5 @@ func main() {
rest.RPCAddr = rpcAddr
rest.OperAddr = operAddr

exporter.Start(chain, listeningPort, logger)
exporter.Start(&cfg, listeningPort, logger)
}
15 changes: 8 additions & 7 deletions rest/akash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"strconv"

"github.com/jim380/Cendermint/config"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -107,19 +108,19 @@ type GroupSpec struct {
} `json:"resources"`
}

func (rd *RESTData) getAkashDeployments() {
// var deployments akashDeployments
func (rd *RESTData) getAkashDeployments(cfg config.Config) {
if cfg.Chain != "akash" {
return
}
var deployments, activeDeployments akashDeployments

// ?filters.state=active
res, err := HttpQuery(RESTAddr + "/akash/deployment/v1beta2/deployments/list")
route := getDeploymentsRoute()
res, err := HttpQuery(RESTAddr + route)
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &deployments)

// rd.AkashInfo.Deployments = deployments

// get total deployments count
totalDeploymentsCount, err := strconv.Atoi(deployments.Pagination.Total)
if err != nil {
Expand All @@ -128,7 +129,7 @@ func (rd *RESTData) getAkashDeployments() {
rd.AkashInfo.TotalDeployments = totalDeploymentsCount

// get active deployments count
resActive, err := HttpQuery(RESTAddr + "/akash/deployment/v1beta2/deployments/list?filters.state=active")
resActive, err := HttpQuery(RESTAddr + route + "?filters.state=active")
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
Expand Down
7 changes: 5 additions & 2 deletions rest/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"strings"

"github.com/jim380/Cendermint/config"
"go.uber.org/zap"
)

Expand All @@ -16,10 +17,12 @@ type Coin struct {
Amount string
}

func (rd *RESTData) getBalances() {
func (rd *RESTData) getBalances(cfg config.Config) {
var b balances

res, err := HttpQuery(RESTAddr + "/cosmos/bank/v1beta1/balances/" + AccAddr)
route := getBalancesByAddressRoute(cfg)

res, err := HttpQuery(RESTAddr + route + AccAddr)
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
Expand Down
11 changes: 7 additions & 4 deletions rest/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"
"strings"

"github.com/jim380/Cendermint/config"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -39,8 +40,9 @@ type lastCommit struct {
}
}

func (b *Blocks) GetInfo() Blocks {
res, err := HttpQuery(RESTAddr + "/blocks/latest")
func (b *Blocks) GetInfo(cfg config.Config) Blocks {
route := getBlockInfoRoute(cfg)
res, err := HttpQuery(RESTAddr + route)
if err != nil {
zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error()))
}
Expand All @@ -54,9 +56,10 @@ func (b *Blocks) GetInfo() Blocks {
return *b
}

func (b *Blocks) GetLastBlockTimestamp(currentHeight int64) Blocks {
func (b *Blocks) GetLastBlockTimestamp(cfg config.Config, currentHeight int64) Blocks {
var lastBlock LastBlock
res, err := HttpQuery(RESTAddr + "/blocks/" + strconv.Itoa(int(currentHeight-1)))
route := getBlockByHeightRoute(cfg)
res, err := HttpQuery(RESTAddr + route + strconv.Itoa(int(currentHeight-1)))
if err != nil {
zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error()))
}
Expand Down
10 changes: 6 additions & 4 deletions rest/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"

"github.com/jim380/Cendermint/config"
"github.com/jim380/Cendermint/utils"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ type rpcValidators struct {
} `json:"validators"`
}

func (rpc *RPCData) getConsensusDump() {
func (rpc *RPCData) getConsensusDump(cfg config.Config) {
var cs ConsensusState
var vSetsResult map[string][]string = make(map[string][]string)

Expand All @@ -66,7 +67,7 @@ func (rpc *RPCData) getConsensusDump() {
}
json.Unmarshal(res, &cs)

conspubMonikerMap := rpc.getConspubMonikerMap()
conspubMonikerMap := rpc.getConspubMonikerMap(cfg)
// cs.Result.Validatorset.Validators is already sorted based on voting power
for index, validator := range cs.Result.Validatorset.Validators {
var prevote, precommit string
Expand Down Expand Up @@ -101,11 +102,12 @@ func (rpc *RPCData) getConsensusDump() {
zap.L().Info("", zap.Bool("Success", true), zap.String("# of validators from RPC", fmt.Sprint(len(rpc.Validatorsets))))
}

func (rpc *RPCData) getConspubMonikerMap() map[string]string {
func (rpc *RPCData) getConspubMonikerMap(cfg config.Config) map[string]string {
var v rpcValidators
var vResult map[string]string = make(map[string]string)

res, err := HttpQuery(RESTAddr + "/cosmos/staking/v1beta1/validators?status=BOND_STATUS_BONDED&pagination.limit=300")
route := getValidatorsRoute(cfg)
res, err := HttpQuery(RESTAddr + route + "?status=BOND_STATUS_BONDED&pagination.limit=300")
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
Expand Down
6 changes: 4 additions & 2 deletions rest/delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/jim380/Cendermint/config"
"go.uber.org/zap"
)

Expand All @@ -28,11 +29,12 @@ type delegationRes []struct {
}
}

func (rd *RESTData) getDelegations() {
func (rd *RESTData) getDelegations(cfg config.Config) {
var delInfo delegationsInfo
var delRes map[string][]string = make(map[string][]string)

res, err := HttpQuery(RESTAddr + "/cosmos/staking/v1beta1/validators/" + OperAddr + "/delegations" + "?pagination.limit=1000")
route := getValidatorByAddressRoute(cfg)
res, err := HttpQuery(RESTAddr + route + OperAddr + "/delegations" + "?pagination.limit=1000")
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
Expand Down
Loading

0 comments on commit cc9993e

Please sign in to comment.