From f9d22cd90035851c0ef2e75ecc44cc8878fbe124 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 31 Oct 2019 20:56:50 -0700 Subject: [PATCH] funding: only broadcast the funding transaction if we actually have it --- fundingmanager.go | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 189eda49..760687fd 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -521,8 +521,9 @@ func (f *fundingManager) start() error { // Rebroadcast the funding transaction for any pending // channel that we initiated. No error will be returned - // if the transaction already has been broadcasted. - if channel.ChanType.IsSingleFunder() && + // if the transaction already has been broadcast. + chanType := channel.ChanType + if chanType.IsSingleFunder() && chanType.HasFundingTx() && channel.IsInitiator { err := f.cfg.PublishTransaction( @@ -1739,21 +1740,28 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { // delete it from our set of active reservations. f.deleteReservationCtx(peerKey, pendingChanID) - // Broadcast the finalized funding transaction to the network. - fundingTx := completeChan.FundingTxn - fndgLog.Infof("Broadcasting funding tx for ChannelPoint(%v): %v", - completeChan.FundingOutpoint, spew.Sdump(fundingTx)) + // Broadcast the finalized funding transaction to the network, but only + // if we actually have the funding transaction. + if completeChan.ChanType.HasFundingTx() { + fundingTx := completeChan.FundingTxn - err = f.cfg.PublishTransaction(fundingTx) - if err != nil { - fndgLog.Errorf("Unable to broadcast funding tx for "+ - "ChannelPoint(%v): %v", completeChan.FundingOutpoint, - err) - // We failed to broadcast the funding transaction, but watch - // the channel regardless, in case the transaction made it to - // the network. We will retry broadcast at startup. - // TODO(halseth): retry more often? Handle with CPFP? Just - // delete from the DB? + fndgLog.Infof("Broadcasting funding tx for ChannelPoint(%v): %v", + completeChan.FundingOutpoint, spew.Sdump(fundingTx)) + + err = f.cfg.PublishTransaction(fundingTx) + if err != nil { + fndgLog.Errorf("Unable to broadcast funding tx for "+ + "ChannelPoint(%v): %v", + completeChan.FundingOutpoint, err) + + // We failed to broadcast the funding transaction, but + // watch the channel regardless, in case the + // transaction made it to the network. We will retry + // broadcast at startup. + // + // TODO(halseth): retry more often? Handle with CPFP? + // Just delete from the DB? + } } // Now that we have a finalized reservation for this funding flow,