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

webapi: Wait for unknown outputs to propagate. #455

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
35 changes: 31 additions & 4 deletions internal/webapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,37 @@ func (w *WebAPI) broadcastTicket(c *gin.Context) {
w.log.Debugf("%s: Broadcasting parent tx %s (ticketHash=%s)", funcName, parentHash, request.TicketHash)
err = dcrdClient.SendRawTransaction(request.ParentHex)
if err != nil {
w.log.Errorf("%s: dcrd.SendRawTransaction for parent tx failed (ticketHash=%s): %v",
funcName, request.TicketHash, err)
w.sendError(types.ErrCannotBroadcastTicket, c)
return
// Unknown output errors have special handling because they
// could be resolved by waiting for network propagation. Any
// other errors are returned to client immediately.
if !strings.Contains(err.Error(), rpc.ErrUnknownOutputs) {
w.log.Errorf("%s: dcrd.SendRawTransaction for parent tx failed (ticketHash=%s): %v",
funcName, request.TicketHash, err)
w.sendError(types.ErrCannotBroadcastTicket, c)
return
}

w.log.Debugf("%s: Parent tx references an unknown output, waiting for it in mempool (ticketHash=%s)",
funcName, request.TicketHash)

txBroadcast := func() bool {
// Wait for 1 second and try again, max 7 attempts.
for i := 0; i < 7; i++ {
time.Sleep(1 * time.Second)
err := dcrdClient.SendRawTransaction(request.ParentHex)
if err == nil {
return true
}
}
return false
}()

if !txBroadcast {
w.log.Errorf("%s: Failed to broadcast parent tx, waiting didn't help (ticketHash=%s)",
funcName, request.TicketHash)
w.sendError(types.ErrCannotBroadcastTicket, c)
return
}
}

} else {
Expand Down
Loading