From 2e4fe260b078fa5cb5557b7824bd36aa42ebd8e7 Mon Sep 17 00:00:00 2001 From: Jonathan Chappelow Date: Wed, 10 Nov 2021 17:55:27 -0600 Subject: [PATCH] client/asset/{btc,dcr}: broadcast async Broadcasting the counterparty swap transaction in AuditContract is not required to pass the audit, yet for SPV wallets it can be quite slow. As such, just broadcast in a goroutine so the AuditInfo return can be recorded as soon as possible. --- client/asset/btc/btc.go | 15 +++++++++------ client/asset/dcr/dcr.go | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/client/asset/btc/btc.go b/client/asset/btc/btc.go index e597809292..516e21172b 100644 --- a/client/asset/btc/btc.go +++ b/client/asset/btc/btc.go @@ -1887,12 +1887,15 @@ func (btc *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes, sin contractHash, addr.ScriptAddress()) } - // Broadcast the transaction. - if hashSent, err := btc.node.sendRawTransaction(tx); err != nil { - btc.log.Debugf("Rebroadcasting counterparty contract %v (THIS MAY BE NORMAL): %v", txHash, err) - } else if !hashSent.IsEqual(txHash) { - btc.log.Errorf("Counterparty contract %v was rebroadcast as %v!", txHash, hashSent) - } + // Broadcast the transaction, but do not block because this is not required + // and does not affect the audit result. + go func() { + if hashSent, err := btc.node.sendRawTransaction(tx); err != nil { + btc.log.Debugf("Rebroadcasting counterparty contract %v (THIS MAY BE NORMAL): %v", txHash, err) + } else if !hashSent.IsEqual(txHash) { + btc.log.Errorf("Counterparty contract %v was rebroadcast as %v!", txHash, hashSent) + } + }() return &asset.AuditInfo{ Coin: newOutput(txHash, vout, uint64(txOut.Value)), diff --git a/client/asset/dcr/dcr.go b/client/asset/dcr/dcr.go index 04afe63606..5471460a7c 100644 --- a/client/asset/dcr/dcr.go +++ b/client/asset/dcr/dcr.go @@ -1546,14 +1546,16 @@ func (dcr *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes, _ t contractHash, addrScript) } - // The counter-party should have broadcasted the contract tx but - // rebroadcast just in case to ensure that the tx is sent to the - // network. - if hashSent, err := dcr.wallet.SendRawTransaction(dcr.ctx, contractTx, true); err != nil { - dcr.log.Debugf("Rebroadcasting counterparty contract %v (THIS MAY BE NORMAL): %v", txHash, err) - } else if !hashSent.IsEqual(txHash) { - dcr.log.Errorf("Counterparty contract %v was rebroadcast as %v!", txHash, hashSent) - } + // The counter-party should have broadcasted the contract tx but rebroadcast + // just in case to ensure that the tx is sent to the network. Do not block + // because this is not required and does not affect the audit result. + go func() { + if hashSent, err := dcr.wallet.SendRawTransaction(dcr.ctx, contractTx, true); err != nil { + dcr.log.Debugf("Rebroadcasting counterparty contract %v (THIS MAY BE NORMAL): %v", txHash, err) + } else if !hashSent.IsEqual(txHash) { + dcr.log.Errorf("Counterparty contract %v was rebroadcast as %v!", txHash, hashSent) + } + }() txTree := determineTxTree(contractTx) return &asset.AuditInfo{