lwallet: only count public channels towards our reserved value

Since private channels (most likely) won't be used for routing other
than as last hop, they bear a smaller risk that we must quickly force
close them in order to resolve a HTLC up/downstream.

In the case where it actually has to be force to resolve a payment (if
it is the first/last hop on a routed payment), we can assume that the
router will have UTXOs available from the reserved value from the
incoming public channel.
This commit is contained in:
Johan T. Halseth 2021-05-10 10:06:23 +02:00
parent a0b6a0b00b
commit 8e1087d1cd
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

@ -604,9 +604,11 @@ func (l *LightningWallet) PsbtFundingVerify(pendingChanID [32]byte,
// If this commit type is an anchor channel we add that to our counter,
// but only if we are contributing funds to the channel. This is done
// to still allow incoming channels even though we have no UTXOs
// available, as in bootstrapping phases.
// available, as in bootstrapping phases. We only count public
// channels.
isPublic := pendingReservation.partialState.ChannelFlags&lnwire.FFAnnounceChannel != 0
if pendingReservation.partialState.ChanType.HasAnchors() &&
intent.LocalFundingAmt() > 0 {
intent.LocalFundingAmt() > 0 && isPublic {
numAnchors++
}
@ -819,9 +821,11 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
// If this commit type is an anchor channel we add that to our counter,
// but only if we are contributing funds to the channel. This is done
// to still allow incoming channels even though we have no UTXOs
// available, as in bootstrapping phases.
// available, as in bootstrapping phases. We only count public
// channels.
isPublic := req.Flags&lnwire.FFAnnounceChannel != 0
if req.CommitType == CommitmentTypeAnchorsZeroFeeHtlcTx &&
fundingIntent.LocalFundingAmt() > 0 {
fundingIntent.LocalFundingAmt() > 0 && isPublic {
numAnchors++
}
@ -888,8 +892,8 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
req.err <- nil
}
// currentNumAnchorChans returns the current number of anchor channels the
// wallet should be ready to fee bump if needed.
// currentNumAnchorChans returns the current number of non-private anchor
// channels the wallet should be ready to fee bump if needed.
func (l *LightningWallet) currentNumAnchorChans() (int, error) {
// Count all anchor channels that are open or pending
// open, or waiting close.
@ -899,10 +903,22 @@ func (l *LightningWallet) currentNumAnchorChans() (int, error) {
}
var numAnchors int
for _, c := range chans {
cntChannel := func(c *channeldb.OpenChannel) {
// We skip private channels, as we assume they won't be used
// for routing.
if c.ChannelFlags&lnwire.FFAnnounceChannel == 0 {
return
}
// Count anchor channels.
if c.ChanType.HasAnchors() {
numAnchors++
}
}
for _, c := range chans {
cntChannel(c)
}
// We also count pending close channels.
@ -925,9 +941,7 @@ func (l *LightningWallet) currentNumAnchorChans() (int, error) {
continue
}
if c.ChanType.HasAnchors() {
numAnchors++
}
cntChannel(c)
}
return numAnchors, nil