multi: apply the new type lntypes.WeightUnit
This commit is contained in:
36 files changed
+178
-133
No files matched your search
@@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/labels"
|
"github.com/lightningnetwork/lnd/labels"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
)
|
)
|
||||||
@@ -1497,14 +1498,14 @@ func (b *BreachArbitrator) createSweepTx(inputs ...input.Input) (*wire.MsgTx,
|
|||||||
spendableOutputs = append(spendableOutputs, inp)
|
spendableOutputs = append(spendableOutputs, inp)
|
||||||
}
|
}
|
||||||
|
|
||||||
txWeight := int64(weightEstimate.Weight())
|
txWeight := weightEstimate.Weight()
|
||||||
|
|
||||||
return b.sweepSpendableOutputsTxn(txWeight, spendableOutputs...)
|
return b.sweepSpendableOutputsTxn(txWeight, spendableOutputs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sweepSpendableOutputsTxn creates a signed transaction from a sequence of
|
// sweepSpendableOutputsTxn creates a signed transaction from a sequence of
|
||||||
// spendable outputs by sweeping the funds into a single p2wkh output.
|
// spendable outputs by sweeping the funds into a single p2wkh output.
|
||||||
func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight int64,
|
func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight lntypes.WeightUnit,
|
||||||
inputs ...input.Input) (*wire.MsgTx, error) {
|
inputs ...input.Input) (*wire.MsgTx, error) {
|
||||||
|
|
||||||
// First, we obtain a new public key script from the wallet which we'll
|
// First, we obtain a new public key script from the wallet which we'll
|
||||||
|
|||||||
+22
-22
@@ -2480,7 +2480,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight := int64(1) * input.HTLCWeight
|
htlcWeight := lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer := lnwallet.CalcFeeBuffer(
|
feeBuffer := lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2517,7 +2517,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(2) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(2) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2578,7 +2578,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(1) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2609,7 +2609,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(2) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(2) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2675,7 +2675,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(1) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2721,7 +2721,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(2) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(2) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2771,7 +2771,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(1) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2835,7 +2835,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(2) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(2) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2880,7 +2880,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(1) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -2976,7 +2976,7 @@ func TestChannelLinkTrimCircuitsPending(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight := int64(1) * input.HTLCWeight
|
htlcWeight := lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer := lnwallet.CalcFeeBuffer(
|
feeBuffer := lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3022,7 +3022,7 @@ func TestChannelLinkTrimCircuitsPending(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight = int64(1+halfHtlcs) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1+halfHtlcs) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3113,7 +3113,7 @@ func TestChannelLinkTrimCircuitsPending(t *testing.T) {
|
|||||||
// With two HTLCs on the pending commit, and two added to the in-memory
|
// With two HTLCs on the pending commit, and two added to the in-memory
|
||||||
// commitment state, the resulting bandwidth should reflect that Alice
|
// commitment state, the resulting bandwidth should reflect that Alice
|
||||||
// is paying the all htlc amounts in addition to all htlc fees.
|
// is paying the all htlc amounts in addition to all htlc fees.
|
||||||
htlcWeight = int64(1+numHtlcs) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1+numHtlcs) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3205,7 +3205,7 @@ func TestChannelLinkTrimCircuitsPending(t *testing.T) {
|
|||||||
// Since the latter two HTLCs have been completely dropped from memory,
|
// Since the latter two HTLCs have been completely dropped from memory,
|
||||||
// only the first two HTLCs we added should still be reflected in the
|
// only the first two HTLCs we added should still be reflected in the
|
||||||
// channel bandwidth.
|
// channel bandwidth.
|
||||||
htlcWeight = int64(1+halfHtlcs) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1+halfHtlcs) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3264,7 +3264,7 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight := int64(1) * input.HTLCWeight
|
htlcWeight := lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer := lnwallet.CalcFeeBuffer(
|
feeBuffer := lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3309,7 +3309,7 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
|||||||
|
|
||||||
// We account for the 2 htlcs and the additional one which would be
|
// We account for the 2 htlcs and the additional one which would be
|
||||||
// needed when sending and htlc.
|
// needed when sending and htlc.
|
||||||
htlcWeight = int64(1+halfHtlcs) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1+halfHtlcs) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3387,7 +3387,7 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Alice's bandwidth should have reverted back to her starting value.
|
// Alice's bandwidth should have reverted back to her starting value.
|
||||||
htlcWeight = int64(1) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3414,7 +3414,7 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
|||||||
|
|
||||||
// We account for the 2 htlcs and the additional one which would be
|
// We account for the 2 htlcs and the additional one which would be
|
||||||
// needed when sending and htlc.
|
// needed when sending and htlc.
|
||||||
htlcWeight = int64(1+halfHtlcs) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1+halfHtlcs) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3492,7 +3492,7 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
|||||||
t.Fatalf("expected %d packet to be failed", halfHtlcs)
|
t.Fatalf("expected %d packet to be failed", halfHtlcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
htlcWeight = int64(1) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3540,7 +3540,7 @@ func TestChannelLinkTrimCircuitsRemoteCommit(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight := int64(1) * input.HTLCWeight
|
htlcWeight := lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer := lnwallet.CalcFeeBuffer(
|
feeBuffer := lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3602,7 +3602,7 @@ func TestChannelLinkTrimCircuitsRemoteCommit(t *testing.T) {
|
|||||||
|
|
||||||
// The resulting bandwidth should reflect that Alice is paying both
|
// The resulting bandwidth should reflect that Alice is paying both
|
||||||
// htlc amounts, in addition to both htlc fees.
|
// htlc amounts, in addition to both htlc fees.
|
||||||
htlcWeight = int64(1+numHtlcs) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(1+numHtlcs) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
@@ -3700,7 +3700,7 @@ func TestChannelLinkBandwidthChanReserve(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the fee buffer for a channel state. Account for htlcs on
|
// Calculate the fee buffer for a channel state. Account for htlcs on
|
||||||
// the potential channel state as well.
|
// the potential channel state as well.
|
||||||
htlcWeight := int64(1) * input.HTLCWeight
|
htlcWeight := lntypes.WeightUnit(1) * input.HTLCWeight
|
||||||
feeBuffer := lnwallet.CalcFeeBuffer(feePerKw, commitWeight+htlcWeight)
|
feeBuffer := lnwallet.CalcFeeBuffer(feePerKw, commitWeight+htlcWeight)
|
||||||
|
|
||||||
// The starting bandwidth of the channel should be exactly the amount
|
// The starting bandwidth of the channel should be exactly the amount
|
||||||
@@ -3727,7 +3727,7 @@ func TestChannelLinkBandwidthChanReserve(t *testing.T) {
|
|||||||
_ = harness.aliceLink.handleSwitchPacket(addPkt)
|
_ = harness.aliceLink.handleSwitchPacket(addPkt)
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
|
|
||||||
htlcWeight = int64(2) * input.HTLCWeight
|
htlcWeight = lntypes.WeightUnit(2) * input.HTLCWeight
|
||||||
feeBuffer = lnwallet.CalcFeeBuffer(
|
feeBuffer = lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, commitWeight+htlcWeight,
|
feePerKw, commitWeight+htlcWeight,
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@ type TxInfo struct {
|
|||||||
Fee btcutil.Amount
|
Fee btcutil.Amount
|
||||||
|
|
||||||
// Weight is the weight of the tx.
|
// Weight is the weight of the tx.
|
||||||
Weight int64
|
Weight lntypes.WeightUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a human readable version of the tx info.
|
// String returns a human readable version of the tx info.
|
||||||
|
|||||||
+3
-2
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -157,10 +158,10 @@ func (m *MockWitnessType) WitnessGenerator(signer Signer,
|
|||||||
// if it would be included in a tx. It also returns if the output itself is a
|
// if it would be included in a tx. It also returns if the output itself is a
|
||||||
// nested p2sh output, if so then we need to take into account the extra
|
// nested p2sh output, if so then we need to take into account the extra
|
||||||
// sigScript data size.
|
// sigScript data size.
|
||||||
func (m *MockWitnessType) SizeUpperBound() (int, bool, error) {
|
func (m *MockWitnessType) SizeUpperBound() (lntypes.WeightUnit, bool, error) {
|
||||||
args := m.Called()
|
args := m.Called()
|
||||||
|
|
||||||
return args.Int(0), args.Bool(1), args.Error(2)
|
return args.Get(0).(lntypes.WeightUnit), args.Bool(1), args.Error(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddWeightEstimation adds the estimated size of the witness in bytes to the
|
// AddWeightEstimation adds the estimated size of the witness in bytes to the
|
||||||
|
|||||||
+17
-8
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -863,7 +864,7 @@ type TxWeightEstimator struct {
|
|||||||
inputCount uint32
|
inputCount uint32
|
||||||
outputCount uint32
|
outputCount uint32
|
||||||
inputSize int
|
inputSize int
|
||||||
inputWitnessSize int
|
inputWitnessSize lntypes.WeightUnit
|
||||||
outputSize int
|
outputSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,7 +889,9 @@ func (twe *TxWeightEstimator) AddP2WKHInput() *TxWeightEstimator {
|
|||||||
// AddWitnessInput updates the weight estimate to account for an additional
|
// AddWitnessInput updates the weight estimate to account for an additional
|
||||||
// input spending a native pay-to-witness output. This accepts the total size
|
// input spending a native pay-to-witness output. This accepts the total size
|
||||||
// of the witness as a parameter.
|
// of the witness as a parameter.
|
||||||
func (twe *TxWeightEstimator) AddWitnessInput(witnessSize int) *TxWeightEstimator {
|
func (twe *TxWeightEstimator) AddWitnessInput(
|
||||||
|
witnessSize lntypes.WeightUnit) *TxWeightEstimator {
|
||||||
|
|
||||||
twe.inputSize += InputSize
|
twe.inputSize += InputSize
|
||||||
twe.inputWitnessSize += witnessSize
|
twe.inputWitnessSize += witnessSize
|
||||||
twe.inputCount++
|
twe.inputCount++
|
||||||
@@ -905,7 +908,8 @@ func (twe *TxWeightEstimator) AddWitnessInput(witnessSize int) *TxWeightEstimato
|
|||||||
// NOTE: The leaf witness size must be calculated without the byte that accounts
|
// NOTE: The leaf witness size must be calculated without the byte that accounts
|
||||||
// for the number of witness elements, only the total size of all elements on
|
// for the number of witness elements, only the total size of all elements on
|
||||||
// the stack that are consumed by the revealed script should be counted.
|
// the stack that are consumed by the revealed script should be counted.
|
||||||
func (twe *TxWeightEstimator) AddTapscriptInput(leafWitnessSize int,
|
func (twe *TxWeightEstimator) AddTapscriptInput(
|
||||||
|
leafWitnessSize lntypes.WeightUnit,
|
||||||
tapscript *waddrmgr.Tapscript) *TxWeightEstimator {
|
tapscript *waddrmgr.Tapscript) *TxWeightEstimator {
|
||||||
|
|
||||||
// We add 1 byte for the total number of witness elements.
|
// We add 1 byte for the total number of witness elements.
|
||||||
@@ -915,7 +919,9 @@ func (twe *TxWeightEstimator) AddTapscriptInput(leafWitnessSize int,
|
|||||||
1 + len(tapscript.ControlBlock.InclusionProof)
|
1 + len(tapscript.ControlBlock.InclusionProof)
|
||||||
|
|
||||||
twe.inputSize += InputSize
|
twe.inputSize += InputSize
|
||||||
twe.inputWitnessSize += leafWitnessSize + controlBlockWitnessSize
|
twe.inputWitnessSize += leafWitnessSize + lntypes.WeightUnit(
|
||||||
|
controlBlockWitnessSize,
|
||||||
|
)
|
||||||
twe.inputCount++
|
twe.inputCount++
|
||||||
twe.hasWitness = true
|
twe.hasWitness = true
|
||||||
|
|
||||||
@@ -956,7 +962,9 @@ func (twe *TxWeightEstimator) AddNestedP2WKHInput() *TxWeightEstimator {
|
|||||||
|
|
||||||
// AddNestedP2WSHInput updates the weight estimate to account for an additional
|
// AddNestedP2WSHInput updates the weight estimate to account for an additional
|
||||||
// input spending a P2SH output with a nested P2WSH redeem script.
|
// input spending a P2SH output with a nested P2WSH redeem script.
|
||||||
func (twe *TxWeightEstimator) AddNestedP2WSHInput(witnessSize int) *TxWeightEstimator {
|
func (twe *TxWeightEstimator) AddNestedP2WSHInput(
|
||||||
|
witnessSize lntypes.WeightUnit) *TxWeightEstimator {
|
||||||
|
|
||||||
twe.inputSize += InputSize + NestedP2WSHSize
|
twe.inputSize += InputSize + NestedP2WSHSize
|
||||||
twe.inputWitnessSize += witnessSize
|
twe.inputWitnessSize += witnessSize
|
||||||
twe.inputCount++
|
twe.inputCount++
|
||||||
@@ -1027,11 +1035,12 @@ func (twe *TxWeightEstimator) AddOutput(pkScript []byte) *TxWeightEstimator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Weight gets the estimated weight of the transaction.
|
// Weight gets the estimated weight of the transaction.
|
||||||
func (twe *TxWeightEstimator) Weight() int {
|
func (twe *TxWeightEstimator) Weight() lntypes.WeightUnit {
|
||||||
txSizeStripped := BaseTxSize +
|
txSizeStripped := BaseTxSize +
|
||||||
wire.VarIntSerializeSize(uint64(twe.inputCount)) + twe.inputSize +
|
wire.VarIntSerializeSize(uint64(twe.inputCount)) + twe.inputSize +
|
||||||
wire.VarIntSerializeSize(uint64(twe.outputCount)) + twe.outputSize
|
wire.VarIntSerializeSize(uint64(twe.outputCount)) + twe.outputSize
|
||||||
weight := txSizeStripped * witnessScaleFactor
|
weight := lntypes.WeightUnit(txSizeStripped * witnessScaleFactor)
|
||||||
|
|
||||||
if twe.hasWitness {
|
if twe.hasWitness {
|
||||||
weight += WitnessHeaderSize + twe.inputWitnessSize
|
weight += WitnessHeaderSize + twe.inputWitnessSize
|
||||||
}
|
}
|
||||||
@@ -1041,5 +1050,5 @@ func (twe *TxWeightEstimator) Weight() int {
|
|||||||
// VSize gets the estimated virtual size of the transactions, in vbytes.
|
// VSize gets the estimated virtual size of the transactions, in vbytes.
|
||||||
func (twe *TxWeightEstimator) VSize() int {
|
func (twe *TxWeightEstimator) VSize() int {
|
||||||
// A tx's vsize is 1/4 of the weight, rounded up.
|
// A tx's vsize is 1/4 of the weight, rounded up.
|
||||||
return (twe.Weight() + witnessScaleFactor - 1) / witnessScaleFactor
|
return int(twe.Weight().ToVB())
|
||||||
}
|
}
|
||||||
+6
-5
@@ -297,11 +297,12 @@ func TestTxWeightEstimator(t *testing.T) {
|
|||||||
tx.AddTxOut(&wire.TxOut{PkScript: p2shScript})
|
tx.AddTxOut(&wire.TxOut{PkScript: p2shScript})
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedWeight := blockchain.GetTransactionWeight(btcutil.NewTx(tx))
|
expectedWeight := blockchain.GetTransactionWeight(
|
||||||
if weightEstimate.Weight() != int(expectedWeight) {
|
btcutil.NewTx(tx),
|
||||||
t.Errorf("Case %d: Got wrong weight: expected %d, got %d",
|
)
|
||||||
i, expectedWeight, weightEstimate.Weight())
|
require.EqualValuesf(t, expectedWeight, weightEstimate.Weight(),
|
||||||
}
|
"Case %d: Got wrong weight: expected %d, got %d",
|
||||||
|
i, expectedWeight, weightEstimate.Weight())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-6
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WitnessGenerator represents a function that is able to generate the final
|
// WitnessGenerator represents a function that is able to generate the final
|
||||||
@@ -32,7 +33,7 @@ type WitnessType interface {
|
|||||||
// WitnessType if it would be included in a tx. It also returns if the
|
// WitnessType if it would be included in a tx. It also returns if the
|
||||||
// output itself is a nested p2sh output, if so then we need to take
|
// output itself is a nested p2sh output, if so then we need to take
|
||||||
// into account the extra sigScript data size.
|
// into account the extra sigScript data size.
|
||||||
SizeUpperBound() (int, bool, error)
|
SizeUpperBound() (lntypes.WeightUnit, bool, error)
|
||||||
|
|
||||||
// AddWeightEstimation adds the estimated size of the witness in bytes
|
// AddWeightEstimation adds the estimated size of the witness in bytes
|
||||||
// to the given weight estimator.
|
// to the given weight estimator.
|
||||||
@@ -726,7 +727,9 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
|||||||
// sigScript data size.
|
// sigScript data size.
|
||||||
//
|
//
|
||||||
// NOTE: This is part of the WitnessType interface.
|
// NOTE: This is part of the WitnessType interface.
|
||||||
func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
func (wt StandardWitnessType) SizeUpperBound() (lntypes.WeightUnit,
|
||||||
|
bool, error) {
|
||||||
|
|
||||||
switch wt {
|
switch wt {
|
||||||
// Outputs on a remote commitment transaction that pay directly to us.
|
// Outputs on a remote commitment transaction that pay directly to us.
|
||||||
case CommitSpendNoDelayTweakless:
|
case CommitSpendNoDelayTweakless:
|
||||||
@@ -743,7 +746,8 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|||||||
case LeaseCommitmentTimeLock:
|
case LeaseCommitmentTimeLock:
|
||||||
size := ToLocalTimeoutWitnessSize +
|
size := ToLocalTimeoutWitnessSize +
|
||||||
LeaseWitnessScriptSizeOverhead
|
LeaseWitnessScriptSizeOverhead
|
||||||
return size, false, nil
|
|
||||||
|
return lntypes.WeightUnit(size), false, nil
|
||||||
|
|
||||||
// 1 CSV time locked output to us on remote commitment.
|
// 1 CSV time locked output to us on remote commitment.
|
||||||
case CommitmentToRemoteConfirmed:
|
case CommitmentToRemoteConfirmed:
|
||||||
@@ -751,7 +755,8 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|||||||
case LeaseCommitmentToRemoteConfirmed:
|
case LeaseCommitmentToRemoteConfirmed:
|
||||||
size := ToRemoteConfirmedWitnessSize +
|
size := ToRemoteConfirmedWitnessSize +
|
||||||
LeaseWitnessScriptSizeOverhead
|
LeaseWitnessScriptSizeOverhead
|
||||||
return size, false, nil
|
|
||||||
|
return lntypes.WeightUnit(size), false, nil
|
||||||
|
|
||||||
// Anchor output on the commitment transaction.
|
// Anchor output on the commitment transaction.
|
||||||
case CommitmentAnchor:
|
case CommitmentAnchor:
|
||||||
@@ -765,7 +770,8 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|||||||
case LeaseHtlcOfferedTimeoutSecondLevel:
|
case LeaseHtlcOfferedTimeoutSecondLevel:
|
||||||
size := ToLocalTimeoutWitnessSize +
|
size := ToLocalTimeoutWitnessSize +
|
||||||
LeaseWitnessScriptSizeOverhead
|
LeaseWitnessScriptSizeOverhead
|
||||||
return size, false, nil
|
|
||||||
|
return lntypes.WeightUnit(size), false, nil
|
||||||
|
|
||||||
// Input to the outgoing HTLC second layer timeout transaction.
|
// Input to the outgoing HTLC second layer timeout transaction.
|
||||||
case HtlcOfferedTimeoutSecondLevelInputConfirmed:
|
case HtlcOfferedTimeoutSecondLevelInputConfirmed:
|
||||||
@@ -779,7 +785,8 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|||||||
case LeaseHtlcAcceptedSuccessSecondLevel:
|
case LeaseHtlcAcceptedSuccessSecondLevel:
|
||||||
size := ToLocalTimeoutWitnessSize +
|
size := ToLocalTimeoutWitnessSize +
|
||||||
LeaseWitnessScriptSizeOverhead
|
LeaseWitnessScriptSizeOverhead
|
||||||
return size, false, nil
|
|
||||||
|
return lntypes.WeightUnit(size), false, nil
|
||||||
|
|
||||||
// Input to the incoming second-layer HTLC success transaction.
|
// Input to the incoming second-layer HTLC success transaction.
|
||||||
case HtlcAcceptedSuccessSecondLevelInputConfirmed:
|
case HtlcAcceptedSuccessSecondLevelInputConfirmed:
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ func fundingFee(numInput int, change bool) btcutil.Amount {
|
|||||||
weightEstimate.AddP2TROutput()
|
weightEstimate.AddP2TROutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
totalWeight := int64(weightEstimate.Weight())
|
totalWeight := weightEstimate.Weight()
|
||||||
|
|
||||||
return feeRate.FeeForWeight(totalWeight)
|
return feeRate.FeeForWeight(totalWeight)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -379,7 +379,7 @@ func testRescanAddressDetection(ht *lntest.HarnessTest) {
|
|||||||
estimator := input.TxWeightEstimator{}
|
estimator := input.TxWeightEstimator{}
|
||||||
estimator.AddP2WKHInput()
|
estimator.AddP2WKHInput()
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
|
|||||||
// We expect the fees to increase by i*delta.
|
// We expect the fees to increase by i*delta.
|
||||||
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
||||||
expectedFeeRate := chainfee.NewSatPerKWeight(
|
expectedFeeRate := chainfee.NewSatPerKWeight(
|
||||||
expectedFee, uint64(txWeight),
|
expectedFee, txWeight,
|
||||||
)
|
)
|
||||||
|
|
||||||
// We should see Bob's anchor sweeping tx being fee bumped
|
// We should see Bob's anchor sweeping tx being fee bumped
|
||||||
@@ -608,7 +608,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
// We expect the fees to increase by i*delta.
|
// We expect the fees to increase by i*delta.
|
||||||
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
||||||
expectedFeeRate := chainfee.NewSatPerKWeight(
|
expectedFeeRate := chainfee.NewSatPerKWeight(
|
||||||
expectedFee, uint64(txWeight),
|
expectedFee, txWeight,
|
||||||
)
|
)
|
||||||
|
|
||||||
// We should see Bob's anchor sweeping tx being fee bumped
|
// We should see Bob's anchor sweeping tx being fee bumped
|
||||||
@@ -929,7 +929,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
|
|||||||
outgoingBudget := 2 * invoiceAmt
|
outgoingBudget := 2 * invoiceAmt
|
||||||
outgoingTxSize := ht.CalculateTxWeight(outgoingSweep)
|
outgoingTxSize := ht.CalculateTxWeight(outgoingSweep)
|
||||||
outgoingEndFeeRate := chainfee.NewSatPerKWeight(
|
outgoingEndFeeRate := chainfee.NewSatPerKWeight(
|
||||||
outgoingBudget, uint64(outgoingTxSize),
|
outgoingBudget, outgoingTxSize,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert the initial sweeping tx is using the start fee rate.
|
// Assert the initial sweeping tx is using the start fee rate.
|
||||||
@@ -950,7 +950,8 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
|
|||||||
// assertSweepFeeRate is a helper closure that asserts the expected fee
|
// assertSweepFeeRate is a helper closure that asserts the expected fee
|
||||||
// rate is used at the given position for a sweeping tx.
|
// rate is used at the given position for a sweeping tx.
|
||||||
assertSweepFeeRate := func(sweepTx *wire.MsgTx,
|
assertSweepFeeRate := func(sweepTx *wire.MsgTx,
|
||||||
startFeeRate, delta chainfee.SatPerKWeight, txSize int64,
|
startFeeRate, delta chainfee.SatPerKWeight,
|
||||||
|
txSize lntypes.WeightUnit,
|
||||||
deadline, position int32, desc string) {
|
deadline, position int32, desc string) {
|
||||||
|
|
||||||
// Bob's HTLC sweeping tx should be fee bumped.
|
// Bob's HTLC sweeping tx should be fee bumped.
|
||||||
@@ -1068,7 +1069,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
|
|||||||
incomingBudget := invoiceAmt.MulF64(contractcourt.DefaultBudgetRatio)
|
incomingBudget := invoiceAmt.MulF64(contractcourt.DefaultBudgetRatio)
|
||||||
incomingTxSize := ht.CalculateTxWeight(incomingSweep)
|
incomingTxSize := ht.CalculateTxWeight(incomingSweep)
|
||||||
incomingEndFeeRate := chainfee.NewSatPerKWeight(
|
incomingEndFeeRate := chainfee.NewSatPerKWeight(
|
||||||
incomingBudget, uint64(incomingTxSize),
|
incomingBudget, incomingTxSize,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert the initial sweeping tx is using the start fee rate.
|
// Assert the initial sweeping tx is using the start fee rate.
|
||||||
@@ -1415,7 +1416,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
|
|
||||||
// Calculate the ending fee rate and fee rate delta used in his fee
|
// Calculate the ending fee rate and fee rate delta used in his fee
|
||||||
// function.
|
// function.
|
||||||
bobTxWeight := uint64(ht.CalculateTxWeight(bobSweepTx))
|
bobTxWeight := ht.CalculateTxWeight(bobSweepTx)
|
||||||
bobEndingFeeRate := chainfee.NewSatPerKWeight(bobBudget, bobTxWeight)
|
bobEndingFeeRate := chainfee.NewSatPerKWeight(bobBudget, bobTxWeight)
|
||||||
bobFeeRateDelta := (bobEndingFeeRate - bobStartFeeRate) /
|
bobFeeRateDelta := (bobEndingFeeRate - bobStartFeeRate) /
|
||||||
chainfee.SatPerKWeight(deadlineB-1)
|
chainfee.SatPerKWeight(deadlineB-1)
|
||||||
|
|||||||
+13
-11
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -187,7 +188,7 @@ func testTaprootComputeInputScriptKeySpendBip86(ht *lntest.HarnessTest,
|
|||||||
estimator := input.TxWeightEstimator{}
|
estimator := input.TxWeightEstimator{}
|
||||||
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
@@ -278,7 +279,7 @@ func testTaprootSignOutputRawScriptSpend(ht *lntest.HarnessTest,
|
|||||||
)
|
)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
|
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
sigHash := txscript.SigHashDefault
|
sigHash := txscript.SigHashDefault
|
||||||
if len(sigHashType) != 0 {
|
if len(sigHashType) != 0 {
|
||||||
sigHash = sigHashType[0]
|
sigHash = sigHashType[0]
|
||||||
@@ -431,7 +432,7 @@ func testTaprootSignOutputRawKeySpendBip86(ht *lntest.HarnessTest,
|
|||||||
estimator := input.TxWeightEstimator{}
|
estimator := input.TxWeightEstimator{}
|
||||||
estimator.AddTaprootKeySpendInput(sigHash)
|
estimator.AddTaprootKeySpendInput(sigHash)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
@@ -525,7 +526,7 @@ func testTaprootSignOutputRawKeySpendRootHash(ht *lntest.HarnessTest,
|
|||||||
estimator := input.TxWeightEstimator{}
|
estimator := input.TxWeightEstimator{}
|
||||||
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
@@ -610,7 +611,7 @@ func testTaprootMuSig2KeySpendBip86(ht *lntest.HarnessTest,
|
|||||||
estimator := input.TxWeightEstimator{}
|
estimator := input.TxWeightEstimator{}
|
||||||
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
@@ -740,7 +741,7 @@ func testTaprootMuSig2KeySpendRootHash(ht *lntest.HarnessTest,
|
|||||||
estimator := input.TxWeightEstimator{}
|
estimator := input.TxWeightEstimator{}
|
||||||
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
@@ -874,10 +875,11 @@ func testTaprootMuSig2ScriptSpend(ht *lntest.HarnessTest,
|
|||||||
feeRate := chainfee.SatPerKWeight(12500)
|
feeRate := chainfee.SatPerKWeight(12500)
|
||||||
estimator := input.TxWeightEstimator{}
|
estimator := input.TxWeightEstimator{}
|
||||||
estimator.AddTapscriptInput(
|
estimator.AddTapscriptInput(
|
||||||
len([]byte("foobar"))+len(leaf1.Script)+1, tapscript,
|
lntypes.WeightUnit(len([]byte("foobar"))+len(leaf1.Script)+1),
|
||||||
|
tapscript,
|
||||||
)
|
)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
@@ -956,7 +958,7 @@ func testTaprootMuSig2CombinedLeafKeySpend(ht *lntest.HarnessTest,
|
|||||||
input.TaprootSignatureWitnessSize, tapscript,
|
input.TaprootSignatureWitnessSize, tapscript,
|
||||||
)
|
)
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
estimatedWeight := int64(estimator.Weight())
|
estimatedWeight := estimator.Weight()
|
||||||
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
requiredFee := feeRate.FeeForWeight(estimatedWeight)
|
||||||
|
|
||||||
tx := wire.NewMsgTx(2)
|
tx := wire.NewMsgTx(2)
|
||||||
@@ -1525,7 +1527,7 @@ func sendToTaprootOutput(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
|||||||
// spend request, the given sweep address' balance is verified to be seen as
|
// spend request, the given sweep address' balance is verified to be seen as
|
||||||
// funds belonging to the wallet.
|
// funds belonging to the wallet.
|
||||||
func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
|
func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
|
||||||
tx *wire.MsgTx, estimatedWeight int64,
|
tx *wire.MsgTx, estimatedWeight lntypes.WeightUnit,
|
||||||
spendRequest *chainrpc.SpendRequest, sweepAddr string) {
|
spendRequest *chainrpc.SpendRequest, sweepAddr string) {
|
||||||
|
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
@@ -1564,7 +1566,7 @@ func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
|
|||||||
// Since Schnorr signatures are fixed size, we must be able to estimate
|
// Since Schnorr signatures are fixed size, we must be able to estimate
|
||||||
// the size of this transaction exactly.
|
// the size of this transaction exactly.
|
||||||
txWeight := blockchain.GetTransactionWeight(btcutil.NewTx(tx))
|
txWeight := blockchain.GetTransactionWeight(btcutil.NewTx(tx))
|
||||||
require.Equal(ht, estimatedWeight, txWeight)
|
require.EqualValues(ht, estimatedWeight, txWeight)
|
||||||
|
|
||||||
txReq := &walletrpc.Transaction{
|
txReq := &walletrpc.Transaction{
|
||||||
TxHex: buf.Bytes(),
|
TxHex: buf.Bytes(),
|
||||||
|
|||||||
@@ -1737,7 +1737,7 @@ func (w *WalletKit) fundPsbtCoinSelect(account string, changeIndex int32,
|
|||||||
// Do we already have enough inputs specified to pay for the TX as it
|
// Do we already have enough inputs specified to pay for the TX as it
|
||||||
// is? In that case we only need to allocate any change, if there is
|
// is? In that case we only need to allocate any change, if there is
|
||||||
// any.
|
// any.
|
||||||
packetFeeNoChange := feeRate.FeeForWeight(int64(estimator.Weight()))
|
packetFeeNoChange := feeRate.FeeForWeight(estimator.Weight())
|
||||||
if inputSum >= outputSum+packetFeeNoChange {
|
if inputSum >= outputSum+packetFeeNoChange {
|
||||||
// Calculate the packet's fee with a change output so, so we can
|
// Calculate the packet's fee with a change output so, so we can
|
||||||
// let the coin selection algorithm decide whether to use a
|
// let the coin selection algorithm decide whether to use a
|
||||||
@@ -1749,9 +1749,7 @@ func (w *WalletKit) fundPsbtCoinSelect(account string, changeIndex int32,
|
|||||||
case chanfunding.P2WKHChangeAddress:
|
case chanfunding.P2WKHChangeAddress:
|
||||||
estimator.AddP2WKHOutput()
|
estimator.AddP2WKHOutput()
|
||||||
}
|
}
|
||||||
packetFeeWithChange := feeRate.FeeForWeight(
|
packetFeeWithChange := feeRate.FeeForWeight(estimator.Weight())
|
||||||
int64(estimator.Weight()),
|
|
||||||
)
|
|
||||||
|
|
||||||
changeAmt, needMore, err := chanfunding.CalculateChangeAmount(
|
changeAmt, needMore, err := chanfunding.CalculateChangeAmount(
|
||||||
inputSum, outputSum, packetFeeNoChange,
|
inputSum, outputSum, packetFeeNoChange,
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ func TestFundPsbtCoinSelect(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
weight := estimator.Weight()
|
weight := estimator.Weight()
|
||||||
fee := chainfee.FeePerKwFloor.FeeForWeight(int64(weight))
|
fee := chainfee.FeePerKwFloor.FeeForWeight(weight)
|
||||||
|
|
||||||
return fee + dust
|
return fee + dust
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest/rpc"
|
"github.com/lightningnetwork/lnd/lntest/rpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -2041,9 +2042,9 @@ func (h *HarnessTest) CalculateTxFee(tx *wire.MsgTx) btcutil.Amount {
|
|||||||
// CalculateTxWeight calculates the weight for a given tx.
|
// CalculateTxWeight calculates the weight for a given tx.
|
||||||
//
|
//
|
||||||
// TODO(yy): use weight estimator to get more accurate result.
|
// TODO(yy): use weight estimator to get more accurate result.
|
||||||
func (h *HarnessTest) CalculateTxWeight(tx *wire.MsgTx) int64 {
|
func (h *HarnessTest) CalculateTxWeight(tx *wire.MsgTx) lntypes.WeightUnit {
|
||||||
utx := btcutil.NewTx(tx)
|
utx := btcutil.NewTx(tx)
|
||||||
return blockchain.GetTransactionWeight(utx)
|
return lntypes.WeightUnit(blockchain.GetTransactionWeight(utx))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalculateTxFeeRate calculates the fee rate for a given tx.
|
// CalculateTxFeeRate calculates the fee rate for a given tx.
|
||||||
@@ -2053,7 +2054,7 @@ func (h *HarnessTest) CalculateTxFeeRate(
|
|||||||
w := h.CalculateTxWeight(tx)
|
w := h.CalculateTxWeight(tx)
|
||||||
fee := h.CalculateTxFee(tx)
|
fee := h.CalculateTxFee(tx)
|
||||||
|
|
||||||
return chainfee.NewSatPerKWeight(fee, uint64(w))
|
return chainfee.NewSatPerKWeight(fee, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalculateTxesFeeRate takes a list of transactions and estimates the fee rate
|
// CalculateTxesFeeRate takes a list of transactions and estimates the fee rate
|
||||||
|
|||||||
+7
-3
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@@ -212,8 +213,9 @@ func CalcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
|||||||
anchors = anchorSize
|
anchors = anchorSize
|
||||||
}
|
}
|
||||||
|
|
||||||
return feePerKw.FeeForWeight(int64(commitWeight+htlcWeight*numHTLCs)) +
|
totalWeight := commitWeight + htlcWeight*numHTLCs
|
||||||
anchors
|
|
||||||
|
return feePerKw.FeeForWeight(lntypes.WeightUnit(totalWeight)) + anchors
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalculateMaxHtlc re-implements the RequiredRemoteChannelReserve of the
|
// CalculateMaxHtlc re-implements the RequiredRemoteChannelReserve of the
|
||||||
@@ -266,8 +268,10 @@ func CalcStaticFeeBuffer(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
|||||||
|
|
||||||
// Account for the HTLC which will be required when sending an htlc.
|
// Account for the HTLC which will be required when sending an htlc.
|
||||||
numHTLCs++
|
numHTLCs++
|
||||||
|
|
||||||
|
totalWeight := commitWeight + numHTLCs*htlcWeight
|
||||||
feeBuffer := lnwallet.CalcFeeBuffer(
|
feeBuffer := lnwallet.CalcFeeBuffer(
|
||||||
feePerKw, int64(commitWeight+numHTLCs*htlcWeight),
|
feePerKw, lntypes.WeightUnit(totalWeight),
|
||||||
)
|
)
|
||||||
|
|
||||||
return feeBuffer.ToSatoshis()
|
return feeBuffer.ToSatoshis()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/blockchain"
|
"github.com/btcsuite/btcd/blockchain"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -59,13 +60,13 @@ func (s SatPerKVByte) String() string {
|
|||||||
type SatPerKWeight btcutil.Amount
|
type SatPerKWeight btcutil.Amount
|
||||||
|
|
||||||
// NewSatPerKWeight creates a new fee rate in sat/kw.
|
// NewSatPerKWeight creates a new fee rate in sat/kw.
|
||||||
func NewSatPerKWeight(fee btcutil.Amount, weight uint64) SatPerKWeight {
|
func NewSatPerKWeight(fee btcutil.Amount, wu lntypes.WeightUnit) SatPerKWeight {
|
||||||
return SatPerKWeight(fee.MulF64(1000 / float64(weight)))
|
return SatPerKWeight(fee.MulF64(1000 / float64(wu)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// FeeForWeight calculates the fee resulting from this fee rate and the given
|
// FeeForWeight calculates the fee resulting from this fee rate and the given
|
||||||
// weight in weight units (wu).
|
// weight in weight units (wu).
|
||||||
func (s SatPerKWeight) FeeForWeight(wu int64) btcutil.Amount {
|
func (s SatPerKWeight) FeeForWeight(wu lntypes.WeightUnit) btcutil.Amount {
|
||||||
// The resulting fee is rounded down, as specified in BOLT#03.
|
// The resulting fee is rounded down, as specified in BOLT#03.
|
||||||
return btcutil.Amount(s) * btcutil.Amount(wu) / 1000
|
return btcutil.Amount(s) * btcutil.Amount(wu) / 1000
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ func calcCoopCloseFee(chanType channeldb.ChannelType,
|
|||||||
weightEstimator.AddTxOutput(remoteOutput)
|
weightEstimator.AddTxOutput(remoteOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
totalWeight := int64(weightEstimator.Weight())
|
totalWeight := weightEstimator.Weight()
|
||||||
|
|
||||||
return idealFeeRate.FeeForWeight(totalWeight)
|
return idealFeeRate.FeeForWeight(totalWeight)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func calculateFees(utxos []wallet.Coin, feeRate chainfee.SatPerKWeight,
|
|||||||
|
|
||||||
// Estimate the fee required for a transaction without a change
|
// Estimate the fee required for a transaction without a change
|
||||||
// output.
|
// output.
|
||||||
totalWeight := int64(weightEstimate.Weight())
|
totalWeight := weightEstimate.Weight()
|
||||||
requiredFeeNoChange := feeRate.FeeForWeight(totalWeight)
|
requiredFeeNoChange := feeRate.FeeForWeight(totalWeight)
|
||||||
|
|
||||||
// Estimate the fee required for a transaction with a change output.
|
// Estimate the fee required for a transaction with a change output.
|
||||||
@@ -137,7 +137,7 @@ func calculateFees(utxos []wallet.Coin, feeRate chainfee.SatPerKWeight,
|
|||||||
|
|
||||||
// Now that we have added the change output, redo the fee
|
// Now that we have added the change output, redo the fee
|
||||||
// estimate.
|
// estimate.
|
||||||
totalWeight = int64(weightEstimate.Weight())
|
totalWeight = weightEstimate.Weight()
|
||||||
requiredFeeWithChange := feeRate.FeeForWeight(totalWeight)
|
requiredFeeWithChange := feeRate.FeeForWeight(totalWeight)
|
||||||
|
|
||||||
return requiredFeeNoChange, requiredFeeWithChange, nil
|
return requiredFeeNoChange, requiredFeeWithChange, nil
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func fundingFee(feeRate chainfee.SatPerKWeight, numInput int, // nolint:unparam
|
|||||||
weightEstimate.AddP2TROutput()
|
weightEstimate.AddP2TROutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
totalWeight := int64(weightEstimate.Weight())
|
totalWeight := weightEstimate.Weight()
|
||||||
return feeRate.FeeForWeight(totalWeight)
|
return feeRate.FeeForWeight(totalWeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
@@ -3800,7 +3801,7 @@ func (lc *LightningChannel) getUnsignedAckedUpdates() []channeldb.LogUpdate {
|
|||||||
// an htlc even if our channel is drained locally.
|
// an htlc even if our channel is drained locally.
|
||||||
// See: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
|
// See: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
|
||||||
func CalcFeeBuffer(feePerKw chainfee.SatPerKWeight,
|
func CalcFeeBuffer(feePerKw chainfee.SatPerKWeight,
|
||||||
commitWeight int64) lnwire.MilliSatoshi {
|
commitWeight lntypes.WeightUnit) lnwire.MilliSatoshi {
|
||||||
|
|
||||||
// Account for a 100% in fee rate increase.
|
// Account for a 100% in fee rate increase.
|
||||||
bufferFeePerKw := 2 * feePerKw
|
bufferFeePerKw := 2 * feePerKw
|
||||||
@@ -3873,7 +3874,7 @@ func (b BufferType) String() string {
|
|||||||
// and verifies that it does not become negative. This function returns the new
|
// and verifies that it does not become negative. This function returns the new
|
||||||
// balance and the exact buffer amount (excluding the commitment fee).
|
// balance and the exact buffer amount (excluding the commitment fee).
|
||||||
func (lc *LightningChannel) applyCommitFee(
|
func (lc *LightningChannel) applyCommitFee(
|
||||||
balance lnwire.MilliSatoshi, commitWeight int64,
|
balance lnwire.MilliSatoshi, commitWeight lntypes.WeightUnit,
|
||||||
feePerKw chainfee.SatPerKWeight,
|
feePerKw chainfee.SatPerKWeight,
|
||||||
buffer BufferType) (lnwire.MilliSatoshi, lnwire.MilliSatoshi, error) {
|
buffer BufferType) (lnwire.MilliSatoshi, lnwire.MilliSatoshi, error) {
|
||||||
|
|
||||||
@@ -4730,8 +4731,8 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
|||||||
// If the updateState boolean is set true, the add and remove heights of the
|
// If the updateState boolean is set true, the add and remove heights of the
|
||||||
// HTLCs will be set to the next commitment height.
|
// HTLCs will be set to the next commitment height.
|
||||||
func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool,
|
func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool,
|
||||||
updateState bool) (lnwire.MilliSatoshi, lnwire.MilliSatoshi, int64,
|
updateState bool) (lnwire.MilliSatoshi, lnwire.MilliSatoshi,
|
||||||
*htlcView, error) {
|
lntypes.WeightUnit, *htlcView, error) {
|
||||||
|
|
||||||
commitChain := lc.localCommitChain
|
commitChain := lc.localCommitChain
|
||||||
dustLimit := lc.channelState.LocalChanCfg.DustLimit
|
dustLimit := lc.channelState.LocalChanCfg.DustLimit
|
||||||
@@ -4792,7 +4793,7 @@ func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool,
|
|||||||
|
|
||||||
// Now go through all HTLCs at this stage, to calculate the total
|
// Now go through all HTLCs at this stage, to calculate the total
|
||||||
// weight, needed to calculate the transaction fee.
|
// weight, needed to calculate the transaction fee.
|
||||||
var totalHtlcWeight int64
|
var totalHtlcWeight lntypes.WeightUnit
|
||||||
for _, htlc := range filteredHTLCView.ourUpdates {
|
for _, htlc := range filteredHTLCView.ourUpdates {
|
||||||
if HtlcIsDust(
|
if HtlcIsDust(
|
||||||
lc.channelState.ChanType, false, !remoteChain,
|
lc.channelState.ChanType, false, !remoteChain,
|
||||||
@@ -7522,7 +7523,7 @@ type AnchorResolution struct {
|
|||||||
CommitFee btcutil.Amount
|
CommitFee btcutil.Amount
|
||||||
|
|
||||||
// CommitWeight is the weight of the commit tx.
|
// CommitWeight is the weight of the commit tx.
|
||||||
CommitWeight int64
|
CommitWeight lntypes.WeightUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalForceCloseSummary describes the final commitment state before the
|
// LocalForceCloseSummary describes the final commitment state before the
|
||||||
@@ -8200,7 +8201,7 @@ func NewAnchorResolution(chanState *channeldb.OpenChannel,
|
|||||||
return &AnchorResolution{
|
return &AnchorResolution{
|
||||||
CommitAnchor: *outPoint,
|
CommitAnchor: *outPoint,
|
||||||
AnchorSignDescriptor: *signDesc,
|
AnchorSignDescriptor: *signDesc,
|
||||||
CommitWeight: weight,
|
CommitWeight: lntypes.WeightUnit(weight),
|
||||||
CommitFee: fee,
|
CommitFee: fee,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -8226,7 +8227,7 @@ func (lc *LightningChannel) AvailableBalance() lnwire.MilliSatoshi {
|
|||||||
// this method. Additionally, the total weight of the next to be created
|
// this method. Additionally, the total weight of the next to be created
|
||||||
// commitment is returned for accounting purposes.
|
// commitment is returned for accounting purposes.
|
||||||
func (lc *LightningChannel) availableBalance(
|
func (lc *LightningChannel) availableBalance(
|
||||||
buffer BufferType) (lnwire.MilliSatoshi, int64) {
|
buffer BufferType) (lnwire.MilliSatoshi, lntypes.WeightUnit) {
|
||||||
|
|
||||||
// We'll grab the current set of log updates that the remote has
|
// We'll grab the current set of log updates that the remote has
|
||||||
// ACKed.
|
// ACKed.
|
||||||
@@ -8265,8 +8266,9 @@ func (lc *LightningChannel) availableBalance(
|
|||||||
// commitment, increasing the commitment fee we must pay as an initiator,
|
// commitment, increasing the commitment fee we must pay as an initiator,
|
||||||
// eating into our balance. It will make sure we won't violate the channel
|
// eating into our balance. It will make sure we won't violate the channel
|
||||||
// reserve constraints for this amount.
|
// reserve constraints for this amount.
|
||||||
func (lc *LightningChannel) availableCommitmentBalance(view *htlcView,
|
func (lc *LightningChannel) availableCommitmentBalance(
|
||||||
remoteChain bool, buffer BufferType) (lnwire.MilliSatoshi, int64) {
|
view *htlcView, remoteChain bool,
|
||||||
|
buffer BufferType) (lnwire.MilliSatoshi, lntypes.WeightUnit) {
|
||||||
|
|
||||||
// Compute the current balances for this commitment. This will take
|
// Compute the current balances for this commitment. This will take
|
||||||
// into account HTLCs to determine the commit weight, which the
|
// into account HTLCs to determine the commit weight, which the
|
||||||
|
|||||||
@@ -832,7 +832,7 @@ func TestForceClose(t *testing.T) {
|
|||||||
|
|
||||||
type forceCloseTestCase struct {
|
type forceCloseTestCase struct {
|
||||||
chanType channeldb.ChannelType
|
chanType channeldb.ChannelType
|
||||||
expectedCommitWeight int64
|
expectedCommitWeight lntypes.WeightUnit
|
||||||
anchorAmt btcutil.Amount
|
anchorAmt btcutil.Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4803,7 +4803,7 @@ func TestChanAvailableBandwidth(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
assertBandwidthEstimateCorrect := func(aliceInitiate bool,
|
assertBandwidthEstimateCorrect := func(aliceInitiate bool,
|
||||||
numNonDustHtlcsOnCommit int64) {
|
numNonDustHtlcsOnCommit lntypes.WeightUnit) {
|
||||||
|
|
||||||
// With the HTLC's added, we'll now query the AvailableBalance
|
// With the HTLC's added, we'll now query the AvailableBalance
|
||||||
// method for the current available channel bandwidth from
|
// method for the current available channel bandwidth from
|
||||||
@@ -5189,7 +5189,7 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
|
|||||||
// fromt the given channel's POV.
|
// fromt the given channel's POV.
|
||||||
// When sending htlcs we enforce the feebuffer on the commitment
|
// When sending htlcs we enforce the feebuffer on the commitment
|
||||||
// transaction.
|
// transaction.
|
||||||
remoteCommitWeight := func(lc *LightningChannel) int64 {
|
remoteCommitWeight := func(lc *LightningChannel) lntypes.WeightUnit {
|
||||||
remoteACKedIndex := lc.localCommitChain.tip().theirMessageIndex
|
remoteACKedIndex := lc.localCommitChain.tip().theirMessageIndex
|
||||||
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
||||||
lc.localUpdateLog.logIndex)
|
lc.localUpdateLog.logIndex)
|
||||||
@@ -10454,8 +10454,8 @@ func TestApplyCommitmentFee(t *testing.T) {
|
|||||||
balanceBelowReserve = lnwire.NewMSatFromSatoshis(5_000)
|
balanceBelowReserve = lnwire.NewMSatFromSatoshis(5_000)
|
||||||
|
|
||||||
// commitment weight with an additional htlc.
|
// commitment weight with an additional htlc.
|
||||||
commitWeight int64 = input.BaseAnchorCommitmentTxWeight +
|
commitWeight lntypes.WeightUnit = input.
|
||||||
input.HTLCWeight
|
BaseAnchorCommitmentTxWeight + input.HTLCWeight
|
||||||
|
|
||||||
// fee rate of 10 sat/vbyte.
|
// fee rate of 10 sat/vbyte.
|
||||||
feePerKw = chainfee.SatPerKWeight(2500)
|
feePerKw = chainfee.SatPerKWeight(2500)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
@@ -471,7 +472,7 @@ func SecondLevelHtlcScript(chanType channeldb.ChannelType, initiator bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommitWeight returns the base commitment weight before adding HTLCs.
|
// CommitWeight returns the base commitment weight before adding HTLCs.
|
||||||
func CommitWeight(chanType channeldb.ChannelType) int64 {
|
func CommitWeight(chanType channeldb.ChannelType) lntypes.WeightUnit {
|
||||||
switch {
|
switch {
|
||||||
case chanType.IsTaproot():
|
case chanType.IsTaproot():
|
||||||
return input.TaprootCommitWeight
|
return input.TaprootCommitWeight
|
||||||
@@ -724,7 +725,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||||||
// by the current fee-per-kw, then divide by 1000 to get the proper
|
// by the current fee-per-kw, then divide by 1000 to get the proper
|
||||||
// fee.
|
// fee.
|
||||||
totalCommitWeight := CommitWeight(cb.chanState.ChanType) +
|
totalCommitWeight := CommitWeight(cb.chanState.ChanType) +
|
||||||
input.HTLCWeight*numHTLCs
|
lntypes.WeightUnit(input.HTLCWeight*numHTLCs)
|
||||||
|
|
||||||
// With the weight known, we can now calculate the commitment fee,
|
// With the weight known, we can now calculate the commitment fee,
|
||||||
// ensuring that we account for any dust outputs trimmed above.
|
// ensuring that we account for any dust outputs trimmed above.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
@@ -241,13 +242,15 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
|||||||
|
|
||||||
// Based on the channel type, we determine the initial commit weight
|
// Based on the channel type, we determine the initial commit weight
|
||||||
// and fee.
|
// and fee.
|
||||||
commitWeight := int64(input.CommitWeight)
|
commitWeight := input.CommitWeight
|
||||||
if req.CommitType.IsTaproot() {
|
if req.CommitType.IsTaproot() {
|
||||||
commitWeight = input.TaprootCommitWeight
|
commitWeight = input.TaprootCommitWeight
|
||||||
} else if req.CommitType.HasAnchors() {
|
} else if req.CommitType.HasAnchors() {
|
||||||
commitWeight = int64(input.AnchorCommitWeight)
|
commitWeight = input.AnchorCommitWeight
|
||||||
}
|
}
|
||||||
commitFee := req.CommitFeePerKw.FeeForWeight(commitWeight)
|
commitFee := req.CommitFeePerKw.FeeForWeight(
|
||||||
|
lntypes.WeightUnit(commitWeight),
|
||||||
|
)
|
||||||
|
|
||||||
localFundingMSat := lnwire.NewMSatFromSatoshis(localFundingAmt)
|
localFundingMSat := lnwire.NewMSatFromSatoshis(localFundingAmt)
|
||||||
// TODO(halseth): make method take remote funding amount directly
|
// TODO(halseth): make method take remote funding amount directly
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
@@ -506,9 +507,10 @@ func calcStaticFee(chanType channeldb.ChannelType, numHTLCs int) btcutil.Amount
|
|||||||
htlcWeight = 172
|
htlcWeight = 172
|
||||||
feePerKw = btcutil.Amount(24/4) * 1000
|
feePerKw = btcutil.Amount(24/4) * 1000
|
||||||
)
|
)
|
||||||
return feePerKw *
|
htlcsWeight := htlcWeight * int64(numHTLCs)
|
||||||
(btcutil.Amount(CommitWeight(chanType) +
|
totalWeight := CommitWeight(chanType) + lntypes.WeightUnit(htlcsWeight)
|
||||||
htlcWeight*int64(numHTLCs))) / 1000
|
|
||||||
|
return feePerKw * (btcutil.Amount(totalWeight)) / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForceStateTransition executes the necessary interaction between the two
|
// ForceStateTransition executes the necessary interaction between the two
|
||||||
|
|||||||
@@ -913,7 +913,7 @@ func createTestChannelsForVectors(tc *testContext, chanType channeldb.ChannelTyp
|
|||||||
|
|
||||||
// Create the initial commitment transactions for the channel.
|
// Create the initial commitment transactions for the channel.
|
||||||
feePerKw := chainfee.SatPerKWeight(feeRate)
|
feePerKw := chainfee.SatPerKWeight(feeRate)
|
||||||
commitWeight := int64(input.CommitWeight)
|
commitWeight := lntypes.WeightUnit(input.CommitWeight)
|
||||||
if chanType.HasAnchors() {
|
if chanType.HasAnchors() {
|
||||||
commitWeight = input.AnchorCommitWeight
|
commitWeight = input.AnchorCommitWeight
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -211,7 +211,7 @@ func (b *BudgetAggregator) filterInputs(inputs InputsMap) InputsMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip inputs that has too little budget.
|
// Skip inputs that has too little budget.
|
||||||
minFee := minFeeRate.FeeForWeight(int64(size))
|
minFee := minFeeRate.FeeForWeight(size)
|
||||||
if pi.params.Budget < minFee {
|
if pi.params.Budget < minFee {
|
||||||
log.Warnf("Skipped input=%v: has budget=%v, but the "+
|
log.Warnf("Skipped input=%v: has budget=%v, but the "+
|
||||||
"min fee requires %v", op, pi.params.Budget,
|
"min fee requires %v", op, pi.params.Budget,
|
||||||
@@ -224,7 +224,7 @@ func (b *BudgetAggregator) filterInputs(inputs InputsMap) InputsMap {
|
|||||||
startingFeeRate := pi.params.StartingFeeRate.UnwrapOr(
|
startingFeeRate := pi.params.StartingFeeRate.UnwrapOr(
|
||||||
chainfee.SatPerKWeight(0),
|
chainfee.SatPerKWeight(0),
|
||||||
)
|
)
|
||||||
startingFee := startingFeeRate.FeeForWeight(int64(size))
|
startingFee := startingFeeRate.FeeForWeight(size)
|
||||||
if pi.params.Budget < startingFee {
|
if pi.params.Budget < startingFee {
|
||||||
log.Errorf("Skipped input=%v: has budget=%v, but the "+
|
log.Errorf("Skipped input=%v: has budget=%v, but the "+
|
||||||
"starting fee requires %v", op,
|
"starting fee requires %v", op,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/fn"
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -34,14 +35,15 @@ func TestBudgetAggregatorFilterInputs(t *testing.T) {
|
|||||||
|
|
||||||
// Mock the `SizeUpperBound` method to return an error exactly once.
|
// Mock the `SizeUpperBound` method to return an error exactly once.
|
||||||
dummyErr := errors.New("dummy error")
|
dummyErr := errors.New("dummy error")
|
||||||
wtErr.On("SizeUpperBound").Return(0, false, dummyErr).Once()
|
wtErr.On("SizeUpperBound").Return(
|
||||||
|
lntypes.WeightUnit(0), false, dummyErr).Once()
|
||||||
|
|
||||||
// Create a mock WitnessType that gives the size.
|
// Create a mock WitnessType that gives the size.
|
||||||
wt := &input.MockWitnessType{}
|
wt := &input.MockWitnessType{}
|
||||||
defer wt.AssertExpectations(t)
|
defer wt.AssertExpectations(t)
|
||||||
|
|
||||||
// Mock the `SizeUpperBound` method to return the size four times.
|
// Mock the `SizeUpperBound` method to return the size four times.
|
||||||
const wtSize = 100
|
const wtSize lntypes.WeightUnit = 100
|
||||||
wt.On("SizeUpperBound").Return(wtSize, true, nil).Times(4)
|
wt.On("SizeUpperBound").Return(wtSize, true, nil).Times(4)
|
||||||
|
|
||||||
// Create a mock input that will be filtered out due to error.
|
// Create a mock input that will be filtered out due to error.
|
||||||
@@ -396,7 +398,7 @@ func TestBudgetInputSetClusterInputs(t *testing.T) {
|
|||||||
|
|
||||||
// Mock the `SizeUpperBound` method to return the size 10 times since
|
// Mock the `SizeUpperBound` method to return the size 10 times since
|
||||||
// we are using ten inputs.
|
// we are using ten inputs.
|
||||||
const wtSize = 100
|
const wtSize lntypes.WeightUnit = 100
|
||||||
wt.On("SizeUpperBound").Return(wtSize, true, nil).Times(10)
|
wt.On("SizeUpperBound").Return(wtSize, true, nil).Times(10)
|
||||||
wt.On("String").Return("mock witness type")
|
wt.On("String").Return("mock witness type")
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/fn"
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/labels"
|
"github.com/lightningnetwork/lnd/labels"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnutils"
|
"github.com/lightningnetwork/lnd/lnutils"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
@@ -155,7 +156,7 @@ func (r *BumpRequest) MaxFeeRateAllowed() (chainfee.SatPerKWeight, error) {
|
|||||||
// calcSweepTxWeight calculates the weight of the sweep tx. It assumes a
|
// calcSweepTxWeight calculates the weight of the sweep tx. It assumes a
|
||||||
// sweeping tx always has a single output(change).
|
// sweeping tx always has a single output(change).
|
||||||
func calcSweepTxWeight(inputs []input.Input,
|
func calcSweepTxWeight(inputs []input.Input,
|
||||||
outputPkScript []byte) (uint64, error) {
|
outputPkScript []byte) (lntypes.WeightUnit, error) {
|
||||||
|
|
||||||
// Use a const fee rate as we only use the weight estimator to
|
// Use a const fee rate as we only use the weight estimator to
|
||||||
// calculate the size.
|
// calculate the size.
|
||||||
@@ -175,7 +176,7 @@ func calcSweepTxWeight(inputs []input.Input,
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return uint64(estimator.weight()), nil
|
return estimator.weight(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BumpResult is used by the Bumper to send updates about the tx being
|
// BumpResult is used by the Bumper to send updates about the tx being
|
||||||
|
|||||||
@@ -314,7 +314,8 @@ func (b *BudgetInputSet) AddWalletInputs(wallet Wallet) error {
|
|||||||
}
|
}
|
||||||
b.addInput(pi)
|
b.addInput(pi)
|
||||||
|
|
||||||
log.Debugf("Added wallet input %v to input set", pi)
|
log.Debugf("Added wallet input to input set: op=%v, amt=%v",
|
||||||
|
pi.OutPoint(), utxo.Value)
|
||||||
|
|
||||||
// Return if we've reached the minimum output amount.
|
// Return if we've reached the minimum output amount.
|
||||||
if !b.NeedWalletInput() {
|
if !b.NeedWalletInput() {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ type weightEstimator struct {
|
|||||||
feeRate chainfee.SatPerKWeight
|
feeRate chainfee.SatPerKWeight
|
||||||
parents map[chainhash.Hash]struct{}
|
parents map[chainhash.Hash]struct{}
|
||||||
parentsFee btcutil.Amount
|
parentsFee btcutil.Amount
|
||||||
parentsWeight int64
|
parentsWeight lntypes.WeightUnit
|
||||||
|
|
||||||
// maxFeeRate is the max allowed fee rate configured by the user.
|
// maxFeeRate is the max allowed fee rate configured by the user.
|
||||||
maxFeeRate chainfee.SatPerKWeight
|
maxFeeRate chainfee.SatPerKWeight
|
||||||
@@ -102,7 +103,7 @@ func (w *weightEstimator) addOutput(txOut *wire.TxOut) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// weight gets the estimated weight of the transaction.
|
// weight gets the estimated weight of the transaction.
|
||||||
func (w *weightEstimator) weight() int {
|
func (w *weightEstimator) weight() lntypes.WeightUnit {
|
||||||
return w.estimator.Weight()
|
return w.estimator.Weight()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ func (w *weightEstimator) weight() int {
|
|||||||
// parent transactions.
|
// parent transactions.
|
||||||
func (w *weightEstimator) fee() btcutil.Amount {
|
func (w *weightEstimator) fee() btcutil.Amount {
|
||||||
// Calculate the weight of the transaction.
|
// Calculate the weight of the transaction.
|
||||||
weight := int64(w.estimator.Weight())
|
weight := w.estimator.Weight()
|
||||||
|
|
||||||
// Calculate the fee.
|
// Calculate the fee.
|
||||||
fee := w.feeRate.FeeForWeight(weight)
|
fee := w.feeRate.FeeForWeight(weight)
|
||||||
@@ -123,7 +124,7 @@ func (w *weightEstimator) fee() btcutil.Amount {
|
|||||||
// outputs, taking into account unconfirmed parent transactions (cpfp).
|
// outputs, taking into account unconfirmed parent transactions (cpfp).
|
||||||
func (w *weightEstimator) feeWithParent() btcutil.Amount {
|
func (w *weightEstimator) feeWithParent() btcutil.Amount {
|
||||||
// Calculate fee and weight for just this tx.
|
// Calculate fee and weight for just this tx.
|
||||||
childWeight := int64(w.estimator.Weight())
|
childWeight := w.estimator.Weight()
|
||||||
|
|
||||||
// Add combined weight of unconfirmed parent txes.
|
// Add combined weight of unconfirmed parent txes.
|
||||||
totalWeight := childWeight + w.parentsWeight
|
totalWeight := childWeight + w.parentsWeight
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -28,7 +29,7 @@ func TestWeightEstimator(t *testing.T) {
|
|||||||
require.NoError(t, w.add(&input1))
|
require.NoError(t, w.add(&input1))
|
||||||
|
|
||||||
// The expectations is that this input is added.
|
// The expectations is that this input is added.
|
||||||
const expectedWeight1 = 322
|
const expectedWeight1 lntypes.WeightUnit = 322
|
||||||
require.Equal(t, expectedWeight1, w.weight())
|
require.Equal(t, expectedWeight1, w.weight())
|
||||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight1),
|
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight1),
|
||||||
w.feeWithParent())
|
w.feeWithParent())
|
||||||
@@ -50,7 +51,7 @@ func TestWeightEstimator(t *testing.T) {
|
|||||||
|
|
||||||
// Pay for parent isn't possible because the parent pays a higher fee
|
// Pay for parent isn't possible because the parent pays a higher fee
|
||||||
// rate than the child. We expect no additional fee on the child.
|
// rate than the child. We expect no additional fee on the child.
|
||||||
const expectedWeight2 = expectedWeight1 + 280
|
const expectedWeight2 lntypes.WeightUnit = expectedWeight1 + 280
|
||||||
require.Equal(t, expectedWeight2, w.weight())
|
require.Equal(t, expectedWeight2, w.weight())
|
||||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight2),
|
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight2),
|
||||||
w.feeWithParent())
|
w.feeWithParent())
|
||||||
@@ -70,7 +71,7 @@ func TestWeightEstimator(t *testing.T) {
|
|||||||
require.NoError(t, w.add(&input3))
|
require.NoError(t, w.add(&input3))
|
||||||
|
|
||||||
// Expect the weight to increase because of the third input.
|
// Expect the weight to increase because of the third input.
|
||||||
const expectedWeight3 = expectedWeight2 + 280
|
const expectedWeight3 lntypes.WeightUnit = expectedWeight2 + 280
|
||||||
require.Equal(t, expectedWeight3, w.weight())
|
require.Equal(t, expectedWeight3, w.weight())
|
||||||
|
|
||||||
// Expect the fee to cover the child and the parent transaction at 20
|
// Expect the fee to cover the child and the parent transaction at 20
|
||||||
@@ -107,7 +108,7 @@ func TestWeightEstimatorMaxFee(t *testing.T) {
|
|||||||
require.NoError(t, w.add(&childInput))
|
require.NoError(t, w.add(&childInput))
|
||||||
|
|
||||||
// The child weight should be 322 weight uints.
|
// The child weight should be 322 weight uints.
|
||||||
const childWeight = 322
|
const childWeight lntypes.WeightUnit = 322
|
||||||
require.Equal(t, childWeight, w.weight())
|
require.Equal(t, childWeight, w.weight())
|
||||||
|
|
||||||
// Check the fee is capped at the maximum allowed fee. The
|
// Check the fee is capped at the maximum allowed fee. The
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
@@ -115,7 +116,7 @@ func (c CommitmentType) ToRemoteWitnessType() (input.WitnessType, error) {
|
|||||||
|
|
||||||
// ToRemoteWitnessSize is the size of the witness that will be required to spend
|
// ToRemoteWitnessSize is the size of the witness that will be required to spend
|
||||||
// the to_remote output.
|
// the to_remote output.
|
||||||
func (c CommitmentType) ToRemoteWitnessSize() (int, error) {
|
func (c CommitmentType) ToRemoteWitnessSize() (lntypes.WeightUnit, error) {
|
||||||
switch c {
|
switch c {
|
||||||
// Legacy channels (both tweaked and non-tweaked) spend from P2WKH
|
// Legacy channels (both tweaked and non-tweaked) spend from P2WKH
|
||||||
// output.
|
// output.
|
||||||
@@ -137,7 +138,7 @@ func (c CommitmentType) ToRemoteWitnessSize() (int, error) {
|
|||||||
|
|
||||||
// ToLocalWitnessSize is the size of the witness that will be required to spend
|
// ToLocalWitnessSize is the size of the witness that will be required to spend
|
||||||
// the to_local output.
|
// the to_local output.
|
||||||
func (c CommitmentType) ToLocalWitnessSize() (int, error) {
|
func (c CommitmentType) ToLocalWitnessSize() (lntypes.WeightUnit, error) {
|
||||||
switch c {
|
switch c {
|
||||||
// An older ToLocalPenaltyWitnessSize constant used to underestimate the
|
// An older ToLocalPenaltyWitnessSize constant used to underestimate the
|
||||||
// size by one byte. The difference in weight can cause different output
|
// size by one byte. The difference in weight can cause different output
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/watchtower/blob"
|
"github.com/lightningnetwork/lnd/watchtower/blob"
|
||||||
"github.com/lightningnetwork/lnd/watchtower/wtdb"
|
"github.com/lightningnetwork/lnd/watchtower/wtdb"
|
||||||
)
|
)
|
||||||
@@ -123,7 +124,7 @@ func (p *JusticeDescriptor) commitToRemoteInput() (*breachedInput, error) {
|
|||||||
// assembleJusticeTxn accepts the breached inputs recovered from state update
|
// assembleJusticeTxn accepts the breached inputs recovered from state update
|
||||||
// and attempts to construct the justice transaction that sweeps the victims
|
// and attempts to construct the justice transaction that sweeps the victims
|
||||||
// funds to their wallet and claims the watchtower's reward.
|
// funds to their wallet and claims the watchtower's reward.
|
||||||
func (p *JusticeDescriptor) assembleJusticeTxn(txWeight int64,
|
func (p *JusticeDescriptor) assembleJusticeTxn(txWeight lntypes.WeightUnit,
|
||||||
inputs ...*breachedInput) (*wire.MsgTx, error) {
|
inputs ...*breachedInput) (*wire.MsgTx, error) {
|
||||||
|
|
||||||
justiceTxn := wire.NewMsgTx(2)
|
justiceTxn := wire.NewMsgTx(2)
|
||||||
@@ -287,7 +288,7 @@ func (p *JusticeDescriptor) CreateJusticeTxn() (*wire.MsgTx, error) {
|
|||||||
|
|
||||||
// TODO(conner): sweep htlc outputs
|
// TODO(conner): sweep htlc outputs
|
||||||
|
|
||||||
txWeight := int64(weightEstimate.Weight())
|
txWeight := weightEstimate.Weight()
|
||||||
|
|
||||||
return p.assembleJusticeTxn(txWeight, sweepInputs...)
|
return p.assembleJusticeTxn(txWeight, sweepInputs...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ func testJusticeDescriptor(t *testing.T, blobType blob.Type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outputs, err := policy.ComputeJusticeTxOuts(
|
outputs, err := policy.ComputeJusticeTxOuts(
|
||||||
totalAmount, int64(txWeight), justiceKit.SweepAddress(),
|
totalAmount, txWeight, justiceKit.SweepAddress(),
|
||||||
sessionInfo.RewardAddress,
|
sessionInfo.RewardAddress,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ func (t *backupTask) bindSession(session *wtdb.ClientSessionBody,
|
|||||||
// Now, compute the output values depending on whether FlagReward is set
|
// Now, compute the output values depending on whether FlagReward is set
|
||||||
// in the current session's policy.
|
// in the current session's policy.
|
||||||
outputs, err := session.Policy.ComputeJusticeTxOuts(
|
outputs, err := session.Policy.ComputeJusticeTxOuts(
|
||||||
t.totalAmt, int64(weightEstimate.Weight()),
|
t.totalAmt, weightEstimate.Weight(),
|
||||||
t.sweepPkScript, session.RewardPkScript,
|
t.sweepPkScript, session.RewardPkScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@@ -180,8 +181,9 @@ func (p *Policy) Validate() error {
|
|||||||
// that pays no reward to the tower. The value is computed using the weight of
|
// that pays no reward to the tower. The value is computed using the weight of
|
||||||
// of the justice transaction and subtracting an amount that satisfies the
|
// of the justice transaction and subtracting an amount that satisfies the
|
||||||
// policy's fee rate.
|
// policy's fee rate.
|
||||||
func (p *Policy) ComputeAltruistOutput(totalAmt btcutil.Amount,
|
func (p *Policy) ComputeAltruistOutput(
|
||||||
txWeight int64, sweepScript []byte) (btcutil.Amount, error) {
|
totalAmt btcutil.Amount, txWeight lntypes.WeightUnit,
|
||||||
|
sweepScript []byte) (btcutil.Amount, error) {
|
||||||
|
|
||||||
txFee := p.SweepFeeRate.FeeForWeight(txWeight)
|
txFee := p.SweepFeeRate.FeeForWeight(txWeight)
|
||||||
if txFee > totalAmt {
|
if txFee > totalAmt {
|
||||||
@@ -204,7 +206,7 @@ func (p *Policy) ComputeAltruistOutput(totalAmt btcutil.Amount,
|
|||||||
// and reward rate. The reward to he tower is subtracted first, before
|
// and reward rate. The reward to he tower is subtracted first, before
|
||||||
// splitting the remaining balance amongst the victim and fees.
|
// splitting the remaining balance amongst the victim and fees.
|
||||||
func (p *Policy) ComputeRewardOutputs(totalAmt btcutil.Amount,
|
func (p *Policy) ComputeRewardOutputs(totalAmt btcutil.Amount,
|
||||||
txWeight int64,
|
txWeight lntypes.WeightUnit,
|
||||||
rewardScript []byte) (btcutil.Amount, btcutil.Amount, error) {
|
rewardScript []byte) (btcutil.Amount, btcutil.Amount, error) {
|
||||||
|
|
||||||
txFee := p.SweepFeeRate.FeeForWeight(txWeight)
|
txFee := p.SweepFeeRate.FeeForWeight(txWeight)
|
||||||
@@ -266,7 +268,8 @@ func ComputeRewardAmount(total btcutil.Amount, base, rate uint32) btcutil.Amount
|
|||||||
// rewardPkScript is the pkScript of the tower where its reward will be
|
// rewardPkScript is the pkScript of the tower where its reward will be
|
||||||
// deposited, and will be
|
// deposited, and will be
|
||||||
// ignored if the blob type does not specify a reward.
|
// ignored if the blob type does not specify a reward.
|
||||||
func (p *Policy) ComputeJusticeTxOuts(totalAmt btcutil.Amount, txWeight int64,
|
func (p *Policy) ComputeJusticeTxOuts(
|
||||||
|
totalAmt btcutil.Amount, txWeight lntypes.WeightUnit,
|
||||||
sweepPkScript, rewardPkScript []byte) ([]*wire.TxOut, error) {
|
sweepPkScript, rewardPkScript []byte) ([]*wire.TxOut, error) {
|
||||||
|
|
||||||
var outputs []*wire.TxOut
|
var outputs []*wire.TxOut
|
||||||
|
|||||||
Reference in new issue
Block a user