webapi: Wait for unknown outputs to propagate.
If broadcasting parent transaction of a ticket fails because it references unknown outputs, there is a good chance that waiting a few seconds will resolve the issue because the ancestor transactions will propagate through the network and reach the mempool of the local dcrd instance.
This commit is contained in:
parent
9ee95f98ab
commit
34cd9d2892
@ -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)
|
w.log.Debugf("%s: Broadcasting parent tx %s (ticketHash=%s)", funcName, parentHash, request.TicketHash)
|
||||||
err = dcrdClient.SendRawTransaction(request.ParentHex)
|
err = dcrdClient.SendRawTransaction(request.ParentHex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.log.Errorf("%s: dcrd.SendRawTransaction for parent tx failed (ticketHash=%s): %v",
|
// Unknown output errors have special handling because they
|
||||||
funcName, request.TicketHash, err)
|
// could be resolved by waiting for network propagation. Any
|
||||||
w.sendError(types.ErrCannotBroadcastTicket, c)
|
// other errors are returned to client immediately.
|
||||||
return
|
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 {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user