Skip to content

Commit da355f3

Browse files
committed
[FAB-2640] Gossip: Support empty set of anchor peers
Gossip currently doesn't support an empty set of anchor peers in the genesis block. In such a case, it should be assumed that the organization of the peer is the only member in the channel. Change-Id: I37e3149076addc6e1e05746488360f700addfee9 Signed-off-by: Yacov Manevich <[email protected]>
1 parent dc7d4d4 commit da355f3

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

gossip/gossip/channel/channel.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Config struct {
4444
PullPeerNum int
4545
PullInterval time.Duration
4646
RequestStateInfoInterval time.Duration
47+
Identity api.PeerIdentityType
4748
}
4849

4950
// GossipChannel defines an object that deals with all channel-related messages
@@ -335,15 +336,22 @@ func (gc *gossipChannel) ConfigureChannel(joinMsg api.JoinChannelMessage) {
335336
gc.logger.Warning("Already have a more updated JoinChannel message(", gc.joinMsg.SequenceNumber(), ") than", gc.joinMsg.SequenceNumber())
336337
return
337338
}
338-
orgs := []api.OrgIdentityType{}
339+
340+
var orgs []api.OrgIdentityType
339341
existingOrgInJoinChanMsg := make(map[string]struct{})
342+
// We are in the channel if the joinMsg contains an empty set of anchor peers
343+
selfOrg := gc.OrgByPeerIdentity(gc.GetConf().Identity)
344+
if len(joinMsg.AnchorPeers()) == 0 {
345+
orgs = []api.OrgIdentityType{selfOrg}
346+
}
340347
for _, anchorPeer := range joinMsg.AnchorPeers() {
341348
orgID := anchorPeer.OrgID
342349
if _, exists := existingOrgInJoinChanMsg[string(orgID)]; !exists {
343350
orgs = append(orgs, orgID)
344351
existingOrgInJoinChanMsg[string(orgID)] = struct{}{}
345352
}
346353
}
354+
347355
gc.orgs = orgs
348356
gc.joinMsg = joinMsg
349357
}

gossip/gossip/channel/channel_test.go

+34-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var conf = Config{
4444
PullPeerNum: 3,
4545
PullInterval: time.Second,
4646
RequestStateInfoInterval: time.Millisecond * 100,
47+
Identity: api.PeerIdentityType("pkiIDInOrg1"),
4748
}
4849

4950
func init() {
@@ -197,8 +198,7 @@ func (ga *gossipAdapterMock) ValidateStateInfoMessage(msg *proto.SignedGossipMes
197198
}
198199

199200
func (ga *gossipAdapterMock) OrgByPeerIdentity(identity api.PeerIdentityType) api.OrgIdentityType {
200-
args := ga.Called(identity)
201-
return args.Get(0).(api.OrgIdentityType)
201+
return ga.GetOrgOfPeer(common.PKIidType(identity))
202202
}
203203

204204
func (ga *gossipAdapterMock) GetOrgOfPeer(PKIIID common.PKIidType) api.OrgIdentityType {
@@ -217,6 +217,9 @@ func configureAdapter(adapter *gossipAdapterMock, members ...discovery.NetworkMe
217217
adapter.On("GetOrgOfPeer", pkiIDInOrg1ButNotEligible).Return(orgInChannelA)
218218
adapter.On("GetOrgOfPeer", pkiIDinOrg2).Return(orgNotInChannelA)
219219
adapter.On("GetOrgOfPeer", mock.Anything).Return(api.OrgIdentityType(nil))
220+
adapter.On("OrgByPeerIdentity", mock.Anything).Run(func(args mock.Arguments) {
221+
fmt.Println(args.Get(0))
222+
})
220223
}
221224

222225
func TestChannelPeriodicalPublishStateInfo(t *testing.T) {
@@ -815,6 +818,35 @@ func TestChannelReconfigureChannel(t *testing.T) {
815818
}
816819
}
817820

821+
func TestChannelNoAnchorPeers(t *testing.T) {
822+
t.Parallel()
823+
824+
// Scenario: We got a join channel message with no anchor peers
825+
// In this case, we should be in the channel
826+
827+
cs := &cryptoService{}
828+
adapter := new(gossipAdapterMock)
829+
configureAdapter(adapter, discovery.NetworkMember{PKIid: pkiIDInOrg1})
830+
831+
adapter.On("GetConf").Return(conf)
832+
adapter.On("GetMembership").Return([]discovery.NetworkMember{})
833+
adapter.On("OrgByPeerIdentity", api.PeerIdentityType(orgInChannelA)).Return(orgInChannelA)
834+
adapter.On("GetOrgOfPeer", pkiIDInOrg1).Return(orgInChannelA)
835+
adapter.On("GetOrgOfPeer", pkiIDinOrg2).Return(orgNotInChannelA)
836+
837+
jcm := &joinChanMsg{
838+
anchorPeers: func() []api.AnchorPeer {
839+
return []api.AnchorPeer{}
840+
},
841+
getTS: func() time.Time {
842+
return time.Now().Add(time.Millisecond * 100)
843+
},
844+
}
845+
846+
gc := NewGossipChannel(cs, channelA, adapter, api.JoinChannelMessage(jcm))
847+
assert.True(t, gc.IsOrgInChannel(orgInChannelA))
848+
}
849+
818850
func TestChannelGetPeers(t *testing.T) {
819851
t.Parallel()
820852

gossip/gossip/chanstate.go

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func (ga *gossipAdapterImpl) GetConf() channel.Config {
8686
PullInterval: ga.conf.PullInterval,
8787
PullPeerNum: ga.conf.PullPeerNum,
8888
RequestStateInfoInterval: ga.conf.RequestStateInfoInterval,
89+
Identity: ga.selfIdentity,
8990
}
9091
}
9192

0 commit comments

Comments
 (0)