From 1121b0c48b8eb0c4d7a2cdbca1aaa6cdb5a46153 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 12 Dec 2017 17:47:31 -0800 Subject: [PATCH] server+funding: fix bug where funding tx could have zero fees attached In this commit, we fix an existing bug that would cause funding transaction to be broadcast without any fees attached at all. This is only an issue if the fee rate reported is extremely so, as can happen on testnet. In this case, when we went to scale down to sat/weight, we would return a value of zero due to integer division. If we went via the EstimateFeePerWeight call directly, then it would've been detected. However, we accept the fee/byte from the user directly on the command line this wasn't being done. To fix this, we'll now manually set the fee to a sane value, if it returns a value that can't properly be scaled to fee/weight. --- server.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.go b/server.go index a888c2e91..8d2429eb0 100644 --- a/server.go +++ b/server.go @@ -1579,6 +1579,7 @@ func (s *server) OpenChannel(peerID int32, nodeKey *btcec.PublicKey, var ( targetPeer *peer pubKeyBytes []byte + err error ) // If the user is targeting the peer by public key, then we'll need to @@ -1608,6 +1609,17 @@ func (s *server) OpenChannel(peerID int32, nodeKey *btcec.PublicKey, // is what's used internally when deciding upon coin selection. fundingFeePerWeight := fundingFeePerByte / blockchain.WitnessScaleFactor + // If the fee rate wasn't high enough to cleanly convert to weight, + // then we'll use a default confirmation target. + if fundingFeePerWeight == 0 { + estimator := s.cc.feeEstimator + fundingFeePerWeight, err = estimator.EstimateFeePerWeight(6) + if err != nil { + errChan <- err + return updateChan, errChan + } + } + // Spawn a goroutine to send the funding workflow request to the // funding manager. This allows the server to continue handling queries // instead of blocking on this request which is exported as a