vspd: Enable blockConnected interrupting.

Check the status of the Context in blockConnected so it can be canceled
when a shutdown is requested.
This commit is contained in:
jholdstock 2023-09-07 15:46:49 +01:00 committed by Jamie Holdstock
parent ad7c587699
commit 97e7b01afe

View File

@ -369,6 +369,11 @@ func (v *vspd) blockConnected(ctx context.Context) {
} }
for _, ticket := range unconfirmed { for _, ticket := range unconfirmed {
// Exit early if context has been cancelled.
if ctx.Err() != nil {
return
}
tktTx, err := dcrdClient.GetRawTransaction(ticket.Hash) tktTx, err := dcrdClient.GetRawTransaction(ticket.Hash)
if err != nil { if err != nil {
// ErrNoTxInfo here probably indicates a tx which was never mined // 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 { for _, ticket := range pending {
// Exit early if context has been cancelled.
if ctx.Err() != nil {
return
}
err = dcrdClient.SendRawTransaction(ticket.FeeTxHex) err = dcrdClient.SendRawTransaction(ticket.FeeTxHex)
if err != nil { if err != nil {
v.log.Errorf("%s: dcrd.SendRawTransaction for fee tx failed (ticketHash=%s): %v", 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 { for _, ticket := range unconfirmedFees {
// Exit early if context has been cancelled.
if ctx.Err() != nil {
return
}
feeTx, err := dcrdClient.GetRawTransaction(ticket.FeeTxHash) feeTx, err := dcrdClient.GetRawTransaction(ticket.FeeTxHash)
if err != nil { if err != nil {
v.log.Errorf("%s: dcrd.GetRawTransaction for fee tx failed (feeTxHash=%s, ticketHash=%s): %v", 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 v.lastScannedBlock = endHeight
for _, spentTicket := range spent { for _, spentTicket := range spent {
// Exit early if context has been cancelled.
if ctx.Err() != nil {
return
}
dbTicket := spentTicket.dbTicket dbTicket := spentTicket.dbTicket
switch { switch {