From 9e281dc7a828c47e007130630cde926a7f20fca7 Mon Sep 17 00:00:00 2001 From: Yacov Manevich Date: Mon, 18 Jan 2021 20:54:04 +0200 Subject: [PATCH] Remove unreachable and unnecessary code in gossip membership In gossip, alive messages are stored in membership stores, and they also have logical timestamps. When a peer learns of an alive message with a higher logical timestamp of its latest alive message (for a specific peer), it enters learnExistingMembers() and tentatively updates the latest envelope and gossip message of what is store in the membership store. However, for completeness, the code checks if the membership store already contains an earlier instance, and if not, populates the membership store with a new instance. This population is not needed, because the code only enters the function if it already knows the peer, hence the membership store contains an earlier instance. This commit simply removes the unneeded code path where the instance is unknown despite the fact that we know about the peer already. Change-Id: I86bc65d881a440c267275a697853a1ead087df18 Signed-off-by: Yacov Manevich --- gossip/discovery/discovery_impl.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gossip/discovery/discovery_impl.go b/gossip/discovery/discovery_impl.go index 163d4cec5a6..8a520b97b1d 100644 --- a/gossip/discovery/discovery_impl.go +++ b/gossip/discovery/discovery_impl.go @@ -868,11 +868,7 @@ func (d *gossipDiscoveryImpl) learnExistingMembers(aliveArr []*proto.SignedGossi alive.lastSeen = time.Now() alive.seqNum = am.Timestamp.SeqNum - if am := d.aliveMembership.MsgByID(m.GetAliveMsg().Membership.PkiId); am == nil { - d.logger.Debug("Adding", am, "to aliveMembership") - msg := &proto.SignedGossipMessage{GossipMessage: m.GossipMessage, Envelope: am.Envelope} - d.aliveMembership.Put(m.GetAliveMsg().Membership.PkiId, msg) - } else { + if am := d.aliveMembership.MsgByID(m.GetAliveMsg().Membership.PkiId); am != nil { d.logger.Debug("Replacing", am, "in aliveMembership") am.GossipMessage = m.GossipMessage am.Envelope = m.Envelope