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.
This commit is contained in:
Olaoluwa Osuntokun 2017-12-12 17:47:31 -08:00
parent 4cca23264d
commit 1121b0c48b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -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