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

eth2wrap: fix node peer count #1681

Merged
merged 5 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 13 additions & 6 deletions app/eth2wrap/httpwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"testing"
"time"

Expand All @@ -43,10 +44,7 @@ type BlockAttestationsProvider interface {

// PeerCount is the response for querying beacon node peer count (/eth/v1/node/peer_count).
type PeerCount struct {
Disconnected int
Connecting int
Connected int
Disconnecting int
Connected int64
}

// NodePeerCountProvider is the interface for providing node peer count.
Expand Down Expand Up @@ -163,8 +161,15 @@ func (h *httpAdapter) NodePeerCount(ctx context.Context) (PeerCount, error) {
if err := json.Unmarshal(respBody, &resp); err != nil {
return PeerCount{}, errors.Wrap(err, "failed to parse beacon node peer count response")
}
if resp.Data.Connected == "" {
return PeerCount{}, errors.New("connected peers missing")
}
count, err := strconv.ParseInt(resp.Data.Connected, 10, 64)
if err != nil {
return PeerCount{}, errors.Wrap(err, "invalid value for connected peers")
}

return resp.Data, nil
return PeerCount{Connected: count}, nil
}

type submitBeaconCommitteeSelectionsJSON struct {
Expand All @@ -180,7 +185,9 @@ type attestationsJSON struct {
}

type peerCountJSON struct {
Data PeerCount `json:"data"`
Data struct {
Connected string `json:"connected"`
xenowits marked this conversation as resolved.
Show resolved Hide resolved
} `json:"data"`
}

func httpPost(ctx context.Context, base string, endpoint string, body io.Reader, timeout time.Duration) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion app/monitoringapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func peerCounter(ctx context.Context, eth2Cl eth2wrap.Client, clock clockwork.Cl
}

// beaconNodePeerCount returns the number of connected peers of the beacon node.
func beaconNodePeerCount(ctx context.Context, eth2Cl eth2wrap.Client) (int, error) {
func beaconNodePeerCount(ctx context.Context, eth2Cl eth2wrap.Client) (int64, error) {
xenowits marked this conversation as resolved.
Show resolved Hide resolved
peerCount, err := eth2Cl.NodePeerCount(ctx)
if err != nil {
return 0, errors.Wrap(err, "get beacon node peer count")
Expand Down