fundingmanager: count channels pending open when checking MaxPending
This commit is contained in:
parent
3afa16b7a6
commit
8b6e7b24aa
@ -961,23 +961,42 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
// Check number of pending channels to be smaller than maximum allowed
|
// Check number of pending channels to be smaller than maximum allowed
|
||||||
// number and send ErrorGeneric to remote peer if condition is
|
// number and send ErrorGeneric to remote peer if condition is
|
||||||
// violated.
|
// violated.
|
||||||
peerIDKey := newSerializedKey(fmsg.peer.IdentityKey())
|
peerPubKey := fmsg.peer.IdentityKey()
|
||||||
|
peerIDKey := newSerializedKey(peerPubKey)
|
||||||
|
|
||||||
msg := fmsg.msg
|
msg := fmsg.msg
|
||||||
amt := msg.FundingAmount
|
amt := msg.FundingAmount
|
||||||
|
|
||||||
|
// We count the number of pending channels for this peer. This is the
|
||||||
|
// sum of the active reservations and the channels pending open in the
|
||||||
|
// database.
|
||||||
|
f.resMtx.RLock()
|
||||||
|
numPending := len(f.activeReservations[peerIDKey])
|
||||||
|
f.resMtx.RUnlock()
|
||||||
|
|
||||||
|
channels, err := f.cfg.Wallet.Cfg.Database.FetchOpenChannels(peerPubKey)
|
||||||
|
if err != nil {
|
||||||
|
f.failFundingFlow(
|
||||||
|
fmsg.peer, fmsg.msg.PendingChannelID, err,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range channels {
|
||||||
|
if c.IsPending {
|
||||||
|
numPending++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): modify to only accept a _single_ pending channel per
|
// TODO(roasbeef): modify to only accept a _single_ pending channel per
|
||||||
// block unless white listed
|
// block unless white listed
|
||||||
f.resMtx.RLock()
|
if numPending >= cfg.MaxPendingChannels {
|
||||||
if len(f.activeReservations[peerIDKey]) >= cfg.MaxPendingChannels {
|
|
||||||
f.resMtx.RUnlock()
|
|
||||||
f.failFundingFlow(
|
f.failFundingFlow(
|
||||||
fmsg.peer, fmsg.msg.PendingChannelID,
|
fmsg.peer, fmsg.msg.PendingChannelID,
|
||||||
lnwire.ErrMaxPendingChannels,
|
lnwire.ErrMaxPendingChannels,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f.resMtx.RUnlock()
|
|
||||||
|
|
||||||
// We'll also reject any requests to create channels until we're fully
|
// We'll also reject any requests to create channels until we're fully
|
||||||
// synced to the network as we won't be able to properly validate the
|
// synced to the network as we won't be able to properly validate the
|
||||||
|
Loading…
Reference in New Issue
Block a user