Skip to content

Commit

Permalink
lnwallet: export AnchorSize
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed May 1, 2024
1 parent 5e1dd2a commit fa61f26
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8575,7 +8575,7 @@ func NewAnchorResolution(chanState *channeldb.OpenChannel,
WitnessScript: anchorWitnessScript,
Output: &wire.TxOut{
PkScript: localAnchor.PkScript(),
Value: int64(anchorSize),
Value: int64(AnchorSize),
},
HashType: sweepSigHash(chanState.ChanType),
}
Expand All @@ -8587,7 +8587,7 @@ func NewAnchorResolution(chanState *channeldb.OpenChannel,

//nolint:lll
signDesc.PrevOutputFetcher = txscript.NewCannedPrevOutputFetcher(
localAnchor.PkScript(), int64(anchorSize),
localAnchor.PkScript(), int64(AnchorSize),
)

// For anchor outputs with taproot channels, the key desc is
Expand Down Expand Up @@ -9080,7 +9080,7 @@ func (lc *LightningChannel) LocalBalanceDust() bool {
// regain the stats allocated to the anchor outputs with the co-op
// close transaction.
if chanState.ChanType.HasAnchors() && chanState.IsInitiator {
localBalance += 2 * anchorSize
localBalance += 2 * AnchorSize
}

return localBalance <= chanState.LocalChanCfg.DustLimit
Expand All @@ -9100,7 +9100,7 @@ func (lc *LightningChannel) RemoteBalanceDust() bool {
// regain the stats allocated to the anchor outputs with the co-op
// close transaction.
if chanState.ChanType.HasAnchors() && !chanState.IsInitiator {
remoteBalance += 2 * anchorSize
remoteBalance += 2 * AnchorSize
}

return remoteBalance <= chanState.RemoteChanCfg.DustLimit
Expand Down
10 changes: 5 additions & 5 deletions lnwallet/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
testCoopClose(t, &coopCloseTestCase{
chanType: channeldb.SingleFunderTweaklessBit |
channeldb.AnchorOutputsBit,
anchorAmt: anchorSize * 2,
anchorAmt: AnchorSize * 2,
})
})
}
Expand Down Expand Up @@ -823,7 +823,7 @@ func TestForceClose(t *testing.T) {
chanType: channeldb.SingleFunderTweaklessBit |
channeldb.AnchorOutputsBit,
expectedCommitWeight: input.AnchorCommitWeight,
anchorAmt: anchorSize * 2,
anchorAmt: AnchorSize * 2,
})
})
t.Run("taproot", func(t *testing.T) {
Expand All @@ -832,7 +832,7 @@ func TestForceClose(t *testing.T) {
channeldb.AnchorOutputsBit |
channeldb.SimpleTaprootFeatureBit,
expectedCommitWeight: input.TaprootCommitWeight,
anchorAmt: anchorSize * 2,
anchorAmt: AnchorSize * 2,
})
})
t.Run("taproot with tapscript root", func(t *testing.T) {
Expand All @@ -842,7 +842,7 @@ func TestForceClose(t *testing.T) {
channeldb.SimpleTaprootFeatureBit |
channeldb.TapscriptRootBit,
expectedCommitWeight: input.TaprootCommitWeight,
anchorAmt: anchorSize * 2,
anchorAmt: AnchorSize * 2,
})
})
}
Expand Down Expand Up @@ -928,7 +928,7 @@ func testForceClose(t *testing.T, testCase *forceCloseTestCase) {
t.Fatal("commit tx not referenced by anchor res")
}
if anchorRes.AnchorSignDescriptor.Output.Value !=
int64(anchorSize) {
int64(AnchorSize) {

t.Fatal("unexpected anchor size")
}
Expand Down
10 changes: 5 additions & 5 deletions lnwallet/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/lightningnetwork/lnd/tlv"
)

// anchorSize is the constant anchor output size.
const anchorSize = btcutil.Amount(330)
// AnchorSize is the constant anchor output size.
const AnchorSize = btcutil.Amount(330)

// DefaultAnchorsCommitMaxFeeRateSatPerVByte is the default max fee rate in
// sat/vbyte the initiator will use for anchor channels. This should be enough
Expand Down Expand Up @@ -1184,7 +1184,7 @@ func CreateCommitTx(chanType channeldb.ChannelType,
if localOutput || numHTLCs > 0 {
commitTx.AddTxOut(&wire.TxOut{
PkScript: localAnchor.PkScript(),
Value: int64(anchorSize),
Value: int64(AnchorSize),
})
}

Expand All @@ -1193,7 +1193,7 @@ func CreateCommitTx(chanType channeldb.ChannelType,
if remoteOutput || numHTLCs > 0 {
commitTx.AddTxOut(&wire.TxOut{
PkScript: remoteAnchor.PkScript(),
Value: int64(anchorSize),
Value: int64(AnchorSize),
})
}
}
Expand All @@ -1218,7 +1218,7 @@ func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool,
// Since the initiator's balance also is stored after subtracting the
// anchor values, add that back in case this was an anchor commitment.
if chanType.HasAnchors() {
initiatorDelta += 2 * anchorSize
initiatorDelta += 2 * AnchorSize
}

// The initiator will pay the full coop close fee, subtract that value
Expand Down
2 changes: 1 addition & 1 deletion lnwallet/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
// addition to the two anchor outputs.
feeMSat := lnwire.NewMSatFromSatoshis(commitFee)
if req.CommitType.HasAnchors() {
feeMSat += 2 * lnwire.NewMSatFromSatoshis(anchorSize)
feeMSat += 2 * lnwire.NewMSatFromSatoshis(AnchorSize)
}

// Used to cut down on verbosity.
Expand Down
2 changes: 1 addition & 1 deletion lnwallet/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType,
commitFee := calcStaticFee(chanType, 0)
var anchorAmt btcutil.Amount
if chanType.HasAnchors() {
anchorAmt += 2 * anchorSize
anchorAmt += 2 * AnchorSize
}

aliceBalance := lnwire.NewMSatFromSatoshis(
Expand Down
2 changes: 1 addition & 1 deletion lnwallet/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ func createTestChannelsForVectors(tc *testContext, chanType channeldb.ChannelTyp

var anchorAmt btcutil.Amount
if chanType.HasAnchors() {
anchorAmt = 2 * anchorSize
anchorAmt = 2 * AnchorSize
}

remoteCommitTx, localCommitTx, err := CreateCommitmentTxns(
Expand Down

0 comments on commit fa61f26

Please sign in to comment.