Skip to content

Commit 41bbdc2

Browse files
committed
Remove anchor peers from CLI
This change set removes the anchor peers from the CLI. and makes gossip take the organization IDs from the configuration groups of the genesis block. After this change set, the only way to get anchor peers to the peer is using the configtx tool Change-Id: I220a8a6e315fe77bc2d29c63e3d9cb2be9937247 Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
1 parent 9a3aa1d commit 41bbdc2

22 files changed

+71
-491
lines changed

common/configvalues/channel/application/organization_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func TestApplicationOrgRollback(t *testing.T) {
7070

7171
func TestApplicationOrgAnchorPeers(t *testing.T) {
7272
endVal := []*pb.AnchorPeer{
73-
&pb.AnchorPeer{Host: "foo", Port: 234, Cert: []byte("foocert")},
74-
&pb.AnchorPeer{Host: "bar", Port: 237, Cert: []byte("barcert")},
73+
&pb.AnchorPeer{Host: "foo", Port: 234},
74+
&pb.AnchorPeer{Host: "bar", Port: 237},
7575
}
7676
invalidMessage := makeInvalidConfigValue()
7777
validMessage := TemplateAnchorPeers("id", endVal)

docs/channel-setup.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,7 @@ CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:5005 peer channel create -c myc1
4242
```
4343

4444
This will create a channel genesis block file `myc1.block` to issue join commands with.
45-
If you want to specify anchor peers, you can create anchor peer files in the following format:
46-
peer-hostname
47-
port
48-
PEM file of peer certificate
4945

50-
See CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:5005 peer channel create -h for an anchor-peer file example
51-
And pass the anchor peer files as a comma-separated argument with flag -a: in example:
52-
```
53-
CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:5005 peer channel create -c myc1 -a anchorPeer1.txt,anchorPeer2.txt
54-
```
5546

5647
### Join a channel
5748
Execute the join command to peer0 in the CLI container.

gossip/api/channel.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ type JoinChannelMessage interface {
5252

5353
// AnchorPeer is an anchor peer's certificate and endpoint (host:port)
5454
type AnchorPeer struct {
55-
Cert PeerIdentityType // Cert defines the certificate of the remote peer
56-
Host string // Host is the hostname/ip address of the remote peer
57-
Port int // Port is the port the remote peer is listening on
55+
Host string // Host is the hostname/ip address of the remote peer
56+
Port int // Port is the port the remote peer is listening on
57+
OrgID OrgIdentityType // OrgID is the identity of the organization the anchor peer came from
58+
5859
}
5960

6061
// OrgIdentityType defines the identity of an organization

gossip/discovery/discovery_impl.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ func (d *gossipDiscoveryImpl) Connect(member NetworkMember) {
131131
d.logger.Debug("Entering", member)
132132
defer d.logger.Debug("Exiting")
133133

134-
if member.PKIid == nil {
135-
d.logger.Warning("Empty PkiID, aborting")
136-
return
137-
}
138-
139134
d.lock.Lock()
140135
defer d.lock.Unlock()
141136

gossip/discovery/discovery_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ func TestConnect(t *testing.T) {
274274
endpoint := fmt.Sprintf("localhost:%d", 7611+j)
275275
netMember2Connect2 := NetworkMember{Endpoint: endpoint, PKIid: []byte(endpoint)}
276276
inst.Connect(netMember2Connect2)
277-
// Check passing nil PKI-ID doesn't crash peer
278-
inst.Connect(NetworkMember{PKIid: nil, Endpoint: endpoint})
279277
}
280278

281279
fullMembership := func() bool {

gossip/gossip/channel/channel.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,7 @@ func (gc *gossipChannel) ConfigureChannel(joinMsg api.JoinChannelMessage) {
339339
orgs := []api.OrgIdentityType{}
340340
existingOrgInJoinChanMsg := make(map[string]struct{})
341341
for _, anchorPeer := range joinMsg.AnchorPeers() {
342-
orgID := gc.OrgByPeerIdentity(anchorPeer.Cert)
343-
if orgID == nil {
344-
gc.logger.Warning("Cannot extract org identity from certificate, aborting.")
345-
return
346-
}
342+
orgID := anchorPeer.OrgID
347343
if _, exists := existingOrgInJoinChanMsg[string(orgID)]; !exists {
348344
orgs = append(orgs, orgID)
349345
existingOrgInJoinChanMsg[string(orgID)] = struct{}{}

gossip/gossip/channel/channel_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ func init() {
5555
var (
5656
// Organizations: {ORG1, ORG2}
5757
// Channel A: {ORG1}
58-
channelA = common.ChainID("A")
59-
orgInChannelA = api.OrgIdentityType("ORG1")
60-
orgNotInChannelA = api.OrgIdentityType("ORG2")
61-
anchorPeerIdentity = api.PeerIdentityType("identityInOrg1")
62-
pkiIDInOrg1 = common.PKIidType("pkiIDInOrg1")
63-
pkiIDinOrg2 = common.PKIidType("pkiIDinOrg2")
58+
channelA = common.ChainID("A")
59+
orgInChannelA = api.OrgIdentityType("ORG1")
60+
orgNotInChannelA = api.OrgIdentityType("ORG2")
61+
pkiIDInOrg1 = common.PKIidType("pkiIDInOrg1")
62+
pkiIDinOrg2 = common.PKIidType("pkiIDinOrg2")
6463
)
6564

6665
type joinChanMsg struct {
@@ -83,7 +82,7 @@ func (jcm *joinChanMsg) AnchorPeers() []api.AnchorPeer {
8382
if jcm.anchorPeers != nil {
8483
return jcm.anchorPeers()
8584
}
86-
return []api.AnchorPeer{{Cert: anchorPeerIdentity}}
85+
return []api.AnchorPeer{{OrgID: orgInChannelA}}
8786
}
8887

8988
type cryptoService struct {
@@ -200,7 +199,6 @@ func (ga *gossipAdapterMock) GetOrgOfPeer(PKIIID common.PKIidType) api.OrgIdenti
200199
func configureAdapter(adapter *gossipAdapterMock, members ...discovery.NetworkMember) {
201200
adapter.On("GetConf").Return(conf)
202201
adapter.On("GetMembership").Return(members)
203-
adapter.On("OrgByPeerIdentity", anchorPeerIdentity).Return(orgInChannelA)
204202
adapter.On("GetOrgOfPeer", pkiIDInOrg1).Return(orgInChannelA)
205203
adapter.On("GetOrgOfPeer", pkiIDinOrg2).Return(orgNotInChannelA)
206204
adapter.On("GetOrgOfPeer", mock.Anything).Return(api.OrgIdentityType(nil))
@@ -704,7 +702,7 @@ func TestChannelReconfigureChannel(t *testing.T) {
704702

705703
outdatedJoinChanMsg := &joinChanMsg{
706704
anchorPeers: func() []api.AnchorPeer {
707-
return []api.AnchorPeer{{Cert: api.PeerIdentityType(orgNotInChannelA)}}
705+
return []api.AnchorPeer{{OrgID: orgNotInChannelA}}
708706
},
709707
getTS: func() time.Time {
710708
return time.Now()
@@ -713,7 +711,7 @@ func TestChannelReconfigureChannel(t *testing.T) {
713711

714712
newJoinChanMsg := &joinChanMsg{
715713
anchorPeers: func() []api.AnchorPeer {
716-
return []api.AnchorPeer{{Cert: api.PeerIdentityType(orgInChannelA)}}
714+
return []api.AnchorPeer{{OrgID: orgInChannelA}}
717715
},
718716
getTS: func() time.Time {
719717
return time.Now().Add(time.Millisecond * 100)
@@ -722,7 +720,7 @@ func TestChannelReconfigureChannel(t *testing.T) {
722720

723721
updatedJoinChanMsg := &joinChanMsg{
724722
anchorPeers: func() []api.AnchorPeer {
725-
return []api.AnchorPeer{{Cert: api.PeerIdentityType(orgNotInChannelA)}}
723+
return []api.AnchorPeer{{OrgID: orgNotInChannelA}}
726724
},
727725
getTS: func() time.Time {
728726
return time.Now().Add(time.Millisecond * 200)

gossip/gossip/gossip_impl.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ func (g *gossipServiceImpl) JoinChan(joinMsg api.JoinChannelMessage, chainID com
184184
// joinMsg is supposed to have been already verified
185185
g.chanState.joinChannel(joinMsg, chainID)
186186

187-
selfPkiID := g.mcs.GetPKIidOfCert(g.selfIdentity)
188187
for _, ap := range joinMsg.AnchorPeers() {
189188
if ap.Host == "" {
190189
g.logger.Warning("Got empty hostname, skipping connecting to anchor peer", ap)
@@ -194,15 +193,15 @@ func (g *gossipServiceImpl) JoinChan(joinMsg api.JoinChannelMessage, chainID com
194193
g.logger.Warning("Got invalid port (0), skipping connecting to anchor peer", ap)
195194
continue
196195
}
197-
pkiID := g.mcs.GetPKIidOfCert(ap.Cert)
196+
endpoint := fmt.Sprintf("%s:%d", ap.Host, ap.Port)
198197
// Skip connecting to self
199-
if bytes.Equal([]byte(pkiID), []byte(selfPkiID)) {
200-
g.logger.Info("Anchor peer with same PKI-ID, skipping connecting to myself")
198+
if g.selfNetworkMember().Endpoint == endpoint || g.selfNetworkMember().InternalEndpoint.Endpoint == endpoint {
199+
g.logger.Info("Anchor peer with same endpoint, skipping connecting to myself")
201200
continue
202201
}
203-
endpoint := fmt.Sprintf("%s:%d", ap.Host, ap.Port)
202+
204203
g.disc.Connect(discovery.NetworkMember{
205-
InternalEndpoint: &proto.SignedEndpoint{Endpoint: endpoint}, PKIid: pkiID})
204+
InternalEndpoint: &proto.SignedEndpoint{Endpoint: endpoint}})
206205
}
207206
}
208207

gossip/gossip/gossip_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func init() {
5353
}
5454

5555
var orgInChannelA = api.OrgIdentityType("ORG1")
56-
var anchorPeerIdentity = api.PeerIdentityType("identityInOrg1")
5756

5857
func acceptData(m interface{}) bool {
5958
if dataMsg := m.(*proto.GossipMessage).GetDataMsg(); dataMsg != nil {
@@ -82,7 +81,7 @@ func (*joinChanMsg) SequenceNumber() uint64 {
8281
// AnchorPeers returns all the anchor peers that are in the channel
8382
func (jcm *joinChanMsg) AnchorPeers() []api.AnchorPeer {
8483
if len(jcm.anchorPeers) == 0 {
85-
return []api.AnchorPeer{{Cert: anchorPeerIdentity}}
84+
return []api.AnchorPeer{{OrgID: orgInChannelA}}
8685
}
8786
return jcm.anchorPeers
8887
}
@@ -317,11 +316,10 @@ func TestConnectToAnchorPeers(t *testing.T) {
317316

318317
jcm := &joinChanMsg{anchorPeers: []api.AnchorPeer{}}
319318
for i := 0; i < n; i++ {
320-
pkiID := fmt.Sprintf("localhost:%d", portPrefix+i)
321319
ap := api.AnchorPeer{
322-
Port: portPrefix + i,
323-
Host: "localhost",
324-
Cert: []byte(pkiID),
320+
Port: portPrefix + i,
321+
Host: "localhost",
322+
OrgID: orgInChannelA,
325323
}
326324
jcm.anchorPeers = append(jcm.anchorPeers, ap)
327325
}

gossip/service/gossip_service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ func (g *gossipServiceImpl) InitializeChannel(chainID string, committer committe
177177
// configUpdated constructs a joinChannelMessage and sends it to the gossipSvc
178178
func (g *gossipServiceImpl) configUpdated(config Config) {
179179
jcm := &joinChannelMessage{seqNum: config.Sequence(), anchorPeers: []api.AnchorPeer{}}
180-
for _, org := range config.Organizations() {
181-
for _, ap := range org.AnchorPeers() {
180+
for orgID, appOrg := range config.Organizations() {
181+
for _, ap := range appOrg.AnchorPeers() {
182182
anchorPeer := api.AnchorPeer{
183-
Host: ap.Host,
184-
Port: int(ap.Port),
185-
Cert: api.PeerIdentityType(ap.Cert),
183+
Host: ap.Host,
184+
Port: int(ap.Port),
185+
OrgID: api.OrgIdentityType(orgID),
186186
}
187187
jcm.anchorPeers = append(jcm.anchorPeers, anchorPeer)
188188
}

0 commit comments

Comments
 (0)