Skip to content

feat: implement suspected#22

Merged
ryandielhenn merged 11 commits intoryandielhenn:mainfrom
hrotovb001:feat/suspected
Mar 26, 2026
Merged

feat: implement suspected#22
ryandielhenn merged 11 commits intoryandielhenn:mainfrom
hrotovb001:feat/suspected

Conversation

@hrotovb001
Copy link
Copy Markdown
Collaborator

@hrotovb001 hrotovb001 commented Mar 22, 2026

Fixes #11

incarnation int
timeout *time.Timer
gossipPort string
mu sync.Mutex
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We should probably use RWMutex instead of mutex.

Copy link
Copy Markdown
Owner

@ryandielhenn ryandielhenn Mar 22, 2026

Choose a reason for hiding this comment

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

I looked into this and found out that RWMutex is pretty complex internally and might actually slow things down. Probably not worth switching.

payload := node.removeGossip()
message := gossip.NewMessage(
gossip.PingReq,
id,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

shouldn't the subject be targetPeer here?

pkg/peer/peer.go Outdated
Dead PeerStatus = "dead"
)

func (leftPeer Peer) IsGreater(rightPeer Peer) bool {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we rename this to Supersedes?

pkg/peer/peer.go Outdated
return false
}

func (leftStatus PeerStatus) IsGreater(rightStatus PeerStatus) bool {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think this is ever used outside of peer can we rename it to supersedes (private).


func (n *Node) handleDeadStatus(id string, updatedPeer peer.Peer) {
// drop payloads about yourself
if id == n.id {
Copy link
Copy Markdown
Owner

@ryandielhenn ryandielhenn Mar 23, 2026

Choose a reason for hiding this comment

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

Reminder for us: This is a potential bug that's being covered up, we should look into other parts of the codebase.

pkg/node/node.go Outdated
for newId, newPeer := range newMsg.Peers {
if newId == oldId {
if newPeer.IsGreater(oldPeer) {
updatedPeers[oldId] = newPeer
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think we can use the id for newMsg to access the peer in oldMsg. Also I think it's better to update the oldPeer in place instead of creating a new queue.

func (n *Node) addGossip(newMsg *gossip.MessagePayload) {
	// nil gaurd
	for _, oldMsg := range n.gossipQueue {
		// nil gaurd

		// replace stale updates about peers in old message
		for id, newPeer := range newMsg.Peers {
			if oldPeer, ok := oldMsg.Peers[id]; ok {
				if newPeer.IsGreater(oldPeer) {
					oldMsg.Peers[id] = newPeer
				}
				delete(newMsg.Peers, id)
			}
		}
	}
   // logic for dropping gossip if capacity hit untouched
}

},
}
payload := gossip.NewPayload(peers, true)
n.addGossip(payload)
Copy link
Copy Markdown
Owner

@ryandielhenn ryandielhenn Mar 25, 2026

Choose a reason for hiding this comment

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

Maybe we just send the refutation immediately? I think refuting immediately resolves the uncertainty about the comment on line 186 of this file.

@ryandielhenn
Copy link
Copy Markdown
Owner

This LGTM thanks @hrotovb001. We can probably fix anything else we missed in a separate PR so we don't keep working on the same diff.

@ryandielhenn ryandielhenn merged commit a56aba7 into ryandielhenn:main Mar 26, 2026
1 check passed
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.

Add SUSPECTED status to peers with timeout and refutation

2 participants