p2p: anti-entropy, a periodic sync with one random peer

Repairs what gossip lost while two nodes stay connected; cheap because
matching digests end the round at once.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 17:33:06 +01:00
co-authored by Claude Sonnet 5.5
parent 11fd2a88c0
commit a54094ea35
3 changed files with 71 additions and 7 deletions
+17
View File
@@ -492,3 +492,20 @@ func TestSyncWithANodeThatKnowsNoDigests(t *testing.T) {
connect(t, b, a)
eventually(t, "b caught up from an old node", func() bool { return count(b) == 4 })
}
// A listing that gossip never delivered is repaired while the link stays up.
func TestAntiEntropyRepairsWhatGossipMissed(t *testing.T) {
a := startNode(t, nil, "u1x")
b := startNodeWith(t, nil, func(c *Config) { c.AntiEntropyInterval = 200 * time.Millisecond }, "u1x")
connect(t, b, a)
eventually(t, "connected and synced", func() bool { return len(b.RegionPeers("u1x")) == 1 })
l := a.listing(t, "u1xjhx")
if _, err := a.s.Put(context.Background(), l); err != nil { // stored, not published: gossip never sees it
t.Fatal(err)
}
eventually(t, "b repairs the gap without reconnecting", func() bool { return count(b) == 1 })
if b.PeerCount() != 1 {
t.Fatal("the link should have stayed up")
}
}