Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : Modify tenderduty dashboard status about tendermint bn254 pubkey type for union chain #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ chains:
chain_id: osmosis-1
# Hooray, in v2 we derive the valcons from abci queries so you don't have to jump through hoops to figure out how
# to convert ed25519 keys to the appropriate bech32 address.
# Use valcons address if using ICS
# Use valcons address if using ICS or tendermint/PubKeyBn254
valoper_address: osmovaloper1xxxxxxx...
# Should the monitor revert to using public API endpoints if all supplied RCP nodes fail?
# This isn't always reliable, not all public nodes have websocket proxying setup correctly.
Expand Down
71 changes: 64 additions & 7 deletions td2/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tenderduty

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -39,20 +40,28 @@ func (cc *ChainConfig) newRpc() error {
down = true
return
}
var network string
var catching_up bool
status, err := cc.client.Status(ctx)
if err != nil {
msg = fmt.Sprintf("❌ could not get status for %s: (%s) %s", cc.name, u, err)
down = true
l(msg)
return
n, c, err := getStatusWithEndpoint(ctx, u)
if err != nil {
msg = fmt.Sprintf("❌ could not get status for %s: (%s) %s", cc.name, u, err)
down = true
l(msg)
return
}
network, catching_up = n, c
} else {
network, catching_up = status.NodeInfo.Network, status.SyncInfo.CatchingUp
}
if status.NodeInfo.Network != cc.ChainId {
msg = fmt.Sprintf("chain id %s on %s does not match, expected %s, skipping", status.NodeInfo.Network, u, cc.ChainId)
if network != cc.ChainId {
msg = fmt.Sprintf("chain id %s on %s does not match, expected %s, skipping", network, u, cc.ChainId)
down = true
l(msg)
return
}
if status.SyncInfo.CatchingUp {
if catching_up {
msg = fmt.Sprint("🐢 node is not synced, skipping ", u)
syncing = true
down = true
Expand Down Expand Up @@ -261,3 +270,51 @@ func guessPublicEndpoint(u string) string {
}
return proto + matches[1] + port
}

func getStatusWithEndpoint(ctx context.Context, u string) (string, bool, error) {
// Parse the URL
parsedURL, err := url.Parse(u)
if err != nil {
return "", false, err
}

// Check if the scheme is 'tcp' and modify to 'http'
if parsedURL.Scheme == "tcp" {
parsedURL.Scheme = "http"
}

queryPath := fmt.Sprintf("%s/status", parsedURL.String())
req, err := http.NewRequestWithContext(ctx, http.MethodGet, queryPath, nil)
if err != nil {
return "", false, err
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", false, err
}
defer resp.Body.Close()

b, err := io.ReadAll(resp.Body)
if err != nil {
return "", false, err
}

type tendermintStatus struct {
JsonRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result struct {
NodeInfo struct {
Network string `json:"network"`
} `json:"node_info"`
SyncInfo struct {
CatchingUp bool `json:"catching_up"`
} `json:"sync_info"`
} `json:"result"`
}
var status tendermintStatus
if err := json.Unmarshal(b, &status); err != nil {
return "", false, err
}
return status.Result.NodeInfo.Network, status.Result.SyncInfo.CatchingUp, nil
}
Loading