lnwallet+fundingmgr: ignore shim channels in pending count
Externally funded channels are expected by the user and explicitly registered through the use of a funding shim and should therefore not count towards the max pending channel count which is primarily there to mitigate DoS attacks.
This commit is contained in:
parent
8b894fe321
commit
f2e0ed19ff
@ -1210,9 +1210,21 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
||||
// sum of the active reservations and the channels pending open in the
|
||||
// database.
|
||||
f.resMtx.RLock()
|
||||
numPending := len(f.activeReservations[peerIDKey])
|
||||
reservations := f.activeReservations[peerIDKey]
|
||||
f.resMtx.RUnlock()
|
||||
|
||||
// We don't count reservations that were created from a canned funding
|
||||
// shim. The user has registered the shim and therefore expects this
|
||||
// channel to arrive.
|
||||
numPending := 0
|
||||
for _, res := range reservations {
|
||||
if !res.reservation.IsCannedShim() {
|
||||
numPending++
|
||||
}
|
||||
}
|
||||
|
||||
// Also count the channels that are already pending. There we don't know
|
||||
// the underlying intent anymore, unfortunately.
|
||||
channels, err := f.cfg.Wallet.Cfg.Database.FetchOpenChannels(peerPubKey)
|
||||
if err != nil {
|
||||
f.failFundingFlow(
|
||||
@ -1222,7 +1234,13 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
||||
}
|
||||
|
||||
for _, c := range channels {
|
||||
if c.IsPending {
|
||||
// Pending channels that have a non-zero thaw height were also
|
||||
// created through a canned funding shim. Those also don't
|
||||
// count towards the DoS protection limit.
|
||||
//
|
||||
// TODO(guggero): Properly store the funding type (wallet, shim,
|
||||
// PSBT) on the channel so we don't need to use the thaw height.
|
||||
if c.IsPending && c.ThawHeight == 0 {
|
||||
numPending++
|
||||
}
|
||||
}
|
||||
|
@ -492,6 +492,13 @@ func (r *ChannelReservation) IsPsbt() bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsCannedShim returns true if there is a canned shim funding intent mapped to
|
||||
// this reservation.
|
||||
func (r *ChannelReservation) IsCannedShim() bool {
|
||||
_, ok := r.fundingIntent.(*chanfunding.ShimIntent)
|
||||
return ok
|
||||
}
|
||||
|
||||
// ProcessPsbt continues a previously paused funding flow that involves PSBT to
|
||||
// construct the funding transaction. This method can be called once the PSBT is
|
||||
// finalized and the signed transaction is available.
|
||||
|
Loading…
Reference in New Issue
Block a user