multi: switch to transaction weight to calculate transaction fees
Due to a recent change within the codebase to return estimated fee rates in sat/kw, this commit ensures that we use this fee rate properly by calculing a transaction's fees using its weight. This includes all of the different transactions that are created within lnd (funding, sweeps, etc.). On-chain transactions still rely on a sat/vbyte fee rate since it's required by btcwallet.
This commit is contained in:
4 files changed
+48
-47
No files matched your search
+5
-5
@@ -994,15 +994,15 @@ func (u *utxoNursery) createSweepTx(kgtnOutputs []kidOutput,
|
||||
utxnLog.Infof("Creating sweep transaction for %v CSV inputs, %v CLTV "+
|
||||
"inputs", len(csvOutputs), len(cltvOutputs))
|
||||
|
||||
txVSize := int64(weightEstimate.VSize())
|
||||
return u.populateSweepTx(txVSize, classHeight, csvOutputs, cltvOutputs)
|
||||
txWeight := int64(weightEstimate.Weight())
|
||||
return u.populateSweepTx(txWeight, classHeight, csvOutputs, cltvOutputs)
|
||||
}
|
||||
|
||||
// populateSweepTx populate the final sweeping transaction with all witnesses
|
||||
// in place for all inputs using the provided txn fee. The created transaction
|
||||
// has a single output sending all the funds back to the source wallet, after
|
||||
// accounting for the fee estimate.
|
||||
func (u *utxoNursery) populateSweepTx(txVSize int64, classHeight uint32,
|
||||
func (u *utxoNursery) populateSweepTx(txWeight int64, classHeight uint32,
|
||||
csvInputs []CsvSpendableOutput,
|
||||
cltvInputs []SpendableOutput) (*wire.MsgTx, error) {
|
||||
|
||||
@@ -1022,11 +1022,11 @@ func (u *utxoNursery) populateSweepTx(txVSize int64, classHeight uint32,
|
||||
}
|
||||
|
||||
// Using the txn weight estimate, compute the required txn fee.
|
||||
feePerVSize, err := u.cfg.Estimator.EstimateFeePerVSize(6)
|
||||
feePerKw, err := u.cfg.Estimator.EstimateFeePerKW(6)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
txFee := feePerVSize.FeeForVSize(txVSize)
|
||||
txFee := feePerKw.FeeForWeight(txWeight)
|
||||
|
||||
// Sweep as much possible, after subtracting txn fees.
|
||||
sweepAmt := int64(totalSum - txFee)
|
||||
|
||||
Reference in new issue
Block a user