@@ -596,7 +596,7 @@ func locateOutputIndex(p *PaymentDescriptor, tx *wire.MsgTx, ourCommit bool,
596
596
// we need to keep track of the indexes of each HTLC in order to properly write
597
597
// the current state to disk, and also to locate the PaymentDescriptor
598
598
// corresponding to HTLC outputs in the commitment transaction.
599
- func (c * commitment ) populateHtlcIndexes () error {
599
+ func (c * commitment ) populateHtlcIndexes (chanType channeldb. ChannelType ) error {
600
600
// First, we'll set up some state to allow us to locate the output
601
601
// index of the all the HTLC's within the commitment transaction. We
602
602
// must keep this index so we can validate the HTLC signatures sent to
@@ -608,8 +608,10 @@ func (c *commitment) populateHtlcIndexes() error {
608
608
// populateIndex is a helper function that populates the necessary
609
609
// indexes within the commitment view for a particular HTLC.
610
610
populateIndex := func (htlc * PaymentDescriptor , incoming bool ) error {
611
- isDust := htlcIsDust (incoming , c .isOurs , c .feePerKw ,
612
- htlc .Amount .ToSatoshis (), c .dustLimit )
611
+ isDust := htlcIsDust (
612
+ chanType , incoming , c .isOurs , c .feePerKw ,
613
+ htlc .Amount .ToSatoshis (), c .dustLimit ,
614
+ )
613
615
614
616
var err error
615
617
switch {
@@ -782,8 +784,10 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
782
784
// generate them in order to locate the outputs within the commitment
783
785
// transaction. As we'll mark dust with a special output index in the
784
786
// on-disk state snapshot.
785
- isDustLocal := htlcIsDust (htlc .Incoming , true , feeRate ,
786
- htlc .Amt .ToSatoshis (), lc .channelState .LocalChanCfg .DustLimit )
787
+ isDustLocal := htlcIsDust (
788
+ chanType , htlc .Incoming , true , feeRate ,
789
+ htlc .Amt .ToSatoshis (), lc .channelState .LocalChanCfg .DustLimit ,
790
+ )
787
791
if ! isDustLocal && localCommitKeys != nil {
788
792
ourP2WSH , ourWitnessScript , err = genHtlcScript (
789
793
chanType , htlc .Incoming , true , htlc .RefundTimeout ,
@@ -793,8 +797,10 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
793
797
return pd , err
794
798
}
795
799
}
796
- isDustRemote := htlcIsDust (htlc .Incoming , false , feeRate ,
797
- htlc .Amt .ToSatoshis (), lc .channelState .RemoteChanCfg .DustLimit )
800
+ isDustRemote := htlcIsDust (
801
+ chanType , htlc .Incoming , false , feeRate ,
802
+ htlc .Amt .ToSatoshis (), lc .channelState .RemoteChanCfg .DustLimit ,
803
+ )
798
804
if ! isDustRemote && remoteCommitKeys != nil {
799
805
theirP2WSH , theirWitnessScript , err = genHtlcScript (
800
806
chanType , htlc .Incoming , false , htlc .RefundTimeout ,
@@ -930,7 +936,8 @@ func (lc *LightningChannel) diskCommitToMemCommit(isLocal bool,
930
936
931
937
// Finally, we'll re-populate the HTLC index for this state so we can
932
938
// properly locate each HTLC within the commitment transaction.
933
- if err := commit .populateHtlcIndexes (); err != nil {
939
+ err = commit .populateHtlcIndexes (lc .channelState .ChanType )
940
+ if err != nil {
934
941
return nil , err
935
942
}
936
943
@@ -1410,8 +1417,10 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
1410
1417
pd .OnionBlob = make ([]byte , len (wireMsg .OnionBlob ))
1411
1418
copy (pd .OnionBlob [:], wireMsg .OnionBlob [:])
1412
1419
1413
- isDustRemote := htlcIsDust (false , false , feeRate ,
1414
- wireMsg .Amount .ToSatoshis (), remoteDustLimit )
1420
+ isDustRemote := htlcIsDust (
1421
+ lc .channelState .ChanType , false , false , feeRate ,
1422
+ wireMsg .Amount .ToSatoshis (), remoteDustLimit ,
1423
+ )
1415
1424
if ! isDustRemote {
1416
1425
theirP2WSH , theirWitnessScript , err := genHtlcScript (
1417
1426
lc .channelState .ChanType , false , false ,
@@ -2168,7 +2177,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
2168
2177
// If the HTLC is dust, then we'll skip it as it doesn't have
2169
2178
// an output on the commitment transaction.
2170
2179
if htlcIsDust (
2171
- htlc .Incoming , false ,
2180
+ chanState . ChanType , htlc .Incoming , false ,
2172
2181
chainfee .SatPerKWeight (revokedSnapshot .FeePerKw ),
2173
2182
htlc .Amt .ToSatoshis (), chanState .RemoteChanCfg .DustLimit ,
2174
2183
) {
@@ -2239,25 +2248,14 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
2239
2248
}, nil
2240
2249
}
2241
2250
2242
- // htlcTimeoutFee returns the fee in satoshis required for an HTLC timeout
2243
- // transaction based on the current fee rate.
2244
- func htlcTimeoutFee (feePerKw chainfee.SatPerKWeight ) btcutil.Amount {
2245
- return feePerKw .FeeForWeight (input .HtlcTimeoutWeight )
2246
- }
2247
-
2248
- // htlcSuccessFee returns the fee in satoshis required for an HTLC success
2249
- // transaction based on the current fee rate.
2250
- func htlcSuccessFee (feePerKw chainfee.SatPerKWeight ) btcutil.Amount {
2251
- return feePerKw .FeeForWeight (input .HtlcSuccessWeight )
2252
- }
2253
-
2254
2251
// htlcIsDust determines if an HTLC output is dust or not depending on two
2255
2252
// bits: if the HTLC is incoming and if the HTLC will be placed on our
2256
2253
// commitment transaction, or theirs. These two pieces of information are
2257
2254
// require as we currently used second-level HTLC transactions as off-chain
2258
2255
// covenants. Depending on the two bits, we'll either be using a timeout or
2259
2256
// success transaction which have different weights.
2260
- func htlcIsDust (incoming , ourCommit bool , feePerKw chainfee.SatPerKWeight ,
2257
+ func htlcIsDust (chanType channeldb.ChannelType ,
2258
+ incoming , ourCommit bool , feePerKw chainfee.SatPerKWeight ,
2261
2259
htlcAmt , dustLimit btcutil.Amount ) bool {
2262
2260
2263
2261
// First we'll determine the fee required for this HTLC based on if this is
@@ -2269,25 +2267,25 @@ func htlcIsDust(incoming, ourCommit bool, feePerKw chainfee.SatPerKWeight,
2269
2267
// If this is an incoming HTLC on our commitment transaction, then the
2270
2268
// second-level transaction will be a success transaction.
2271
2269
case incoming && ourCommit :
2272
- htlcFee = htlcSuccessFee ( feePerKw )
2270
+ htlcFee = HtlcSuccessFee ( chanType , feePerKw )
2273
2271
2274
2272
// If this is an incoming HTLC on their commitment transaction, then
2275
2273
// we'll be using a second-level timeout transaction as they've added
2276
2274
// this HTLC.
2277
2275
case incoming && ! ourCommit :
2278
- htlcFee = htlcTimeoutFee ( feePerKw )
2276
+ htlcFee = HtlcTimeoutFee ( chanType , feePerKw )
2279
2277
2280
2278
// If this is an outgoing HTLC on our commitment transaction, then
2281
2279
// we'll be using a timeout transaction as we're the sender of the
2282
2280
// HTLC.
2283
2281
case ! incoming && ourCommit :
2284
- htlcFee = htlcTimeoutFee ( feePerKw )
2282
+ htlcFee = HtlcTimeoutFee ( chanType , feePerKw )
2285
2283
2286
2284
// If this is an outgoing HTLC on their commitment transaction, then
2287
2285
// we'll be using an HTLC success transaction as they're the receiver
2288
2286
// of this HTLC.
2289
2287
case ! incoming && ! ourCommit :
2290
- htlcFee = htlcSuccessFee ( feePerKw )
2288
+ htlcFee = HtlcSuccessFee ( chanType , feePerKw )
2291
2289
}
2292
2290
2293
2291
return (htlcAmt - htlcFee ) < dustLimit
@@ -2431,7 +2429,7 @@ func (lc *LightningChannel) fetchCommitmentView(remoteChain bool,
2431
2429
2432
2430
// Finally, we'll populate all the HTLC indexes so we can track the
2433
2431
// locations of each HTLC in the commitment state.
2434
- if err := c .populateHtlcIndexes (); err != nil {
2432
+ if err := c .populateHtlcIndexes (lc . channelState . ChanType ); err != nil {
2435
2433
return nil , err
2436
2434
}
2437
2435
@@ -2769,8 +2767,10 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
2769
2767
// dust output after taking into account second-level HTLC fees, then a
2770
2768
// sigJob will be generated and appended to the current batch.
2771
2769
for _ , htlc := range remoteCommitView .incomingHTLCs {
2772
- if htlcIsDust (true , false , feePerKw , htlc .Amount .ToSatoshis (),
2773
- dustLimit ) {
2770
+ if htlcIsDust (
2771
+ chanType , true , false , feePerKw ,
2772
+ htlc .Amount .ToSatoshis (), dustLimit ,
2773
+ ) {
2774
2774
continue
2775
2775
}
2776
2776
@@ -2785,7 +2785,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
2785
2785
// HTLC timeout transaction for them. The output of the timeout
2786
2786
// transaction needs to account for fees, so we'll compute the
2787
2787
// required fee and output now.
2788
- htlcFee := htlcTimeoutFee ( feePerKw )
2788
+ htlcFee := HtlcTimeoutFee ( chanType , feePerKw )
2789
2789
outputAmt := htlc .Amount .ToSatoshis () - htlcFee
2790
2790
2791
2791
// With the fee calculate, we can properly create the HTLC
@@ -2822,8 +2822,10 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
2822
2822
sigBatch = append (sigBatch , sigJob )
2823
2823
}
2824
2824
for _ , htlc := range remoteCommitView .outgoingHTLCs {
2825
- if htlcIsDust (false , false , feePerKw , htlc .Amount .ToSatoshis (),
2826
- dustLimit ) {
2825
+ if htlcIsDust (
2826
+ chanType , false , false , feePerKw ,
2827
+ htlc .Amount .ToSatoshis (), dustLimit ,
2828
+ ) {
2827
2829
continue
2828
2830
}
2829
2831
@@ -2836,7 +2838,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
2836
2838
// HTLC success transaction for them. The output of the timeout
2837
2839
// transaction needs to account for fees, so we'll compute the
2838
2840
// required fee and output now.
2839
- htlcFee := htlcSuccessFee ( feePerKw )
2841
+ htlcFee := HtlcSuccessFee ( chanType , feePerKw )
2840
2842
outputAmt := htlc .Amount .ToSatoshis () - htlcFee
2841
2843
2842
2844
// With the proper output amount calculated, we can now
@@ -3785,16 +3787,20 @@ func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool,
3785
3787
// weight, needed to calculate the transaction fee.
3786
3788
var totalHtlcWeight int64
3787
3789
for _ , htlc := range filteredHTLCView .ourUpdates {
3788
- if htlcIsDust (remoteChain , ! remoteChain , feePerKw ,
3789
- htlc .Amount .ToSatoshis (), dustLimit ) {
3790
+ if htlcIsDust (
3791
+ lc .channelState .ChanType , remoteChain , ! remoteChain ,
3792
+ feePerKw , htlc .Amount .ToSatoshis (), dustLimit ,
3793
+ ) {
3790
3794
continue
3791
3795
}
3792
3796
3793
3797
totalHtlcWeight += input .HTLCWeight
3794
3798
}
3795
3799
for _ , htlc := range filteredHTLCView .theirUpdates {
3796
- if htlcIsDust (! remoteChain , ! remoteChain , feePerKw ,
3797
- htlc .Amount .ToSatoshis (), dustLimit ) {
3800
+ if htlcIsDust (
3801
+ lc .channelState .ChanType , ! remoteChain , ! remoteChain ,
3802
+ feePerKw , htlc .Amount .ToSatoshis (), dustLimit ,
3803
+ ) {
3798
3804
continue
3799
3805
}
3800
3806
@@ -3857,7 +3863,7 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
3857
3863
Index : uint32 (htlc .localOutputIndex ),
3858
3864
}
3859
3865
3860
- htlcFee := htlcSuccessFee ( feePerKw )
3866
+ htlcFee := HtlcSuccessFee ( chanType , feePerKw )
3861
3867
outputAmt := htlc .Amount .ToSatoshis () - htlcFee
3862
3868
3863
3869
successTx , err := createHtlcSuccessTx (
@@ -3911,7 +3917,7 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
3911
3917
Index : uint32 (htlc .localOutputIndex ),
3912
3918
}
3913
3919
3914
- htlcFee := htlcTimeoutFee ( feePerKw )
3920
+ htlcFee := HtlcTimeoutFee ( chanType , feePerKw )
3915
3921
outputAmt := htlc .Amount .ToSatoshis () - htlcFee
3916
3922
3917
3923
timeoutTx , err := createHtlcTimeoutTx (
@@ -5383,7 +5389,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
5383
5389
// In order to properly reconstruct the HTLC transaction, we'll need to
5384
5390
// re-calculate the fee required at this state, so we can add the
5385
5391
// correct output value amount to the transaction.
5386
- htlcFee := htlcTimeoutFee ( feePerKw )
5392
+ htlcFee := HtlcTimeoutFee ( chanType , feePerKw )
5387
5393
secondLevelOutputAmt := htlc .Amt .ToSatoshis () - htlcFee
5388
5394
5389
5395
// With the fee calculated, re-construct the second level timeout
@@ -5513,7 +5519,7 @@ func newIncomingHtlcResolution(signer input.Signer,
5513
5519
5514
5520
// First, we'll reconstruct the original HTLC success transaction,
5515
5521
// taking into account the fee rate used.
5516
- htlcFee := htlcSuccessFee ( feePerKw )
5522
+ htlcFee := HtlcSuccessFee ( chanType , feePerKw )
5517
5523
secondLevelOutputAmt := htlc .Amt .ToSatoshis () - htlcFee
5518
5524
successTx , err := createHtlcSuccessTx (
5519
5525
chanType , op , secondLevelOutputAmt , csvDelay ,
@@ -5637,8 +5643,10 @@ func extractHtlcResolutions(feePerKw chainfee.SatPerKWeight, ourCommit bool,
5637
5643
// We'll skip any HTLC's which were dust on the commitment
5638
5644
// transaction, as these don't have a corresponding output
5639
5645
// within the commitment transaction.
5640
- if htlcIsDust (htlc .Incoming , ourCommit , feePerKw ,
5641
- htlc .Amt .ToSatoshis (), dustLimit ) {
5646
+ if htlcIsDust (
5647
+ chanType , htlc .Incoming , ourCommit , feePerKw ,
5648
+ htlc .Amt .ToSatoshis (), dustLimit ,
5649
+ ) {
5642
5650
continue
5643
5651
}
5644
5652
@@ -6141,7 +6149,7 @@ func (lc *LightningChannel) availableCommitmentBalance(view *htlcView,
6141
6149
// For an extra HTLC fee to be paid on our commitment, the HTLC must be
6142
6150
// large enough to make a non-dust HTLC timeout transaction.
6143
6151
htlcFee := lnwire .NewMSatFromSatoshis (
6144
- htlcTimeoutFee ( feePerKw ),
6152
+ HtlcTimeoutFee ( lc . channelState . ChanType , feePerKw ),
6145
6153
)
6146
6154
6147
6155
// If we are looking at the remote commitment, we must use the remote
@@ -6151,7 +6159,7 @@ func (lc *LightningChannel) availableCommitmentBalance(view *htlcView,
6151
6159
lc .channelState .RemoteChanCfg .DustLimit ,
6152
6160
)
6153
6161
htlcFee = lnwire .NewMSatFromSatoshis (
6154
- htlcSuccessFee ( feePerKw ),
6162
+ HtlcSuccessFee ( lc . channelState . ChanType , feePerKw ),
6155
6163
)
6156
6164
}
6157
6165
0 commit comments