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,