Skip to content

Commit

Permalink
Add BandProtocol_laozi-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
wlsaud619 committed Jun 11, 2021
1 parent 49ef56a commit 2ec14fe
Show file tree
Hide file tree
Showing 11 changed files with 501 additions and 49 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Cosmos-IE
![CreatePlan](https://img.shields.io/badge/release-v3.0.2-red)
![CreatePlan](https://img.shields.io/badge/release-v3.0.3-red)
![CreatePlan](https://img.shields.io/badge/go-1.15%2B-blue)
![CreatePlan](https://img.shields.io/badge/license-Apache--2.0-green)
Integrated Exporter for CosmosSDK
Expand All @@ -8,7 +8,7 @@ Integrated Exporter for CosmosSDK
This Prometheus exporter is for monitoring information which is not provided from Tendermint’s basic Prometheus exporter(localhost:26660)

## List of supported chains
Cosmos(cosmoshub-4), IRISnet(irishub-1)
Cosmos(cosmoshub-4), IRISnet(irishub-1), BandProtocol-testnet(band-laozi-testnet1)

## Install
```bash
Expand All @@ -19,7 +19,7 @@ cd $HOME/Cosmos-IE
go build

./Cosmos-IE version
## Cosmos-IE v3.0.2
## Cosmos-IE v3.0.3
```

## Service(ex: cosmos)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

var (
version string = "v3.0.2"
version string = "v3.0.3"

// versionCmd represents the version command
versionCmd = &cobra.Command{
Expand Down
18 changes: 17 additions & 1 deletion exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,23 @@ func Start(chain string, log *zap.Logger) {

func addGauges(chain string, metricData *metric, log *zap.Logger) {

if chain == "terra" {
if chain == "band" {
if len(additionalGauges) == 0 {
additionalGauges = make([]prometheus.Gauge, len(gaugesNamespaceList_Band))

for i := 0; i < len(gaugesNamespaceList_Band); i++ {
additionalGauges[i] = utils.NewGauge("exporter", gaugesNamespaceList_Band[i], "")
prometheus.MustRegister(additionalGauges[i])
}
} else {
gaugesValue := [...]float64{
metricData.Validator.Oracle.Active,
}
for i:=0; i < len(gaugesNamespaceList_Band); i++ {
additionalGauges[i].Set(gaugesValue[i])
}
}
} else if chain == "terra" {
if len(additionalGauges) == 0 {
additionalGauges = make([]prometheus.Gauge, len(gaugesNamespaceList_Terra))

Expand Down
30 changes: 16 additions & 14 deletions exporter/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func SetMetric(currentBlock int64, restData *rest.RESTData, log *zap.Logger) {
consPubKey := restData.Validator.Consensus_pubkey.Key
consAddr := restData.Validatorsets[consPubKey][0]

//// network
/* network */
metricData.Network.ChainID = restData.Commit.ChainId
metricData.Network.BlockHeight = currentBlock

Expand All @@ -23,54 +23,56 @@ func SetMetric(currentBlock int64, restData *rest.RESTData, log *zap.Logger) {
metricData.Network.Staking.TotalSupply = restData.StakingPool.Pool.Total_supply
metricData.Network.Staking.BondedRatio = metricData.Network.Staking.BondedTokens / metricData.Network.Staking.TotalSupply

// minting
//// minting
metricData.Network.Minting.Inflation = restData.Inflation
metricData.Network.Minting.ActualInflation = metricData.Network.Minting.Inflation / metricData.Network.Staking.BondedRatio

//gov
////gov
metricData.Network.Gov.TotalProposalCount = restData.Gov.TotalProposalCount
metricData.Network.Gov.VotingProposalCount = restData.Gov.VotingProposalCount


//// validator
/* validator */
metricData.Validator.Moniker = restData.Validator.Description.Moniker
metricData.Validator.VotingPower = utils.StringToFloat64(restData.Validatorsets[consPubKey][1])
metricData.Validator.MinSelfDelegation = utils.StringToFloat64(restData.Validator.MinSelfDelegation)
metricData.Validator.JailStatus = utils.BoolToFloat64(restData.Validator.Jailed)

// address
//// address
metricData.Validator.Address.Operator = operAddr
metricData.Validator.Address.Account = utils.GetAccAddrFromOperAddr(operAddr, log)
metricData.Validator.Address.ConsensusHex = utils.Bech32AddrToHexAddr(consAddr, log)

// proposer
//// proposer
// metricData.Validator.Proposer.Ranking = utils.StringToFloat64(restData.Validatorsets[consPubKey][3])
// metricData.Validator.Proposer.Status = restData.Commit.ValidatorProposingStatus

// delegation
//// delegation
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

// commission
//// commission
metricData.Validator.Commission.Rate = utils.StringToFloat64(restData.Validator.Commission.Commission_rates.Rate)
metricData.Validator.Commission.MaxRate = utils.StringToFloat64(restData.Validator.Commission.Commission_rates.Max_rate)
metricData.Validator.Commission.MaxChangeRate = utils.StringToFloat64(restData.Validator.Commission.Commission_rates.Max_change_rate)

// account
//// account
metricData.Validator.Account.Balances = restData.Balances
metricData.Validator.Account.Commission = restData.Commission
metricData.Validator.Account.Rewards = restData.Rewards

// commit
//// commit
// metricData.Validator.Commit.VoteType = restData.Commit.VoteType
metricData.Validator.Commit.PrecommitStatus = restData.Commit.ValidatorPrecommitStatus

// oracle
metricData.Validator.Oracle.Miss = restData.Oracle.Miss
//for Terra
metricData.Validator.Oracle.FeederBalance = utils.StringToFloat64(restData.Oracle.Feeder.Balance.Amount)
//// oracle
// Terra
metricData.Validator.Oracle.Miss = restData.Oracle_terra.Miss
metricData.Validator.Oracle.FeederBalance = utils.StringToFloat64(restData.Oracle_terra.Feeder.Balance.Amount)
// Band
metricData.Validator.Oracle.Active = restData.Oracle_band

}

Expand Down
15 changes: 14 additions & 1 deletion exporter/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
iris "github.com/irisnet/irishub/address"


terra "github.com/terra-project/core/types"
// kava "github.com/kava-labs/kava/app"
emoney "github.com/e-money/em-ledger/types"
Expand Down Expand Up @@ -47,6 +46,20 @@ func setConfig(chain string) {
switch chain {
case "iris":
iris.ConfigureBech32Prefix()
case "band":
bech32MainPrefix := "band"
var bip44CoinType uint32 = 494

accountPrefix := bech32MainPrefix
validatorPrefix := bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator
consensusPrefix := bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus

config.SetBech32PrefixForAccount(accountPrefix, accountPrefix+sdk.PrefixPublic)
config.SetBech32PrefixForValidator(validatorPrefix, validatorPrefix+sdk.PrefixPublic)
config.SetBech32PrefixForConsensusNode(consensusPrefix, consensusPrefix+sdk.PrefixPublic)
config.SetCoinType(bip44CoinType)

// fmt.Println(accountPrefix, validatorPrefix, consensusPrefix)

case "terra":
config.SetCoinType(terra.CoinType)
Expand Down
10 changes: 8 additions & 2 deletions exporter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (
gaugesNamespaceList_Terra = [...]string{"oracleMiss",
"oracleFeederBalance",
}
gaugesNamespaceList_Band = [...]string{"oracleActive",
}

metricData metric
)
Expand Down Expand Up @@ -107,10 +109,13 @@ type metric struct {
PrecommitStatus float64
}

// for Terra
// for Terra & Band
Oracle struct {
// Terra
Miss float64
FeederBalance float64
// Band
Active float64
}

}
Expand All @@ -123,11 +128,12 @@ func getDenomList(chain string) []string {
// Add a staking denom to index 0
switch chain{
case "cosmos":
// dList = []string{"uatom"}
dList = []string{"uatom"}
case "iris":
dList = []string{"uiris"}
// dList = []string{"ubif"}
case "band":
dList = []string{"uband"}
case "terra":
dList = []string{"uluna",
"ukrw", "usdr", "uusd", "umnt"}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/node-a-team/Cosmos-IE
go 1.15

require (
github.com/bandprotocol/chain v1.0.0
github.com/cosmos/cosmos-sdk v0.41.3
github.com/e-money/em-ledger v0.9.4
github.com/irisnet/irishub v1.0.1
Expand All @@ -13,7 +14,7 @@ require (
github.com/spf13/viper v1.7.1
github.com/tendermint/tendermint v0.34.7
github.com/terra-project/core v0.4.2
go.uber.org/zap v1.13.0
go.uber.org/zap v1.15.0
)

replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
Expand Down
Loading

0 comments on commit 2ec14fe

Please sign in to comment.