[client] Publish the network map event once per converged map

Every bounded pass published "Network map updated", so a large map pushed
dozens of identical events to the UI for a single update. The event now
fires from the converging pass, next to the lazy-exclude finalize. A map
ignored as outdated no longer publishes it either, since nothing was
applied.
This commit is contained in:
riccardom
2026-10-20 10:30:43 +02:00
parent 5d09d9218a
commit 9fa50dd7b9
2 changed files with 32 additions and 2 deletions
+2 -2
View File
@@ -1066,8 +1066,6 @@ func (e *Engine) applySyncPass(update *mgmProto.SyncResponse, firstPass bool) (b
return false, err
}
e.statusRecorder.PublishEvent(cProto.SystemEvent_INFO, cProto.SystemEvent_SYSTEM, "Network map updated", "", nil)
return more, nil
}
@@ -1766,6 +1764,8 @@ func (e *Engine) updateNetworkMap(networkMap *mgmProto.NetworkMap, maxBatch int,
excludedLazyPeers := e.toExcludedLazyPeers(remotePeers)
e.connMgr.SetExcludeList(e.ctx, excludedLazyPeers)
doneLazy()
e.statusRecorder.PublishEvent(cProto.SystemEvent_INFO, cProto.SystemEvent_SYSTEM, "Network map updated", "", nil)
}
e.networkSerial = serial
+30
View File
@@ -718,6 +718,36 @@ func TestEngine_UpdateNetworkMap(t *testing.T) {
require.False(t, more, "pass 2 should converge")
require.Len(t, engine.peerStore.PeersPubKey(), 1)
})
// The UI shows one "Network map updated" event per map, so the passes that
// only drain peer batches must stay silent and the converging one publishes.
t.Run("chunked apply publishes one network map event", func(t *testing.T) {
countMapEvents := func() int {
n := 0
for _, ev := range engine.statusRecorder.GetEventHistory() {
if ev.GetMessage() == "Network map updated" {
n++
}
}
return n
}
before := countMapEvents()
nm := &mgmtProto.NetworkMap{
Serial: 8,
RemotePeers: []*mgmtProto.RemotePeerConfig{peer1, peer2, peer3},
}
more, err := engine.updateNetworkMap(nm, 1, true)
require.NoError(t, err)
require.True(t, more, "pass 1 should signal more")
assert.Equal(t, before, countMapEvents(), "a draining pass should not publish the event")
more, err = engine.updateNetworkMap(nm, 1, false)
require.NoError(t, err)
require.False(t, more, "pass 2 should converge")
assert.Equal(t, before+1, countMapEvents(), "the converging pass should publish exactly one event")
})
}
func TestEngine_UpdateNetworkMapWithRoutes(t *testing.T) {