Skip to content

Commit

Permalink
Filter self-node when requesting channel state
Browse files Browse the repository at this point in the history
  • Loading branch information
gotoxu committed Apr 28, 2019
1 parent 613c94c commit 51f6747
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions channel/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func (gc *gossipChannel) Initialize(chainID string, members []common.PKIidType,
}

func (gc *gossipChannel) AddMember(member common.PKIidType) (*protos.ChainState, error) {
// can't add self to the members
if bytes.Equal(member, gc.pkiID) {
return nil, errors.New("Can't add leader to the channel members")
}

gc.Lock()
defer gc.Unlock()

Expand All @@ -182,11 +187,7 @@ func (gc *gossipChannel) AddMember(member common.PKIidType) (*protos.ChainState,
return nil, err
}

if bytes.Equal(member, gc.pkiID) {
return nil, errors.New("Can't add leader to the channel members")
}

for _, m := range stateInfo.Properties.Members {
for _, m := range gc.members {
if bytes.Equal(member, common.PKIidType(m)) {
return gc.chainStateMsg, nil
}
Expand Down Expand Up @@ -635,7 +636,10 @@ func (gc *gossipChannel) requestStateInfo() {
return
}

endpoints := filter.SelectPeers(gc.GetChannelConfig().PullPeerNum, gc.GetMembership(), gc.IsMemberInChan)
filters := filter.CombineRoutingFilters(gc.IsMemberInChan, func(member common.NetworkMember) bool {
return gc.pkiID.IsNotSameFilter(member.PKIID)
})
endpoints := filter.SelectPeers(gc.GetChannelConfig().PullPeerNum, gc.GetMembership(), filters)
gc.Send(req, endpoints...)
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"google.golang.org/grpc"
)

func TestAddLeaderToChainMembers(t *testing.T) {
func TestAddSelfToChainMembers(t *testing.T) {
gossipSvc1, err := CreateGossipServer([]string{"localhost:12053"}, "localhost:12053", 0)
require.NoError(t, err)
defer gossipSvc1.Stop()
Expand Down

0 comments on commit 51f6747

Please sign in to comment.