Commit 6c3cb99d authored by yacovm's avatar yacovm Committed by Yacov Manevich
Browse files

[FAB-5157] Optimize peer selection of channel batches

In gossip whenever a batch of channel-scoped messages
(either leadership, blocks, stateInfo, etc.) is sent to remote peers,
a function goes over all existing alive peers and then selects from
them a subset of peers. This is done in gossipInChan function

In case of leadership messages, the subset is taken from the entire
membership set without an upper bound (we gossip leadership messages
to all peers in the channel), and in case of non-leadership messages
the subset is taken with an upper bound equal to the propogation
fanout (configurable).

Finding peers that are eligible to receive any channel-related data
involves cryptographical computations and is non-negligible
(measured ~ 25ms in a network of 8 peers)

The 2 possibilities (leadership and non-leadership) are calculated even
though each method invocation of gossipInChan receives only 1 type of message.
Therefore, it would be beneficial performance wise to just calculate the
option that is relevant to that method invocation and not calculate
both options each time.

This commit addresses this by calculating the peers to send according to
the type of message in the invocation.

Change-Id: If6940182f83ef046c1d1f7186a71946128591e69
Signed-off-by: default avataryacovm <>
parent b8e189eb
......@@ -595,6 +595,9 @@ func (g *gossipServiceImpl) gossipInChan(messages []*proto.SignedGossipMessage,
return bytes.Equal(o.(*proto.SignedGossipMessage).Channel, channel)
messagesOfChannel, messages = partitionMessages(grabMsgs, messages)
if len(messagesOfChannel) == 0 {
// Grab channel object for that channel
gc := g.chanState.getGossipChannelByChainID(channel)
if gc == nil {
......@@ -604,15 +607,16 @@ func (g *gossipServiceImpl) gossipInChan(messages []*proto.SignedGossipMessage,
// Select the peers to send the messages to
// For leadership messages we will select all peers that pass routing factory - e.g. all peers in channel and org
membership := g.disc.GetMembership()
allPeersInCh := filter.SelectPeers(len(membership), membership, chanRoutingFactory(gc))
peers2Send := filter.SelectPeers(g.conf.PropagatePeerNum, membership, chanRoutingFactory(gc))
var peers2Send []*comm.RemotePeer
if messagesOfChannel[0].IsLeadershipMsg() {
peers2Send = filter.SelectPeers(len(membership), membership, chanRoutingFactory(gc))
} else {
peers2Send = filter.SelectPeers(g.conf.PropagatePeerNum, membership, chanRoutingFactory(gc))
// Send the messages to the remote peers
for _, msg := range messagesOfChannel {
if msg.IsLeadershipMsg() {
g.comm.Send(msg, allPeersInCh...)
} else {
g.comm.Send(msg, peers2Send...)
g.comm.Send(msg, peers2Send...)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment