-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor consensus querying (#35)
* chore: add config example * chore: removed unnecessary config option * chore: added disclaimer on how to get consensus-address
- Loading branch information
1 parent
a0536bf
commit 64623dd
Showing
13 changed files
with
133 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package queriers | ||
|
||
import ( | ||
"main/pkg/config" | ||
"main/pkg/tendermint" | ||
"main/pkg/types" | ||
"main/pkg/utils" | ||
"sync" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
type SigningInfoQuerier struct { | ||
Logger zerolog.Logger | ||
Config *config.Config | ||
} | ||
|
||
func NewSigningInfoQuerier(logger *zerolog.Logger, config *config.Config) *SigningInfoQuerier { | ||
return &SigningInfoQuerier{ | ||
Logger: logger.With().Str("component", "rewards_querier").Logger(), | ||
Config: config, | ||
} | ||
} | ||
|
||
func (q *SigningInfoQuerier) GetMetrics() ([]prometheus.Collector, []*types.QueryInfo) { | ||
var queryInfos []*types.QueryInfo | ||
|
||
missedBlocksGauge := prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "cosmos_validators_exporter_missed_blocks", | ||
Help: "Validator's missed blocks", | ||
}, | ||
[]string{"chain", "address"}, | ||
) | ||
|
||
var wg sync.WaitGroup | ||
var mutex sync.Mutex | ||
|
||
for _, chain := range q.Config.Chains { | ||
rpc := tendermint.NewRPC(chain, q.Config.Timeout, q.Logger) | ||
|
||
for _, validator := range chain.Validators { | ||
wg.Add(1) | ||
go func(validator config.Validator, rpc *tendermint.RPC, chain config.Chain) { | ||
defer wg.Done() | ||
|
||
if validator.ConsensusAddress == "" { | ||
return | ||
} | ||
|
||
signingInfo, signingInfoQuery, err := rpc.GetSigningInfo(validator.ConsensusAddress) | ||
|
||
mutex.Lock() | ||
defer mutex.Unlock() | ||
|
||
queryInfos = append(queryInfos, signingInfoQuery) | ||
|
||
if err != nil { | ||
q.Logger.Error(). | ||
Err(err). | ||
Str("chain", chain.Name). | ||
Str("address", validator.Address). | ||
Msg("Error getting validator signing info") | ||
return | ||
} | ||
|
||
missedBlocksCounter := utils.StrToInt64(signingInfo.ValSigningInfo.MissedBlocksCounter) | ||
if missedBlocksCounter >= 0 { | ||
missedBlocksGauge.With(prometheus.Labels{ | ||
"chain": chain.Name, | ||
"address": validator.Address, | ||
}).Set(float64(missedBlocksCounter)) | ||
} | ||
}(validator, rpc, chain) | ||
} | ||
} | ||
|
||
wg.Wait() | ||
|
||
return []prometheus.Collector{ | ||
missedBlocksGauge, | ||
}, queryInfos | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters