Skip to content

Commit

Permalink
chore: fix proposal bug & refactor around config
Browse files Browse the repository at this point in the history
  • Loading branch information
jim380 committed Sep 17, 2023
1 parent 8c282c5 commit d9f07d3
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 56 deletions.
18 changes: 10 additions & 8 deletions config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ func (config Config) CheckInputs(chainList map[string][]string) {
}

// TO-DO add more robust checks
if config.SDKVersion == "" {
log.Fatal("SDK version was not provided")
}

if config.OperatorAddr == "" {
log.Fatal("Operator address was not provided")
}
Expand Down Expand Up @@ -166,10 +162,6 @@ func GetChainList() map[string][]string {
return chainList
}

func (config Config) GetSDKVersion() string {
return config.SDKVersion
}

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

Expand All @@ -179,3 +171,13 @@ func (config Config) IsLegacySDKVersion() bool {

return legacy
}

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

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

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

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

Expand All @@ -26,7 +26,7 @@ func Start(config config.Config, port string, logger *zap.Logger) {

}

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

Expand All @@ -39,12 +39,12 @@ func Run(cfg config.Config, log *zap.Logger) {
go func() {
for {
var block rest.Blocks
block.GetInfo(cfg)
block.GetInfo(*cfg)

currentBlockHeight, _ := strconv.ParseInt(block.Block.Header.Height, 10, 64)
if previousBlockHeight != currentBlockHeight {
fmt.Println("--------------------------- Start ---------------------------")
block.GetLastBlockTimestamp(cfg, 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)))
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func main() {

cfg := config.Config{
Chain: os.Getenv("CHAIN"),
SDKVersion: os.Getenv("SDK_VERSION"),
OperatorAddr: os.Getenv("OPERATOR_ADDR"),
RestAddr: os.Getenv("REST_ADDR"),
RpcAddr: os.Getenv("RPC_ADDR"),
Expand Down Expand Up @@ -71,5 +70,5 @@ func main() {
rest.RPCAddr = rpcAddr
rest.OperAddr = operAddr

exporter.Start(cfg, listeningPort, logger)
exporter.Start(&cfg, listeningPort, logger)
}
6 changes: 5 additions & 1 deletion 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,7 +108,10 @@ type GroupSpec struct {
} `json:"resources"`
}

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

route := getDeploymentsRoute()
Expand Down
13 changes: 6 additions & 7 deletions rest/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ func (rd *RESTData) getGovInfo(cfg config.Config) {
var (
g gov
gi govInfo
totalProposals []string
proposalsInVoting []string
inVotingVoted int
inVotingDidNotVote int
)

route := getProposalsRoute(cfg)
res, err := HttpQuery(RESTAddr + route + "?pagination.limit=1000")
res, err := HttpQuery(RESTAddr + route + "?pagination.limit=2000")
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
Expand All @@ -58,13 +57,14 @@ func (rd *RESTData) getGovInfo(cfg config.Config) {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
}

for _, value := range g.Proposals {
totalProposals = append(totalProposals, value.ProposalID)
totalProposals := g.Proposals
for _, value := range totalProposals {
if value.Status == "PROPOSAL_STATUS_VOTING_PERIOD" {
proposalsInVoting = append(proposalsInVoting, value.ProposalID)
}
}
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Total proposals count", totalProposals[len(totalProposals)-1]))

zap.L().Info("\t", zap.Bool("Success", true), zap.String("Total proposals count", strconv.Itoa(len(totalProposals))))
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Proposals in voting", strconv.Itoa(len(proposalsInVoting))))

for _, value := range proposalsInVoting {
Expand All @@ -80,8 +80,7 @@ func (rd *RESTData) getGovInfo(cfg config.Config) {
inVotingDidNotVote++
}
}
totalProposalsCount, _ := strconv.ParseFloat(totalProposals[len(totalProposals)-1], 64)
gi.TotalProposalCount = totalProposalsCount
gi.TotalProposalCount = float64(len(totalProposals))
gi.VotingProposalCount = float64(len(proposalsInVoting))
gi.InVotingVotedCount = float64(inVotingVoted)
gi.InVotingDidNotVoteCount = float64(inVotingDidNotVote)
Expand Down
31 changes: 25 additions & 6 deletions rest/gravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"os"

"github.com/jim380/Cendermint/config"
utils "github.com/jim380/Cendermint/utils"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -132,7 +133,10 @@ func (rd *RESTData) getUmeePrice() {
rd.GravityInfo.UMEEPrice = p.UMEEPrice
}

func (rd *RESTData) getBatchFees() {
func (rd *RESTData) getBatchFees(cfg config.Config) {
if !cfg.IsGravityBridgeEnabled() {
return
}
var b batchFees

route := getBatchFeesRoute()
Expand All @@ -151,7 +155,10 @@ func (rd *RESTData) getBatchFees() {
rd.GravityInfo.BatchFees = feesTotal
}

func (rd *RESTData) getBatchesFees() {
func (rd *RESTData) getBatchesFees(cfg config.Config) {
if !cfg.IsGravityBridgeEnabled() {
return
}
var b batches

route := getBatchesFeesRoute()
Expand All @@ -172,7 +179,10 @@ func (rd *RESTData) getBatchesFees() {
rd.GravityInfo.BatchesFees = feesTotal
}

func (rd *RESTData) getBridgeFees() {
func (rd *RESTData) getBridgeFees(cfg config.Config) {
if !cfg.IsGravityBridgeEnabled() {
return
}
var p ethPrice
var bf float64

Expand All @@ -189,7 +199,10 @@ func (rd *RESTData) getBridgeFees() {
rd.GravityInfo.BridgeFees = bf
}

func (rd *RESTData) getBridgeParams() {
func (rd *RESTData) getBridgeParams(cfg config.Config) {
if !cfg.IsGravityBridgeEnabled() {
return
}
var params gravityParams

rd.GravityInfo.GravityActive = 0.0
Expand All @@ -209,7 +222,10 @@ func (rd *RESTData) getBridgeParams() {
}
}

func (rd *RESTData) getOracleEventNonce() {
func (rd *RESTData) getOracleEventNonce(cfg config.Config) {
if !cfg.IsGravityBridgeEnabled() {
return
}
var evt oracleEventNonce

orchAddr := os.Getenv("UMEE_ORCH_ADDR")
Expand All @@ -223,7 +239,10 @@ func (rd *RESTData) getOracleEventNonce() {
rd.GravityInfo.EventNonce = evt.EventNonce
}

func (rd *RESTData) getValSet() {
func (rd *RESTData) getValSet(cfg config.Config) {
if !cfg.IsGravityBridgeEnabled() {
return
}
var vs valSetInfo

var vsResult map[string]string = make(map[string]string)
Expand Down
5 changes: 3 additions & 2 deletions rest/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type appVersion struct {
SDKVersion string `json:"cosmos_sdk_version"`
}

func (rd *RESTData) getNodeInfo(cfg config.Config) {
func (rd *RESTData) getNodeInfo(cfg *config.Config) {
var nodeInfo nodeInfo

route := getNodeInfoRoute(cfg)
route := getNodeInfoRoute()
res, err := HttpQuery(RESTAddr + route)
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
Expand All @@ -47,4 +47,5 @@ func (rd *RESTData) getNodeInfo(cfg config.Config) {
zap.L().Info("", zap.Bool("Success", true), zap.String("SDK version", nodeInfo.Application.SDKVersion))

rd.NodeInfo = nodeInfo
cfg.SDKVersion = nodeInfo.Application.SDKVersion
}
50 changes: 25 additions & 25 deletions rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (rpc RPCData) new() *RPCData {
return &RPCData{Validatorsets: make(map[string][]string)}
}

func GetData(cfg config.Config, blockHeight int64, blockData Blocks, denom string) *RESTData {
func GetData(cfg *config.Config, blockHeight int64, blockData Blocks, denom string) *RESTData {
// rpc
var rpcData RPCData
rpc := rpcData.new()
Expand All @@ -67,26 +67,27 @@ func GetData(cfg config.Config, blockHeight int64, blockData Blocks, denom strin
AccAddr = utils.GetAccAddrFromOperAddr(OperAddr)

rd := restData.new(blockHeight)
rd.getNodeInfo(cfg) // get node info first

wg := sync.WaitGroup{}
wg.Add(1)
go func() {
rpc.getConsensusDump(cfg)
rd.getStakingPool(cfg, denom)
rd.getSlashingParams(cfg)
rd.getInflation(cfg, denom)
rd.getGovInfo(cfg)
// TO-DO fix finding validator in active set for sdk version >= v0.46
rd.getValidatorsets(cfg, blockHeight)
rd.getValidator(cfg)

rpc.getConsensusDump(*cfg)
rd.getStakingPool(*cfg, denom)
rd.getSlashingParams(*cfg)
rd.getInflation(*cfg, denom)
rd.getGovInfo(*cfg)
rd.getValidatorsets(*cfg, blockHeight)
rd.getValidator(*cfg)
// TO-DO if consumer chain, use cosmoshub's ConsPubKey
valMap, found := rd.Validatorsets[rd.Validator.ConsPubKey.Key]
if !found {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "Validator not found in the active set"))
}

rd.getBalances(cfg)
rd.getRewardsCommission(cfg)
rd.getSigningInfo(cfg, valMap[0])
rd.getBalances(*cfg)
rd.getRewardsCommission(*cfg)
rd.getSigningInfo(*cfg, valMap[0])

consHexAddr := utils.Bech32AddrToHexAddr(valMap[0])
rd.getCommit(blockData, consHexAddr)
Expand All @@ -96,20 +97,19 @@ func GetData(cfg config.Config, blockHeight int64, blockData Blocks, denom strin
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Balances", fmt.Sprint(rd.Balances)))
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Rewards", fmt.Sprint(rd.Rewards)))
zap.L().Info("\t", zap.Bool("Success", true), zap.String("Commission", fmt.Sprint(rd.Commission)))
rd.getIBCChannels(cfg)
rd.getIBCConnections(cfg)
rd.getNodeInfo(cfg)
rd.getTxInfo(cfg, blockHeight)
rd.getIBCChannels(*cfg)
rd.getIBCConnections(*cfg)
rd.getTxInfo(*cfg, blockHeight)
rd.computerTPS(blockData)
rd.getUpgradeInfo(cfg)
rd.getAkashDeployments()
rd.getUpgradeInfo(*cfg)
rd.getAkashDeployments(*cfg)
// gravity
rd.getBridgeParams()
rd.getValSet()
rd.getOracleEventNonce()
rd.getBatchFees()
rd.getBatchesFees()
rd.getBridgeFees()
rd.getBridgeParams(*cfg)
rd.getValSet(*cfg)
rd.getOracleEventNonce(*cfg)
rd.getBatchFees(*cfg)
rd.getBatchesFees(*cfg)
rd.getBridgeFees(*cfg)
wg.Done()
}()
wg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion rest/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func getProposalsRoute(cfg config.Config) string {
return "/cosmos/gov/v1beta1/proposals"
}

func getNodeInfoRoute(cfg config.Config) string {
func getNodeInfoRoute() string {
return "/cosmos/base/tendermint/v1beta1/node_info"
}

Expand Down

0 comments on commit d9f07d3

Please sign in to comment.