Skip to content

feat: gossip improvements#5520

Open
sbackend123 wants to merge 10 commits into
masterfrom
feat/gossip-improvements
Open

feat: gossip improvements#5520
sbackend123 wants to merge 10 commits into
masterfrom
feat/gossip-improvements

Conversation

@sbackend123

@sbackend123 sbackend123 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Adds write coalescing for hive outbound gossip. Single-peer BroadcastPeers calls are buffered per addressee and flushed as one batched message after ~1s (configurable via GossipCoalesceInterval), or immediately when the buffer reaches maxBatchSize (30). Calls with 2+ peers are sent without coalescing

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

#5490

Screenshots (if appropriate):

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

sbackend123 and others added 3 commits June 29, 2026 11:48
Discard buffered gossip on shutdown instead of flushing, restore quit
checks in broadcastNow, document the async BroadcastPeers contract, use
fixed 100ms jitter, and clean up tests and metrics.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sbackend123 sbackend123 marked this pull request as ready for review June 29, 2026 12:43
Comment thread pkg/hive/hive.go

select {
case <-ctx.Done():
return total - len(peers), ctx.Err()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you care about the count when context is cancelled? also, why do you care about the count when an error is returned in general (below, shutting down/other send error)

Comment thread pkg/hive/gossip_buffer.go
mu sync.Mutex
pending map[string]*pendingGossip // addressee bytestring -> buffered peers
interval time.Duration
jitter time.Duration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Comment thread pkg/hive/gossip_buffer.go
e, ok := b.pending[key]
if !ok {
var jitter time.Duration
if b.jitter > 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this is needed...

Comment thread pkg/hive/gossip_buffer.go
type pendingGossip struct {
addressee swarm.Address
peers map[string]swarm.Address // peer bytestring -> address (set semantics)
deadline time.Time

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder whether there's a benefit of keeping a deadline per peer. usually, write coalescing is simple enough:

  • have an interval fire at a constant rate
  • if new records arrived by interval fire
  • when new entries arrived, optionally, postpone the sending the sending until the next interval firing (and so also you could extend up to a set upper bound, so that entries don't keep collecting forever but also guarantee that information goes out still relatively quickly)
  • send all the pending sends

also: usually, when a peer arrives - we gossip that peer to all peers (full nodes) and gossip to that peer all of our connected peers.
this in turn means that sending is almost always involving all connected peers. which in turn also means that the timestamps on the individual pendingGossip entries would be almost identical (making the field even more so redundant)

Comment thread pkg/hive/gossip_buffer.go
}

if len(e.peers) >= b.maxBatch {
delete(b.pending, key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really confusing - we first add to the item on the map just to also maybe potentially return it directly? not really add...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants