Skip to content

Commit 1fc45e9

Browse files
authored
fix: remove setting peer healthy true in case of underpopulated bins (#5145)
1 parent 930110d commit 1fc45e9

3 files changed

Lines changed: 11 additions & 23 deletions

File tree

pkg/node/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ func NewBee(
975975
return nil, fmt.Errorf("status service: %w", err)
976976
}
977977

978-
saludService := salud.New(nodeStatus, kad, localStore, logger, detector, api.FullMode.String(), salud.DefaultMinPeersPerBin, salud.DefaultDurPercentile, salud.DefaultConnsPercentile)
978+
saludService := salud.New(nodeStatus, kad, localStore, logger, detector, api.FullMode.String(), salud.DefaultDurPercentile, salud.DefaultConnsPercentile)
979979
b.saludCloser = saludService
980980

981981
rC, unsub := saludService.SubscribeNetworkStorageRadius()

pkg/salud/salud.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const (
2929
initialBackoffDelay = 10 * time.Second
3030
maxBackoffDelay = 5 * time.Minute
3131
backoffFactor = 2
32-
DefaultMinPeersPerBin = 4
3332
DefaultDurPercentile = 0.4 // consider 40% as healthy, lower percentile = stricter duration check
3433
DefaultConnsPercentile = 0.8 // consider 80% as healthy, lower percentile = stricter conns check
3534
)
@@ -64,7 +63,6 @@ func New(
6463
logger log.Logger,
6564
startupStabilizer stabilization.Subscriber,
6665
mode string,
67-
minPeersPerbin int,
6866
durPercentile float64,
6967
connsPercentile float64,
7068
) *service {
@@ -81,12 +79,12 @@ func New(
8179
}
8280

8381
s.wg.Add(1)
84-
go s.worker(startupStabilizer, mode, minPeersPerbin, durPercentile, connsPercentile)
82+
go s.worker(startupStabilizer, mode, durPercentile, connsPercentile)
8583

8684
return s
8785
}
8886

89-
func (s *service) worker(startupStabilizer stabilization.Subscriber, mode string, minPeersPerbin int, durPercentile float64, connsPercentile float64) {
87+
func (s *service) worker(startupStabilizer stabilization.Subscriber, mode string, durPercentile float64, connsPercentile float64) {
9088
defer s.wg.Done()
9189

9290
sub, unsubscribe := startupStabilizer.Subscribe()
@@ -102,7 +100,7 @@ func (s *service) worker(startupStabilizer stabilization.Subscriber, mode string
102100
currentDelay := initialBackoffDelay
103101

104102
for {
105-
s.salud(mode, minPeersPerbin, durPercentile, connsPercentile)
103+
s.salud(mode, durPercentile, connsPercentile)
106104

107105
select {
108106
case <-s.quit:
@@ -134,13 +132,12 @@ type peer struct {
134132
// salud acquires the status snapshot of every peer and computes an nth percentile of response duration and connected
135133
// per count, the most common storage radius, and the batch commitment, and based on these values, marks peers as unhealhy that fall beyond
136134
// the allowed thresholds.
137-
func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64, connsPercentile float64) {
135+
func (s *service) salud(mode string, durPercentile float64, connsPercentile float64) {
138136
var (
139137
mtx sync.Mutex
140138
wg sync.WaitGroup
141139
totaldur float64
142140
peers []peer
143-
bins [swarm.MaxBins]int
144141
)
145142

146143
err := s.topology.EachConnectedPeer(func(addr swarm.Address, bin uint8) (stop bool, jumpToNext bool, err error) {
@@ -165,7 +162,6 @@ func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64,
165162
}
166163

167164
mtx.Lock()
168-
bins[bin]++
169165
totaldur += dur.Seconds()
170166
peers = append(peers, peer{snapshot, dur, addr, bin, s.reserve.IsWithinStorageRadius(addr)})
171167
mtx.Unlock()
@@ -206,17 +202,10 @@ func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64,
206202

207203
var healthy bool
208204

209-
// every bin should have at least some peers, healthy or not
210-
if bins[peer.bin] <= minPeersPerbin {
211-
s.metrics.Healthy.Inc()
212-
s.topology.UpdatePeerHealth(peer.addr, true, peer.dur)
213-
continue
214-
}
215-
216205
if networkRadius > 0 && peer.status.CommittedDepth < uint32(networkRadius-2) {
217206
s.logger.Debug("radius health failure", "radius", peer.status.CommittedDepth, "peer_address", peer.addr, "bin", peer.bin)
218207
} else if peer.dur.Seconds() > pDur {
219-
s.logger.Debug("response duration below threshold", "duration", peer.dur, "peer_address", peer.addr, "bin", peer.bin)
208+
s.logger.Debug("response duration above threshold", "duration", peer.dur, "peer_address", peer.addr, "bin", peer.bin)
220209
} else if peer.status.ConnectedPeers < pConns {
221210
s.logger.Debug("connections count below threshold", "connections", peer.status.ConnectedPeers, "peer_address", peer.addr, "bin", peer.bin)
222211
} else if peer.status.BatchCommitment != commitment {
@@ -230,7 +219,6 @@ func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64,
230219
s.metrics.Healthy.Inc()
231220
} else {
232221
s.metrics.Unhealthy.Inc()
233-
bins[peer.bin]--
234222
}
235223
}
236224

pkg/salud/salud_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestSalud(t *testing.T) {
7272
mockstorer.WithCapacityDoubling(2),
7373
)
7474

75-
service := salud.New(statusM, topM, reserve, log.Noop, stabilmock.NewSubscriber(true), "full", 0, 0.8, 0.8)
75+
service := salud.New(statusM, topM, reserve, log.Noop, stabilmock.NewSubscriber(true), "full", 0.8, 0.8)
7676

7777
err := spinlock.Wait(time.Minute, func() bool {
7878
return len(topM.PeersHealth()) == len(peers)
@@ -119,7 +119,7 @@ func TestSelfUnhealthyRadius(t *testing.T) {
119119
mockstorer.WithCapacityDoubling(0),
120120
)
121121

122-
service := salud.New(statusM, topM, reserve, log.Noop, stabilmock.NewSubscriber(true), "full", 0, 0.8, 0.8)
122+
service := salud.New(statusM, topM, reserve, log.Noop, stabilmock.NewSubscriber(true), "full", 0.8, 0.8)
123123
testutil.CleanupCloser(t, service)
124124

125125
err := spinlock.Wait(time.Minute, func() bool {
@@ -157,7 +157,7 @@ func TestSelfHealthyCapacityDoubling(t *testing.T) {
157157
mockstorer.WithCapacityDoubling(2),
158158
)
159159

160-
service := salud.New(statusM, topM, reserve, log.Noop, stabilmock.NewSubscriber(true), "full", 0, 0.8, 0.8)
160+
service := salud.New(statusM, topM, reserve, log.Noop, stabilmock.NewSubscriber(true), "full", 0.8, 0.8)
161161
testutil.CleanupCloser(t, service)
162162

163163
err := spinlock.Wait(time.Minute, func() bool {
@@ -187,7 +187,7 @@ func TestSubToRadius(t *testing.T) {
187187

188188
topM := topMock.NewTopologyDriver(topMock.WithPeers(addrs...))
189189

190-
service := salud.New(&statusMock{make(map[string]peer)}, topM, mockstorer.NewReserve(), log.Noop, stabilmock.NewSubscriber(true), "full", 0, 0.8, 0.8)
190+
service := salud.New(&statusMock{make(map[string]peer)}, topM, mockstorer.NewReserve(), log.Noop, stabilmock.NewSubscriber(true), "full", 0.8, 0.8)
191191

192192
c, unsub := service.SubscribeNetworkStorageRadius()
193193
t.Cleanup(unsub)
@@ -220,7 +220,7 @@ func TestUnsub(t *testing.T) {
220220

221221
topM := topMock.NewTopologyDriver(topMock.WithPeers(addrs...))
222222

223-
service := salud.New(&statusMock{make(map[string]peer)}, topM, mockstorer.NewReserve(), log.Noop, stabilmock.NewSubscriber(true), "full", 0, 0.8, 0.8)
223+
service := salud.New(&statusMock{make(map[string]peer)}, topM, mockstorer.NewReserve(), log.Noop, stabilmock.NewSubscriber(true), "full", 0.8, 0.8)
224224
testutil.CleanupCloser(t, service)
225225

226226
c, unsub := service.SubscribeNetworkStorageRadius()

0 commit comments

Comments
 (0)