Merge pull request #1644 from wpaulino/kw-fees

multi: switch to sat/kw fees
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2018-08-09 20:19:28 -07:00
commit d2612e51bd
28 files changed
+408 -446

No files matched your search

+24 -23
View File
@@ -81,9 +81,9 @@ type initFundingReserveMsg struct {
// paying some multiple of the accepted base fee rate of the network.
commitFeePerKw SatPerKWeight
// fundingFeePerVSize is the fee rate in sat/vbyte to use for the
// initial funding transaction.
fundingFeePerVSize SatPerVByte
// fundingFeePerKw is the fee rate in sat/kw to use for the initial
// funding transaction.
fundingFeePerKw SatPerKWeight
// pushMSat is the number of milli-satoshis that should be pushed over
// the responder as part of the initial channel creation.
@@ -413,7 +413,7 @@ out:
// commitment transaction is valid.
func (l *LightningWallet) InitChannelReservation(
capacity, ourFundAmt btcutil.Amount, pushMSat lnwire.MilliSatoshi,
commitFeePerKw SatPerKWeight, fundingFeePerVSize SatPerVByte,
commitFeePerKw SatPerKWeight, fundingFeePerKw SatPerKWeight,
theirID *btcec.PublicKey, theirAddr net.Addr,
chainHash *chainhash.Hash, flags lnwire.FundingFlag) (*ChannelReservation, error) {
@@ -421,17 +421,17 @@ func (l *LightningWallet) InitChannelReservation(
respChan := make(chan *ChannelReservation, 1)
l.msgChan <- &initFundingReserveMsg{
chainHash: chainHash,
nodeID: theirID,
nodeAddr: theirAddr,
fundingAmount: ourFundAmt,
capacity: capacity,
commitFeePerKw: commitFeePerKw,
fundingFeePerVSize: fundingFeePerVSize,
pushMSat: pushMSat,
flags: flags,
err: errChan,
resp: respChan,
chainHash: chainHash,
nodeID: theirID,
nodeAddr: theirAddr,
fundingAmount: ourFundAmt,
capacity: capacity,
commitFeePerKw: commitFeePerKw,
fundingFeePerKw: fundingFeePerKw,
pushMSat: pushMSat,
flags: flags,
err: errChan,
resp: respChan,
}
return <-respChan, <-errChan
@@ -479,10 +479,10 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
// don't need to perform any coin selection. Otherwise, attempt to
// obtain enough coins to meet the required funding amount.
if req.fundingAmount != 0 {
// Coin selection is done on the basis of sat-per-vbyte, we'll
// use the passed sat/vbyte passed in to perform coin selection.
// Coin selection is done on the basis of sat/kw, so we'll use
// the fee rate passed in to perform coin selection.
err := l.selectCoinsAndChange(
req.fundingFeePerVSize, req.fundingAmount,
req.fundingFeePerKw, req.fundingAmount,
reservation.ourContribution,
)
if err != nil {
@@ -1266,7 +1266,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// within the passed contribution's inputs. If necessary, a change address will
// also be generated.
// TODO(roasbeef): remove hardcoded fees and req'd confs for outputs.
func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerVByte,
func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerKWeight,
amt btcutil.Amount, contribution *ChannelContribution) error {
// We hold the coin select mutex while querying for outputs, and
@@ -1276,7 +1276,7 @@ func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerVByte,
defer l.coinSelectMtx.Unlock()
walletLog.Infof("Performing funding tx coin selection using %v "+
"sat/vbyte as fee rate", int64(feeRate))
"sat/kw as fee rate", int64(feeRate))
// Find all unlocked unspent witness outputs with greater than 1
// confirmation.
@@ -1385,9 +1385,9 @@ func selectInputs(amt btcutil.Amount, coins []*Utxo) (btcutil.Amount, []*Utxo, e
// coinSelect attempts to select a sufficient amount of coins, including a
// change output to fund amt satoshis, adhering to the specified fee rate. The
// specified fee rate should be expressed in sat/vbyte for coin selection to
// specified fee rate should be expressed in sat/kw for coin selection to
// function properly.
func coinSelect(feeRate SatPerVByte, amt btcutil.Amount,
func coinSelect(feeRate SatPerKWeight, amt btcutil.Amount,
coins []*Utxo) ([]*Utxo, btcutil.Amount, error) {
amtNeeded := amt
@@ -1431,7 +1431,8 @@ func coinSelect(feeRate SatPerVByte, amt btcutil.Amount,
// amount isn't enough to pay fees, then increase the requested
// coin amount by the estimate required fee, performing another
// round of coin selection.
requiredFee := feeRate.FeeForVSize(int64(weightEstimate.VSize()))
totalWeight := int64(weightEstimate.Weight())
requiredFee := feeRate.FeeForWeight(totalWeight)
if overShootAmt < requiredFee {
amtNeeded = amt + requiredFee
continue