From f588def54187c36608903ba6f43c9b7e88d6c30a Mon Sep 17 00:00:00 2001 From: jholdstock Date: Tue, 26 Sep 2023 16:50:02 +0100 Subject: [PATCH 1/2] Use go 1.21 & update build tools. --- .github/workflows/docker.yml | 2 +- .github/workflows/go.yml | 8 ++++---- Dockerfile | 2 +- 3 files changed, 6 insertions(+), 6 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 . . From ada5b931b7a536720f04888a437392a498eec3de Mon Sep 17 00:00:00 2001 From: jholdstock Date: Tue, 26 Sep 2023 16:50:25 +0100 Subject: [PATCH 2/2] Handle expired/missed ticket counts from VSPs. --- docs/api.md | 4 +++- service.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 4bb9e15..ebf4778 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()