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:
parent
4cca23264d
commit
1121b0c48b
12
server.go
12
server.go
@ -1579,6 +1579,7 @@ func (s *server) OpenChannel(peerID int32, nodeKey *btcec.PublicKey,
|
|||||||
var (
|
var (
|
||||||
targetPeer *peer
|
targetPeer *peer
|
||||||
pubKeyBytes []byte
|
pubKeyBytes []byte
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
// If the user is targeting the peer by public key, then we'll need to
|
// 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.
|
// is what's used internally when deciding upon coin selection.
|
||||||
fundingFeePerWeight := fundingFeePerByte / blockchain.WitnessScaleFactor
|
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
|
// Spawn a goroutine to send the funding workflow request to the
|
||||||
// funding manager. This allows the server to continue handling queries
|
// funding manager. This allows the server to continue handling queries
|
||||||
// instead of blocking on this request which is exported as a
|
// instead of blocking on this request which is exported as a
|
||||||
|
Loading…
Reference in New Issue
Block a user