Skip to content

Commit

Permalink
Remove subnetIDs from uptime manager (#3235)
Browse files Browse the repository at this point in the history
Signed-off-by: Ceyhun Onur <[email protected]>
  • Loading branch information
ceyonur authored Sep 23, 2024
1 parent c4912bc commit c55a011
Show file tree
Hide file tree
Showing 52 changed files with 824 additions and 1,760 deletions.
8 changes: 3 additions & 5 deletions api/info/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Client interface {
IsBootstrapped(context.Context, string, ...rpc.Option) (bool, error)
GetTxFee(context.Context, ...rpc.Option) (*GetTxFeeResponse, error)
Upgrades(context.Context, ...rpc.Option) (*upgrade.Config, error)
Uptime(context.Context, ids.ID, ...rpc.Option) (*UptimeResponse, error)
Uptime(context.Context, ...rpc.Option) (*UptimeResponse, error)
GetVMs(context.Context, ...rpc.Option) (map[ids.ID][]string, error)
}

Expand Down Expand Up @@ -109,11 +109,9 @@ func (c *client) Upgrades(ctx context.Context, options ...rpc.Option) (*upgrade.
return res, err
}

func (c *client) Uptime(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (*UptimeResponse, error) {
func (c *client) Uptime(ctx context.Context, options ...rpc.Option) (*UptimeResponse, error) {
res := &UptimeResponse{}
err := c.requester.SendRequest(ctx, "info.uptime", &UptimeRequest{
SubnetID: subnetID,
}, res, options...)
err := c.requester.SendRequest(ctx, "info.uptime", struct{}{}, res, options...)
return res, err
}

Expand Down
25 changes: 6 additions & 19 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,26 +313,13 @@ type UptimeResponse struct {
WeightedAveragePercentage json.Float64 `json:"weightedAveragePercentage"`
}

type UptimeRequest struct {
// Deprecated: SubnetID in UptimeRequest is deprecated.
// Uptime API will be available only for Primary Network Validators.
SubnetID ids.ID `json:"subnetID"`
}

func (i *Info) Uptime(_ *http.Request, args *UptimeRequest, reply *UptimeResponse) error {
if args.SubnetID != constants.PrimaryNetworkID {
i.log.Warn("Deprecated API called",
zap.String("service", "info"),
zap.String("method", "uptime"),
)
} else {
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "uptime"),
)
}
func (i *Info) Uptime(_ *http.Request, _ *struct{}, reply *UptimeResponse) error {
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "uptime"),
)

result, err := i.networking.NodeUptime(args.SubnetID)
result, err := i.networking.NodeUptime()
if err != nil {
return fmt.Errorf("couldn't get node uptime: %w", err)
}
Expand Down
14 changes: 1 addition & 13 deletions api/info/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ info.peers({
lastReceived: string,
benched: string[],
observedUptime: int,
observedSubnetUptime: map[string]int,
}
}
```
Expand All @@ -542,7 +541,6 @@ info.peers({
- `lastReceived` is the timestamp of last message received from the peer.
- `benched` shows chain IDs that the peer is being benched.
- `observedUptime` is this node's primary network uptime, observed by the peer.
- `observedSubnetUptime` (Deprecated) is a map of Subnet IDs to this node's Subnet uptimes, observed by the peer.

**Example Call:**

Expand Down Expand Up @@ -575,7 +573,6 @@ curl -X POST --data '{
"lastReceived": "2020-06-01T15:22:57Z",
"benched": [],
"observedUptime": "99",
"observedSubnetUptimes": {},
"trackedSubnets": [],
"benched": []
},
Expand All @@ -588,9 +585,6 @@ curl -X POST --data '{
"lastReceived": "2020-06-01T15:22:34Z",
"benched": [],
"observedUptime": "75",
"observedSubnetUptimes": {
"29uVeLPJB1eQJkzRemU8g8wZDw5uJRqpab5U2mX9euieVwiEbL": "100"
},
"trackedSubnets": [
"29uVeLPJB1eQJkzRemU8g8wZDw5uJRqpab5U2mX9euieVwiEbL"
],
Expand All @@ -605,7 +599,6 @@ curl -X POST --data '{
"lastReceived": "2020-06-01T15:22:55Z",
"benched": [],
"observedUptime": "95",
"observedSubnetUptimes": {},
"trackedSubnets": [],
"benched": []
}
Expand All @@ -623,18 +616,13 @@ Other sources may be using data gathered with incomplete (limited) information.
**Signature:**

```sh
info.uptime({
subnetID: string // optional
}) ->
info.uptime() ->
{
rewardingStakePercentage: float64,
weightedAveragePercentage: float64
}
```

- `subnetID` (Deprecated) is the Subnet to get the uptime of. If not provided, returns the uptime of the node on
the primary network.

- `rewardingStakePercentage` is the percent of stake which thinks this node is above the uptime
requirement.
- `weightedAveragePercentage` is the stake-weighted average of all observed uptimes for this node.
Expand Down
13 changes: 1 addition & 12 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,6 @@ func (m *manager) createAvalancheChain(
m.FrontierPollFrequency,
m.ConsensusAppConcurrency,
m.ResourceTracker,
validators.UnhandledSubnetConnector, // avalanche chains don't use subnet connector
sb,
connectedValidators,
peerTracker,
Expand Down Expand Up @@ -1107,10 +1106,7 @@ func (m *manager) createSnowmanChain(
messageSender = sender.Trace(messageSender, m.Tracer)
}

var (
bootstrapFunc func()
subnetConnector = validators.UnhandledSubnetConnector
)
var bootstrapFunc func()
// If [m.validatorState] is nil then we are creating the P-Chain. Since the
// P-Chain is the first chain to be created, we can use it to initialize
// required interfaces for the other chains
Expand Down Expand Up @@ -1147,12 +1143,6 @@ func (m *manager) createSnowmanChain(
bootstrapFunc = func() {
close(m.unblockChainCreatorCh)
}

// Set up the subnet connector for the P-Chain
subnetConnector, ok = vm.(validators.SubnetConnector)
if !ok {
return nil, fmt.Errorf("expected validators.SubnetConnector but got %T", vm)
}
}

// Initialize the ProposerVM and the vm wrapped inside it
Expand Down Expand Up @@ -1295,7 +1285,6 @@ func (m *manager) createSnowmanChain(
m.FrontierPollFrequency,
m.ConsensusAppConcurrency,
m.ResourceTracker,
subnetConnector,
sb,
connectedValidators,
peerTracker,
Expand Down
26 changes: 0 additions & 26 deletions message/internal_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,32 +335,6 @@ func InternalConnected(nodeID ids.NodeID, nodeVersion *version.Application) Inbo
}
}

// ConnectedSubnet contains the subnet ID of the subnet that the node is
// connected to.
type ConnectedSubnet struct {
SubnetID ids.ID `json:"subnet_id,omitempty"`
}

func (m *ConnectedSubnet) String() string {
return fmt.Sprintf(
"SubnetID: %s",
m.SubnetID,
)
}

// InternalConnectedSubnet returns a message that indicates the node with [nodeID] is
// connected to the subnet with the given [subnetID].
func InternalConnectedSubnet(nodeID ids.NodeID, subnetID ids.ID) InboundMessage {
return &inboundMessage{
nodeID: nodeID,
op: ConnectedSubnetOp,
message: &ConnectedSubnet{
SubnetID: subnetID,
},
expiration: mockable.MaxTime,
}
}

type Disconnected struct{}

func (Disconnected) String() string {
Expand Down
8 changes: 4 additions & 4 deletions message/messagemock/outbound_message_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions message/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMessage(t *testing.T) {
bytesSaved bool // if true, outbound message saved bytes must be non-zero
}{
{
desc: "ping message with no compression no subnet uptimes",
desc: "ping message with no compression no uptime",
op: PingOp,
msg: &p2p.Message{
Message: &p2p.Message_Ping{
Expand All @@ -78,17 +78,12 @@ func TestMessage(t *testing.T) {
bytesSaved: false,
},
{
desc: "ping message with no compression and subnet uptimes",
desc: "ping message with no compression and uptime",
op: PingOp,
msg: &p2p.Message{
Message: &p2p.Message_Ping{
Ping: &p2p.Ping{
SubnetUptimes: []*p2p.SubnetUptime{
{
SubnetId: testID[:],
Uptime: 100,
},
},
Uptime: 100,
},
},
},
Expand Down
5 changes: 0 additions & 5 deletions message/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const (
AppGossipOp
// Internal:
ConnectedOp
ConnectedSubnetOp
DisconnectedOp
NotifyOp
GossipRequestOp
Expand Down Expand Up @@ -113,7 +112,6 @@ var (
GetFailedOp,
QueryFailedOp,
ConnectedOp,
ConnectedSubnetOp,
DisconnectedOp,
NotifyOp,
GossipRequestOp,
Expand Down Expand Up @@ -151,7 +149,6 @@ var (
ChitsOp,
// Internal
ConnectedOp,
ConnectedSubnetOp,
DisconnectedOp,
}

Expand Down Expand Up @@ -261,8 +258,6 @@ func (op Op) String() string {
// Internal
case ConnectedOp:
return "connected"
case ConnectedSubnetOp:
return "connected_subnet"
case DisconnectedOp:
return "disconnected"
case NotifyOp:
Expand Down
5 changes: 1 addition & 4 deletions message/outbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type OutboundMsgBuilder interface {

Ping(
primaryUptime uint32,
subnetUptimes []*p2p.SubnetUptime,
) (OutboundMessage, error)

Pong() (OutboundMessage, error)
Expand Down Expand Up @@ -200,14 +199,12 @@ func newOutboundBuilder(compressionType compression.Type, builder *msgBuilder) O

func (b *outMsgBuilder) Ping(
primaryUptime uint32,
subnetUptimes []*p2p.SubnetUptime,
) (OutboundMessage, error) {
return b.builder.createOutbound(
&p2p.Message{
Message: &p2p.Message_Ping{
Ping: &p2p.Ping{
Uptime: primaryUptime,
SubnetUptimes: subnetUptimes,
Uptime: primaryUptime,
},
},
},
Expand Down
58 changes: 19 additions & 39 deletions network/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@ type metrics struct {
// trackedSubnets does not include the primary network ID
trackedSubnets set.Set[ids.ID]

numTracked prometheus.Gauge
numPeers prometheus.Gauge
numSubnetPeers *prometheus.GaugeVec
timeSinceLastMsgSent prometheus.Gauge
timeSinceLastMsgReceived prometheus.Gauge
sendFailRate prometheus.Gauge
connected prometheus.Counter
disconnected prometheus.Counter
acceptFailed prometheus.Counter
inboundConnRateLimited prometheus.Counter
inboundConnAllowed prometheus.Counter
tlsConnRejected prometheus.Counter
numUselessPeerListBytes prometheus.Counter
nodeUptimeWeightedAverage prometheus.Gauge
nodeUptimeRewardingStake prometheus.Gauge
nodeSubnetUptimeWeightedAverage *prometheus.GaugeVec // Deprecated
nodeSubnetUptimeRewardingStake *prometheus.GaugeVec // Deprecated
peerConnectedLifetimeAverage prometheus.Gauge
lock sync.RWMutex
peerConnectedStartTimes map[ids.NodeID]float64
peerConnectedStartTimesSum float64
numTracked prometheus.Gauge
numPeers prometheus.Gauge
numSubnetPeers *prometheus.GaugeVec
timeSinceLastMsgSent prometheus.Gauge
timeSinceLastMsgReceived prometheus.Gauge
sendFailRate prometheus.Gauge
connected prometheus.Counter
disconnected prometheus.Counter
acceptFailed prometheus.Counter
inboundConnRateLimited prometheus.Counter
inboundConnAllowed prometheus.Counter
tlsConnRejected prometheus.Counter
numUselessPeerListBytes prometheus.Counter
nodeUptimeWeightedAverage prometheus.Gauge
nodeUptimeRewardingStake prometheus.Gauge
peerConnectedLifetimeAverage prometheus.Gauge
lock sync.RWMutex
peerConnectedStartTimes map[ids.NodeID]float64
peerConnectedStartTimesSum float64
}

func newMetrics(
Expand Down Expand Up @@ -111,20 +109,6 @@ func newMetrics(
Name: "node_uptime_rewarding_stake",
Help: "The percentage of total stake which thinks this node is eligible for rewards",
}),
nodeSubnetUptimeWeightedAverage: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "node_subnet_uptime_weighted_average",
Help: "This node's subnet uptime averages weighted by observing subnet peer stakes",
},
[]string{"subnetID"},
),
nodeSubnetUptimeRewardingStake: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "node_subnet_uptime_rewarding_stake",
Help: "The percentage of subnet's total stake which thinks this node is eligible for subnet's rewards",
},
[]string{"subnetID"},
),
peerConnectedLifetimeAverage: prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "peer_connected_duration_average",
Expand All @@ -150,8 +134,6 @@ func newMetrics(
registerer.Register(m.inboundConnRateLimited),
registerer.Register(m.nodeUptimeWeightedAverage),
registerer.Register(m.nodeUptimeRewardingStake),
registerer.Register(m.nodeSubnetUptimeWeightedAverage),
registerer.Register(m.nodeSubnetUptimeRewardingStake),
registerer.Register(m.peerConnectedLifetimeAverage),
)

Expand All @@ -160,8 +142,6 @@ func newMetrics(
// initialize to 0
subnetIDStr := subnetID.String()
m.numSubnetPeers.WithLabelValues(subnetIDStr).Set(0)
m.nodeSubnetUptimeWeightedAverage.WithLabelValues(subnetIDStr).Set(0)
m.nodeSubnetUptimeRewardingStake.WithLabelValues(subnetIDStr).Set(0)
}

return m, err
Expand Down
Loading

0 comments on commit c55a011

Please sign in to comment.