Skip to content

Commit

Permalink
Add votePubkey optional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
naei committed Jul 29, 2022
1 parent e72bebd commit dea0bd7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ Usage of solana_exporter:
number for the log level verbosity
-vmodule value
comma-separated list of pattern=N settings for file-filtered logging
-votepubkey
Validator vote address (will only return results of this address)
```
12 changes: 9 additions & 3 deletions cmd/solana_exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const (
)

var (
rpcAddr = flag.String("rpcURI", "", "Solana RPC URI (including protocol and path)")
addr = flag.String("addr", ":8080", "Listen address")
rpcAddr = flag.String("rpcURI", "", "Solana RPC URI (including protocol and path)")
addr = flag.String("addr", ":8080", "Listen address")
votePubkey = flag.String("votepubkey", "", "Validator vote address (will only return results of this address)")
)

func init() {
Expand Down Expand Up @@ -93,7 +94,12 @@ func (c *solanaCollector) Collect(ch chan<- prometheus.Metric) {
ctx, cancel := context.WithTimeout(context.Background(), httpTimeout)
defer cancel()

accs, err := c.rpcClient.GetVoteAccounts(ctx, rpc.CommitmentRecent)
params := map[string]string{"commitment": string(rpc.CommitmentRecent)}
if *votePubkey != "" {
params = map[string]string{"commitment": string(rpc.CommitmentRecent), "votePubkey": *votePubkey}
}

accs, err := c.rpcClient.GetVoteAccounts(ctx, []interface{}{params})
if err != nil {
ch <- prometheus.NewInvalidMetric(c.totalValidatorsDesc, err)
ch <- prometheus.NewInvalidMetric(c.validatorActivatedStake, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type (
)

// https://docs.solana.com/developing/clients/jsonrpc-api#getvoteaccounts
func (c *RPCClient) GetVoteAccounts(ctx context.Context, commitment Commitment) (*GetVoteAccountsResponse, error) {
body, err := c.rpcRequest(ctx, formatRPCRequest("getVoteAccounts", []interface{}{commitment}))
func (c *RPCClient) GetVoteAccounts(ctx context.Context, params []interface{}) (*GetVoteAccountsResponse, error) {
body, err := c.rpcRequest(ctx, formatRPCRequest("getVoteAccounts", params))
if err != nil {
return nil, fmt.Errorf("RPC call failed: %w", err)
}
Expand Down

0 comments on commit dea0bd7

Please sign in to comment.