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 <[email protected]>
1 parent 9a3aa1d commit 41bbdc2

22 files changed

+71
-491
lines changed

common/configvalues/channel/application/organization_test.go

+2-2
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

-9
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

+4-3
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

-5
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

-2
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

+1-5
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

+9-11
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

+5-6
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

+4-6
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

+5-5
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
}

gossip/state/state_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ var (
4848
)
4949

5050
var orgID = []byte("ORG1")
51-
var anchorPeerIdentity = api.PeerIdentityType("identityInOrg1")
5251

5352
type joinChanMsg struct {
5453
}
@@ -61,7 +60,7 @@ func (*joinChanMsg) SequenceNumber() uint64 {
6160

6261
// AnchorPeers returns all the anchor peers that are in the channel
6362
func (*joinChanMsg) AnchorPeers() []api.AnchorPeer {
64-
return []api.AnchorPeer{{Cert: anchorPeerIdentity}}
63+
return []api.AnchorPeer{{OrgID: orgID}}
6564
}
6665

6766
type orgCryptoService struct {

peer/channel/channel.go

+6-42
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ var (
3939
genesisBlockPath string
4040

4141
// create related variables
42-
chainID string
43-
anchorPeerList string
44-
channelTxFile string
42+
chainID string
43+
channelTxFile string
4544
)
4645

4746
// Cmd returns the cobra command for Node
@@ -66,7 +65,6 @@ func AddFlags(cmd *cobra.Command) {
6665

6766
flags.StringVarP(&genesisBlockPath, "blockpath", "b", common.UndefinedParamValue, "Path to file containing genesis block")
6867
flags.StringVarP(&chainID, "chain", "c", common.UndefinedParamValue, "In case of a newChain command, the chain ID to create.")
69-
flags.StringVarP(&anchorPeerList, "anchors", "a", "", anchorPeerUsage)
7068
flags.StringVarP(&channelTxFile, "file", "f", "", "Configuration transaction file generated by a tool such as configtxgen for submitting to orderer")
7169
}
7270

@@ -78,11 +76,10 @@ var channelCmd = &cobra.Command{
7876

7977
// ChannelCmdFactory holds the clients used by ChannelCmdFactory
8078
type ChannelCmdFactory struct {
81-
EndorserClient pb.EndorserClient
82-
Signer msp.SigningIdentity
83-
BroadcastClient common.BroadcastClient
84-
DeliverClient deliverClientIntf
85-
AnchorPeerParser *common.AnchorPeerParser
79+
EndorserClient pb.EndorserClient
80+
Signer msp.SigningIdentity
81+
BroadcastClient common.BroadcastClient
82+
DeliverClient deliverClientIntf
8683
}
8784

8885
// InitCmdFactory init the ChannelCmdFactor with default clients
@@ -121,40 +118,7 @@ func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) {
121118
}
122119

123120
cmdFact.DeliverClient = newDeliverClient(client, chainID)
124-
cmdFact.AnchorPeerParser = common.GetAnchorPeersParser(anchorPeerList)
125121
}
126122

127123
return cmdFact, nil
128124
}
129-
130-
const anchorPeerUsage = `In case of a newChain command, the list of anchor peer files, separated by commas.
131-
The files should be in the following format:
132-
anchorPeerHost
133-
anchorPeerPort
134-
PEM encoded certificate.
135-
136-
In example:
137-
1.2.3.4
138-
7051
139-
-----BEGIN CERTIFICATE-----
140-
MIIDXTCCAkWgAwIBAgIJALRf63iSHa0BMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
141-
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
142-
aWRnaXRzIFB0eSBMdGQwHhcNMTcwMTI2MjMyMzM1WhcNMTgwMTI2MjMyMzM1WjBF
143-
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
144-
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
145-
CgKCAQEAzbph0SEHYb/tvNYATWfpl7oAFpw3Tcn2s0icJaScqs2RodjosIOBK6AB
146-
N6fkgGDHwYhYbMNfJzUYSYgXD4MPjDxzPw+/Hz02bjuxFB8pQnmln6b6pVHz79vL
147-
i3UQ8eaCe3zswpX0JJTlOs5wdJGOySNRNatbVKl9HDNWcNl6Ec5MrlK3/v6OGF03
148-
0ak7QYDNjyHaz3rMaOzJumRJeOxtjUO/+TbjN+bkcXSgQH9LjoeaZdkV/QWrCA1I
149-
qGowBOxYcyiX56bKKFvCZ76ZYA55d3HyI/H7S258CTdE6WUTDXNqmXnX5WbBuUiK
150-
dypI+KmGlzrRETahrJSJKdlxxtpPVwIDAQABo1AwTjAdBgNVHQ4EFgQUnK6ITmnz
151-
hfNKFr+57Bcayzio47EwHwYDVR0jBBgwFoAUnK6ITmnzhfNKFr+57Bcayzio47Ew
152-
DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAvYFu4xQDE11C8wdK/5LE
153-
G61E9yjsDjFlhzgsG8+TqWI6LjHzm3hSNj7VMI7f0ckydxxOSQqKEkkQaL5GNS3B
154-
JOwsGtPjgQ2Sxx2KrEyaNozxznm1qZflQCis95NVvjHeiybbLfjQRVKde0+7kSKc
155-
cqBBE+IwxNofNyevlRyCBNsH6v2DLJoiFwvE5PqY6XvAcC17va/TKS16TVCqpxX0
156-
OrngleEKom1hiU1MzGZ29/nGpwP/oD8Lf+BqxipLf3BdiDR2+n5dbrV/ul1VczwQ
157-
F2ht++pZbdiqmv7CRAfvkSzrkwIeL+XfVR6ncFf4Nf92u6DJDnTzc/0K3pLaE+bo
158-
JQ==
159-
-----END CERTIFICATE-----
160-
`

peer/channel/create.go

+1-25
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ import (
2222
"time"
2323

2424
"github.com/golang/protobuf/proto"
25-
"github.com/hyperledger/fabric/common/cauthdsl"
2625
"github.com/hyperledger/fabric/common/configtx"
2726
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
2827
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
29-
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
30-
"github.com/hyperledger/fabric/common/configvalues/msp"
3128
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3229
"github.com/hyperledger/fabric/peer/common"
3330
cb "github.com/hyperledger/fabric/protos/common"
@@ -63,32 +60,11 @@ func createCmd(cf *ChannelCmdFactory) *cobra.Command {
6360
}
6461

6562
func createChannelFromDefaults(cf *ChannelCmdFactory) (*cb.Envelope, error) {
66-
if cf.AnchorPeerParser == nil {
67-
cf.AnchorPeerParser = common.GetDefaultAnchorPeerParser()
68-
}
69-
70-
anchorPeers, err := cf.AnchorPeerParser.Parse()
71-
if err != nil {
72-
return nil, err
73-
}
74-
7563
oTemplate := configtxtest.OrdererTemplate()
7664
oOrgTemplate := configtxtest.OrdererOrgTemplate()
7765
appOrgTemplate := configtxtest.ApplicationOrgTemplate()
78-
gosscg := configtxapplication.TemplateAnchorPeers("XXXFakeOrg", anchorPeers)
79-
80-
// FIXME: remove this hack as soon as 'peer channel create' is fixed properly
81-
// we add admin policies for this config group, otherwise a majority won't be reached
82-
p := &cb.ConfigPolicy{
83-
Policy: &cb.Policy{
84-
Type: int32(cb.Policy_SIGNATURE),
85-
Policy: cauthdsl.MarshaledAcceptAllPolicy,
86-
},
87-
}
88-
gosscg.Groups[configtxapplication.GroupKey].Groups["XXXFakeOrg"].Policies[msp.AdminsPolicyKey] = p
8966

90-
gossTemplate := configtx.NewSimpleTemplate(gosscg)
91-
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, oOrgTemplate, appOrgTemplate, gossTemplate)
67+
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, oOrgTemplate, appOrgTemplate)
9268

9369
signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()
9470
if err != nil {

0 commit comments

Comments
 (0)