Skip to content

Commit

Permalink
Don't expect VSPs to have "revoked". (#198)
Browse files Browse the repository at this point in the history
This was deprecated in vspd 1.2 and removed in 1.3.
  • Loading branch information
jholdstock authored Jan 8, 2025
1 parent 11a37a4 commit db79ec4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
1 change: 0 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Example: <https://api.decred.org/?c=vsp>
"closed": false,
"voting": 3935,
"voted": 57073,
"revoked": 83,
"expired": 73,
"missed": 10,
},
Expand Down
23 changes: 5 additions & 18 deletions service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2024 The Decred developers
// Copyright (c) 2017-2025 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -33,7 +33,6 @@ type Vsp struct {
Closed bool `json:"closed"`
Voting int64 `json:"voting"`
Voted int64 `json:"voted"`
Revoked int64 `json:"revoked"`
Expired int64 `json:"expired"`
Missed int64 `json:"missed"`
VspdVersion string `json:"vspdversion"`
Expand Down Expand Up @@ -230,16 +229,15 @@ func vspStats(service *Service, url string) error {
vspclosed, hasClosed := info["vspclosed"]
voting, hasVoting := info["voting"]
voted, hasVoted := info["voted"]
revoked, hasRevoked := info["revoked"]
expired, hasExpired := info["expired"]
missed, hasMissed := info["missed"]
version, hasVersion := info["vspdversion"]
blockheight, hasBlockHeight := info["blockheight"]
networkproportion, hasnetworkproportion := info["estimatednetworkproportion"]

hasRequiredFields := hasAPIVersions && hasFeePercentage &&
hasClosed && hasVoting && hasVoted && hasRevoked && hasVersion &&
hasBlockHeight && hasnetworkproportion
hasClosed && hasVoting && hasVoted && hasExpired && hasMissed &&
hasVersion && hasBlockHeight && hasnetworkproportion

if !hasRequiredFields {
return fmt.Errorf("%v: missing required fields: %+v", infoURL, info)
Expand All @@ -254,23 +252,12 @@ func vspStats(service *Service, url string) error {
vsp.Closed = vspclosed.(bool)
vsp.Voting = int64(voting.(float64))
vsp.Voted = int64(voted.(float64))
vsp.Revoked = int64(revoked.(float64))
vsp.Expired = int64(expired.(float64))
vsp.Missed = int64(missed.(float64))
vsp.VspdVersion = version.(string)
vsp.BlockHeight = uint64(blockheight.(float64))
vsp.EstimatedNetworkProportion = networkproportion.(float64)

// Expired and Missed were introduced in vspd 1.3.0 so they will be absent
// from the responses received from older versions. When every VSP is
// updated to 1.3.0+ these fields can be treated like every other required
// field.
if hasExpired {
vsp.Expired = int64(expired.(float64))
}

if hasMissed {
vsp.Missed = int64(missed.(float64))
}

vsp.LastUpdated = time.Now().Unix()

service.Mutex.Lock()
Expand Down

0 comments on commit db79ec4

Please sign in to comment.