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

Handle expired/missed ticket counts from VSPs. #180

Merged
merged 2 commits into from
Oct 26, 2023
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 .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 #v4.1.0
- name: Build the Docker image
run: docker build -t decred/dcrwebapi:$(date +%s) .

8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.19", "1.20"]
go: ["1.20", "1.21"]
steps:
- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 #v4.0.1
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe #v4.1.0
with:
go-version: ${{ matrix.go }}
- name: Check out source
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 #v4.1.0
- name: Install Linters
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3"
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2"
- name: Build
run: go build ./...
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build
FROM golang:1.20-alpine AS builder
FROM golang:1.21-alpine AS builder

WORKDIR $GOPATH/src/github.com/decred/dcrwebapi
COPY . .
Expand Down
4 changes: 3 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Example: <https://api.decred.org/?c=vsp>
"closed": false,
"voting": 3935,
"voted": 57073,
"revoked": 83
"revoked": 83,
"expired": 73,
"missed": 10,
},
}
```
16 changes: 16 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Vsp struct {
Voting int64 `json:"voting"`
Voted int64 `json:"voted"`
Revoked int64 `json:"revoked"`
Expired int64 `json:"expired"`
Missed int64 `json:"missed"`
VspdVersion string `json:"vspdversion"`
BlockHeight uint64 `json:"blockheight"`
EstimatedNetworkProportion float64 `json:"estimatednetworkproportion"`
Expand Down Expand Up @@ -204,6 +206,8 @@ func vspStats(service *Service, url string) error {
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"]
Expand All @@ -230,6 +234,18 @@ func vspStats(service *Service, url string) error {
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
Loading