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

Accumulated minor nits and fixes. #446

Merged
merged 8 commits into from
Sep 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
10 changes: 8 additions & 2 deletions cmd/v3tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/decred/slog"
"github.com/decred/vspd/client/v3"
"github.com/decred/vspd/internal/config"
"github.com/decred/vspd/internal/signal"
"github.com/decred/vspd/types/v2"
)
Expand Down Expand Up @@ -164,7 +165,12 @@ func run() int {
return 1
}

voteChoices := map[string]string{"autorevocations": "no"}
// Grab an agenda ID from the current vote version.
network := config.TestNet3
voteVersion := network.CurrentVoteVersion()
agendaID := network.Deployments[voteVersion][0].Vote.Id

voteChoices := map[string]string{agendaID: "no"}
tspend := map[string]string{
"6c78690fa2fa31803df0376897725704e9dc19ecbdf80061e79b69de93ca1360": "no",
"abb86660dda1f1b66544bab24a823a22e9213ada48649f0d913623f49e17dacb": "yes",
Expand Down Expand Up @@ -206,7 +212,7 @@ func run() int {
return 1
}

voteChoices["autorevocations"] = "yes"
voteChoices[agendaID] = "yes"

// Sleep to ensure a new timestamp. vspd will reject old/reused timestamps.
time.Sleep(1001 * time.Millisecond)
Expand Down
24 changes: 12 additions & 12 deletions cmd/vspd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func run() int {

log := cfg.logger("VSP")

// Create a context that is canceled when a shutdown request is received
// through an interrupt signal such as SIGINT (Ctrl+C).
ctx := signal.ShutdownListener(log)

defer log.Criticalf("Shutdown complete")
log.Criticalf("Version %s (Go version %s %s/%s)", version.String(),
runtime.Version(), runtime.GOOS, runtime.GOARCH)
Expand Down Expand Up @@ -105,34 +109,30 @@ func run() int {
}

// WaitGroup for services to signal when they have shutdown cleanly.
var shutdownWg sync.WaitGroup

// Create a context that is canceled when a shutdown request is received
// through an interrupt signal such as SIGINT (Ctrl+C).
ctx := signal.ShutdownListener(log)
var wg sync.WaitGroup

// Start the webapi server.
shutdownWg.Add(1)
wg.Add(1)
go func() {
api.Run(ctx)
shutdownWg.Done()
wg.Done()
}()

// Start vspd.
vspd := vspd.New(cfg.network, log, db, dcrd, wallets, blockNotifChan)
shutdownWg.Add(1)
wg.Add(1)
go func() {
vspd.Run(ctx)
shutdownWg.Done()
wg.Done()
}()

// Periodically write a database backup file.
shutdownWg.Add(1)
wg.Add(1)
go func() {
for {
select {
case <-ctx.Done():
shutdownWg.Done()
wg.Done()
return
case <-time.After(cfg.BackupInterval):
err := db.WriteHotBackupFile()
Expand All @@ -145,7 +145,7 @@ func run() int {

// Wait for shutdown tasks to complete before running deferred tasks and
// returning.
shutdownWg.Wait()
wg.Wait()

return 0
}
2 changes: 1 addition & 1 deletion database/votechange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func exampleRecord() VoteChangeRecord {
}

func testVoteChangeRecords(t *testing.T) {
hash := "MyHash"
const hash = "MyHash"
record := exampleRecord()

// Insert a record into the database.
Expand Down
2 changes: 1 addition & 1 deletion docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ configuration. A 200 HTTP status will be returned if the VSP seems
healthy, or a 500 status will be used to indicate something is wrong.

```bash
$ curl --user admin:12345 --request GET http://localhost:8800/admin/status
$ curl --user admin:12345 http://localhost:8800/admin/status
```

```json
Expand Down
8 changes: 5 additions & 3 deletions internal/vspd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"github.com/jrick/wsrpc/v2"
)

// update is called once when vspd starts up, and once each time a
// blockconnected notification is received from dcrd.
// update uses the latest available information from dcrd to update all of the
// data in the vspd database. When appropriate it will also broadcast pending
// fee transactions and add tickets to voting wallets.
func (v *Vspd) update(ctx context.Context) {
const funcName = "update"

Expand Down Expand Up @@ -44,7 +45,8 @@ func (v *Vspd) update(ctx context.Context) {
return
}

// Step 4/4: Set ticket outcome in database if any tickets are voted/revoked.
// Step 4/4: Set ticket outcome in database if any tickets are
// voted/revoked.
v.setOutcomes(ctx, dcrdClient)
if ctx.Err() != nil {
return
Expand Down
4 changes: 2 additions & 2 deletions internal/webapi/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (w *WebAPI) dcrdStatus(c *gin.Context) dcrdStatus {
dcrdClient := c.MustGet(dcrdKey).(*rpc.DcrdRPC)
dcrdErr := c.MustGet(dcrdErrorKey)
if dcrdErr != nil {
w.log.Errorf("Could not get dcrd client: %v", dcrdErr.(error))
w.log.Errorf("%v", dcrdErr.(error))
return status
}

Expand Down Expand Up @@ -190,7 +190,7 @@ func (w *WebAPI) ticketSearch(c *gin.Context) {
dcrdClient := c.MustGet(dcrdKey).(*rpc.DcrdRPC)
dcrdErr := c.MustGet(dcrdErrorKey)
if dcrdErr != nil {
w.log.Errorf("Could not get dcrd client: %v", dcrdErr.(error))
w.log.Errorf("%v", dcrdErr.(error))
c.String(http.StatusInternalServerError, "Could not get dcrd client")
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/webapi/getfeeaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (w *WebAPI) feeAddress(c *gin.Context) {
dcrdClient := c.MustGet(dcrdKey).(*rpc.DcrdRPC)
dcrdErr := c.MustGet(dcrdErrorKey)
if dcrdErr != nil {
w.log.Errorf("%s: Could not get dcrd client: %v", funcName, dcrdErr.(error))
w.log.Errorf("%s: %v", funcName, dcrdErr.(error))
w.sendError(types.ErrInternalError, c)
return
}
Expand Down
8 changes: 4 additions & 4 deletions internal/webapi/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func TestIsValidVoteChoices(t *testing.T) {
func TestIsValidTSpendPolicy(t *testing.T) {

// A valid tspend hash is 32 bytes (64 characters).
validHash := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
anotherValidHash := "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
const validHash = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
const anotherValidHash = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"

var tests = []struct {
tspendPolicy map[string]string
Expand Down Expand Up @@ -102,8 +102,8 @@ func TestIsValidTSpendPolicy(t *testing.T) {
func TestIsValidTreasuryPolicy(t *testing.T) {

// A valid treasury key is 33 bytes (66 characters).
validKey := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
anotherValidKey := "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
const validKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
const anotherValidKey = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"

var tests = []struct {
treasuryPolicy map[string]string
Expand Down
2 changes: 1 addition & 1 deletion internal/webapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (w *WebAPI) broadcastTicket(c *gin.Context) {
dcrdClient := c.MustGet(dcrdKey).(*rpc.DcrdRPC)
dcrdErr := c.MustGet(dcrdErrorKey)
if dcrdErr != nil {
w.log.Errorf("%s: Could not get dcrd client: %v", funcName, dcrdErr.(error))
w.log.Errorf("%s: %v", funcName, dcrdErr.(error))
w.sendError(types.ErrInternalError, c)
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/webapi/payfee.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (w *WebAPI) payFee(c *gin.Context) {
dcrdClient := c.MustGet(dcrdKey).(*rpc.DcrdRPC)
dcrdErr := c.MustGet(dcrdErrorKey)
if dcrdErr != nil {
w.log.Errorf("%s: Could not get dcrd client: %v", funcName, dcrdErr.(error))
w.log.Errorf("%s: %v", funcName, dcrdErr.(error))
w.sendError(types.ErrInternalError, c)
return
}
Expand Down
1 change: 0 additions & 1 deletion internal/webapi/public/css/vspd.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ html, body {
height: 100%;
}
body {
overflow-y: overlay;
background-color: #F3F5F6;
color: #3D5873;
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions internal/webapi/setaltsignaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (w *WebAPI) setAltSignAddr(c *gin.Context) {
dcrdClient := c.MustGet(dcrdKey).(node)
dcrdErr := c.MustGet(dcrdErrorKey)
if dcrdErr != nil {
w.log.Errorf("%s: Could not get dcrd client: %v", funcName, dcrdErr.(error))
w.log.Errorf("%s: %v", funcName, dcrdErr.(error))
w.sendError(types.ErrInternalError, c)
return
}
Expand All @@ -56,7 +56,7 @@ func (w *WebAPI) setAltSignAddr(c *gin.Context) {
return
}
if currentData != nil {
msg := "alternate sign address data already exists"
const msg = "alternate sign address data already exists"
w.log.Warnf("%s: %s (ticketHash=%s)", funcName, msg, ticketHash)
w.sendErrorWithMsg(msg, types.ErrBadRequest, c)
return
Expand Down
Loading