From 97e7b01afe1e2931048b177ab6b29dc3029e5b25 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Thu, 7 Sep 2023 15:46:49 +0100 Subject: [PATCH] vspd: Enable blockConnected interrupting. Check the status of the Context in blockConnected so it can be canceled when a shutdown is requested. --- cmd/vspd/vspd.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/vspd/vspd.go b/cmd/vspd/vspd.go index fb36572..e806ff2 100644 --- a/cmd/vspd/vspd.go +++ b/cmd/vspd/vspd.go @@ -369,6 +369,11 @@ func (v *vspd) blockConnected(ctx context.Context) { } for _, ticket := range unconfirmed { + // Exit early if context has been cancelled. + if ctx.Err() != nil { + return + } + tktTx, err := dcrdClient.GetRawTransaction(ticket.Hash) if err != nil { // ErrNoTxInfo here probably indicates a tx which was never mined @@ -423,6 +428,11 @@ func (v *vspd) blockConnected(ctx context.Context) { } for _, ticket := range pending { + // Exit early if context has been cancelled. + if ctx.Err() != nil { + return + } + err = dcrdClient.SendRawTransaction(ticket.FeeTxHex) if err != nil { v.log.Errorf("%s: dcrd.SendRawTransaction for fee tx failed (ticketHash=%s): %v", @@ -459,6 +469,11 @@ func (v *vspd) blockConnected(ctx context.Context) { } for _, ticket := range unconfirmedFees { + // Exit early if context has been cancelled. + if ctx.Err() != nil { + return + } + feeTx, err := dcrdClient.GetRawTransaction(ticket.FeeTxHash) if err != nil { v.log.Errorf("%s: dcrd.GetRawTransaction for fee tx failed (feeTxHash=%s, ticketHash=%s): %v", @@ -584,6 +599,11 @@ func (v *vspd) blockConnected(ctx context.Context) { v.lastScannedBlock = endHeight for _, spentTicket := range spent { + // Exit early if context has been cancelled. + if ctx.Err() != nil { + return + } + dbTicket := spentTicket.dbTicket switch {