From d5cd9861d2e09c54deb197fcb0e02c6245cc410c Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 7 Dec 2020 14:14:20 +0100 Subject: [PATCH] channeldb+lnwallet: define zero-fee channel type --- channeldb/channel.go | 10 ++++++++++ lnwallet/commitment.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/channeldb/channel.go b/channeldb/channel.go index 41f51337..14a0c62e 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -244,6 +244,10 @@ const ( // that only the responder can decide to cooperatively close the // channel. FrozenBit ChannelType = 1 << 4 + + // ZeroHtlcTxFeeBit indicates that the channel should use zero-fee + // second-level HTLC transactions. + ZeroHtlcTxFeeBit ChannelType = 1 << 5 ) // IsSingleFunder returns true if the channel type if one of the known single @@ -275,6 +279,12 @@ func (c ChannelType) HasAnchors() bool { return c&AnchorOutputsBit == AnchorOutputsBit } +// ZeroHtlcTxFee returns true if this channel type uses second-level HTLC +// transactions signed with zero-fee. +func (c ChannelType) ZeroHtlcTxFee() bool { + return c&ZeroHtlcTxFeeBit == ZeroHtlcTxFeeBit +} + // IsFrozen returns true if the channel is considered to be "frozen". A frozen // channel means that only the responder can initiate a cooperative channel // closure. diff --git a/lnwallet/commitment.go b/lnwallet/commitment.go index f5eaf861..9dbf19b1 100644 --- a/lnwallet/commitment.go +++ b/lnwallet/commitment.go @@ -278,6 +278,12 @@ func CommitWeight(chanType channeldb.ChannelType) int64 { func HtlcTimeoutFee(chanType channeldb.ChannelType, feePerKw chainfee.SatPerKWeight) btcutil.Amount { + // For zero-fee HTLC channels, this will always be zero, regardless of + // feerate. + if chanType.ZeroHtlcTxFee() { + return 0 + } + if chanType.HasAnchors() { return feePerKw.FeeForWeight(input.HtlcTimeoutWeightConfirmed) } @@ -290,6 +296,12 @@ func HtlcTimeoutFee(chanType channeldb.ChannelType, func HtlcSuccessFee(chanType channeldb.ChannelType, feePerKw chainfee.SatPerKWeight) btcutil.Amount { + // For zero-fee HTLC channels, this will always be zero, regardless of + // feerate. + if chanType.ZeroHtlcTxFee() { + return 0 + } + if chanType.HasAnchors() { return feePerKw.FeeForWeight(input.HtlcSuccessWeightConfirmed) }