Skip to content

Commit

Permalink
vspd: Enable checkWalletConsistency interrupting.
Browse files Browse the repository at this point in the history
Add a Context parameter to checkWalletConsistency so it can be canceled
when a shutdown is requested.
  • Loading branch information
jholdstock committed Sep 7, 2023
1 parent 11778d8 commit 8e00739
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/vspd/vspd.go
Expand Up @@ -148,7 +148,7 @@ func (v *vspd) run() int {

// Run voting wallet consistency check now to ensure all wallets are up to
// date.
v.checkWalletConsistency()
v.checkWalletConsistency(ctx)

// Stop if shutdown requested.
if ctx.Err() != nil {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (v *vspd) run() int {

// Run voting wallet consistency check periodically.
case <-consistencyTicker.C:
v.checkWalletConsistency()
v.checkWalletConsistency(ctx)

// Ensure dcrd client is connected so notifications are received.
case <-dcrdTicker.C:
Expand Down Expand Up @@ -630,7 +630,7 @@ func (v *vspd) blockConnected(ctx context.Context) {
// checkWalletConsistency will retrieve all votable tickets from the database
// and ensure they are all added to voting wallets with the correct vote
// choices.
func (v *vspd) checkWalletConsistency() {
func (v *vspd) checkWalletConsistency(ctx context.Context) {
const funcName = "checkWalletConsistency"

v.log.Info("Checking voting wallet consistency")
Expand Down Expand Up @@ -669,6 +669,11 @@ func (v *vspd) checkWalletConsistency() {

// Iterate over each wallet and add any missing tickets.
for _, walletClient := range walletClients {
// Exit early if context has been cancelled.
if ctx.Err() != nil {
return
}

// Get all tickets the wallet is aware of.
walletTickets, err := walletClient.TicketInfo(oldestHeight)
if err != nil {
Expand Down Expand Up @@ -727,6 +732,11 @@ func (v *vspd) checkWalletConsistency() {
// all wallets.

for _, walletClient := range walletClients {
// Exit early if context has been cancelled.
if ctx.Err() != nil {
return
}

// Get all tickets the wallet is aware of.
walletTickets, err := walletClient.TicketInfo(oldestHeight)
if err != nil {
Expand All @@ -736,6 +746,11 @@ func (v *vspd) checkWalletConsistency() {
}

for _, dbTicket := range votableTickets {
// Exit early if context has been cancelled.
if ctx.Err() != nil {
return
}

// All tickets should be added to all wallets at this point, so log
// a warning if any are still missing.
walletTicket, exists := walletTickets[dbTicket.Hash]
Expand Down

0 comments on commit 8e00739

Please sign in to comment.