From 010947a222402879059613870c73a202966cb40d Mon Sep 17 00:00:00 2001 From: Jamie Holdstock Date: Thu, 26 Oct 2023 14:39:08 +0100 Subject: [PATCH] Handle expired/missed ticket counts from VSPs. (#180) * Use go 1.21 & update build tools. * Handle expired/missed ticket counts from VSPs. --- .github/workflows/docker.yml | 2 +- .github/workflows/go.yml | 8 ++++---- Dockerfile | 2 +- docs/api.md | 4 +++- service.go | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 019202d..7ad337b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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) . diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8a06fba..c3f7d59 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 24af396..a29b18d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 . . diff --git a/docs/api.md b/docs/api.md index 2ed1fbd..e1760f2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -26,7 +26,9 @@ Example: "closed": false, "voting": 3935, "voted": 57073, - "revoked": 83 + "revoked": 83, + "expired": 73, + "missed": 10, }, } ``` diff --git a/service.go b/service.go index e677c6a..8e6ae4a 100644 --- a/service.go +++ b/service.go @@ -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"` @@ -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"] @@ -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()