multi: allow disable banning peers

When users set `gossip.ban-threshold` to 0, it's now treated as setting
the ban score to max uint64, which effectively disables the banning. We
still want to record the peer's ban score in case we need it for future
debugging.
This commit is contained in:
yyforyongyu committed 2025-08-04 15:46:16 +08:00
1 parent a6f8617e7c
commit 60603f0854
4 files changed
+14 -4

No files matched your search

+8
View File
@@ -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,
+3 -2
View File
@@ -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.