Skip to content

Commit

Permalink
client/asset/{btc,dcr}: broadcast async
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chappjc committed Nov 15, 2021
1 parent 6f3989c commit 2e4fe26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
15 changes: 9 additions & 6 deletions client/asset/btc/btc.go
Expand Up @@ -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)),
Expand Down
18 changes: 10 additions & 8 deletions client/asset/dcr/dcr.go
Expand Up @@ -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{
Expand Down

0 comments on commit 2e4fe26

Please sign in to comment.