diff --git a/discovery/ban.go b/discovery/ban.go index c13a21b72..5229c706c 100644 --- a/discovery/ban.go +++ b/discovery/ban.go @@ -2,6 +2,7 @@ package discovery import ( "errors" + "math" "sync" "time" @@ -150,6 +151,13 @@ type banman struct { // newBanman creates a new banman with the default maxBannedPeers. func newBanman(banThreshold uint64) *banman { + // If the ban threshold is set to 0, we'll use the max value to + // effectively disable banning. + if banThreshold == 0 { + log.Warn("Banning is disabled due to zero banThreshold") + banThreshold = math.MaxUint64 + } + return &banman{ peerBanIndex: lru.NewCache[[33]byte, *cachedBanInfo]( maxBannedPeers, diff --git a/discovery/gossiper_test.go b/discovery/gossiper_test.go index 6b9a1d58f..58c975bd4 100644 --- a/discovery/gossiper_test.go +++ b/discovery/gossiper_test.go @@ -995,6 +995,7 @@ func createTestCtx(t *testing.T, startHeight uint32, isChanPeer bool) ( GetAlias: getAlias, FindChannel: mockFindChannel, ScidCloser: newMockScidCloser(isChanPeer), + BanThreshold: DefaultBanThreshold, }, selfKeyDesc) if err := gossiper.Start(); err != nil { @@ -4656,7 +4657,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) { } // Loop 100 times to get nodePeer banned. - for i := 0; i < 100; i++ { + for i := range DefaultBanThreshold { // Craft a valid channel announcement for a channel we don't // have. We will ensure that it fails validation by modifying // the tx script. @@ -4746,7 +4747,7 @@ func TestChanAnnBanningChanPeer(t *testing.T) { nodePeer := &mockPeer{remoteKeyPriv1.PubKey(), nil, nil, atomic.Bool{}} // Loop 100 times to get nodePeer banned. - for i := 0; i < 100; i++ { + for i := range DefaultBanThreshold { // Craft a valid channel announcement for a channel we don't // have. We will ensure that it fails validation by modifying // the router. diff --git a/lncfg/gossip.go b/lncfg/gossip.go index 61e5fe739..6eb4661e9 100644 --- a/lncfg/gossip.go +++ b/lncfg/gossip.go @@ -40,7 +40,7 @@ type Gossip struct { FilterConcurrency int `long:"filter-concurrency" description:"The maximum number of concurrent gossip filter applications that can be processed. If not set, defaults to 5."` - BanThreshold uint64 `long:"ban-threshold" description:"The score at which a peer is banned. A peer's ban score is incremented for each invalid gossip message. Invalid messages include those with bad signatures, stale timestamps, excessive updates, or invalid chain data. Once the score reaches this threshold, the peer is banned."` + BanThreshold uint64 `long:"ban-threshold" description:"The score at which a peer is banned. A peer's ban score is incremented for each invalid gossip message. Invalid messages include those with bad signatures, stale timestamps, excessive updates, or invalid chain data. Once the score reaches this threshold, the peer is banned. Set to 0 to disable banning."` } // Parse the pubkeys for the pinned syncers. diff --git a/sample-lnd.conf b/sample-lnd.conf index 38f761783..1e67a609e 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -1788,7 +1788,8 @@ ; that is considered invalid, its ban score is incremented. Once the score ; reaches this threshold, the peer is banned for a default of 48 hours, and we ; will no longer process gossip messages from them. This is a measure to -; protect the node from spam and misbehaving peers. +; protect the node from spam and misbehaving peers. Setting this value to 0 +; disables banning completely. ; ; A gossip message can be considered invalid for several reasons, including: ; - Invalid signature on the announcement.