Skip to content

Commit

Permalink
[FAB-3241] Gossip: Do not send redundant StateInfo
Browse files Browse the repository at this point in the history
In gossip, whenever the channel related metadata is updated,
a "dirty flag" is turned on, and periodically a goroutine disseminates
to peers if the dirty flag is turned on.
There is a bug that this dirty flag is never turned off.
This causes a redundant dissemination of StateInfo.

The stateInfo is periodically pulled from peers via a pull mechanism anyway
so there is no point in having periodical dissemination and thus the dirty
flag should be turned off after dissemination.

Change-Id: Ie508df33c28e007e952195faed7837db5641e41a
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Apr 19, 2017
1 parent 5eb5d07 commit 281b7d7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ func (gc *gossipChannel) publishStateInfo() {
stateInfoMsg := gc.stateInfoMsg
gc.RUnlock()
gc.Gossip(stateInfoMsg)
if len(gc.GetMembership()) > 0 {
atomic.StoreInt32(&gc.shouldGossipStateInfo, int32(0))
}
}

func (gc *gossipChannel) createBlockPuller() pull.Mediator {
Expand Down
61 changes: 61 additions & 0 deletions gossip/gossip/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,67 @@ func TestChannelGetPeers(t *testing.T) {
assert.Len(t, gc.GetPeers(), 0)
}

func TestOnDemandGossip(t *testing.T) {
t.Parallel()

// Scenario: update the metadata and ensure only 1 dissemination
// takes place when membership is not empty

cs := &cryptoService{}
adapter := new(gossipAdapterMock)
configureAdapter(adapter)

gossipedEvents := make(chan struct{})

conf := conf
conf.PublishStateInfoInterval = time.Millisecond * 200
adapter.On("GetConf").Return(conf)
adapter.On("GetMembership").Return([]discovery.NetworkMember{})
adapter.On("Gossip", mock.Anything).Run(func(mock.Arguments) {
gossipedEvents <- struct{}{}
})
gc := NewGossipChannel(pkiIDInOrg1, cs, channelA, adapter, api.JoinChannelMessage(&joinChanMsg{}))
defer gc.Stop()
select {
case <-gossipedEvents:
assert.Fail(t, "Should not have gossiped because metadata has not been updated yet")
case <-time.After(time.Millisecond * 500):
}
gc.UpdateStateInfo(createStateInfoMsg(0, pkiIDInOrg1, channelA))
select {
case <-gossipedEvents:
case <-time.After(time.Second):
assert.Fail(t, "Didn't gossip within a timely manner")
}
select {
case <-gossipedEvents:
case <-time.After(time.Second):
assert.Fail(t, "Should have gossiped a second time, because membership is empty")
}
adapter = new(gossipAdapterMock)
configureAdapter(adapter, []discovery.NetworkMember{{}}...)
adapter.On("Gossip", mock.Anything).Run(func(mock.Arguments) {
gossipedEvents <- struct{}{}
})
gc.(*gossipChannel).Adapter = adapter
select {
case <-gossipedEvents:
case <-time.After(time.Second):
assert.Fail(t, "Should have gossiped a third time")
}
select {
case <-gossipedEvents:
assert.Fail(t, "Should not have gossiped a fourth time, because dirty flag should have been turned off")
case <-time.After(time.Millisecond * 500):
}
gc.UpdateStateInfo(createStateInfoMsg(1, pkiIDInOrg1, channelA))
select {
case <-gossipedEvents:
case <-time.After(time.Second):
assert.Fail(t, "Should have gossiped a block now, because got a new StateInfo message")
}
}

func createDataUpdateMsg(nonce uint64) *proto.SignedGossipMessage {
return (&proto.GossipMessage{
Nonce: 0,
Expand Down

0 comments on commit 281b7d7

Please sign in to comment.