Skip to content

Commit

Permalink
Remove anchor peers from CLI
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yacovm committed Feb 24, 2017
1 parent 9a3aa1d commit 41bbdc2
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 491 deletions.
4 changes: 2 additions & 2 deletions common/configvalues/channel/application/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func TestApplicationOrgRollback(t *testing.T) {

func TestApplicationOrgAnchorPeers(t *testing.T) {
endVal := []*pb.AnchorPeer{
&pb.AnchorPeer{Host: "foo", Port: 234, Cert: []byte("foocert")},
&pb.AnchorPeer{Host: "bar", Port: 237, Cert: []byte("barcert")},
&pb.AnchorPeer{Host: "foo", Port: 234},
&pb.AnchorPeer{Host: "bar", Port: 237},
}
invalidMessage := makeInvalidConfigValue()
validMessage := TemplateAnchorPeers("id", endVal)
Expand Down
9 changes: 0 additions & 9 deletions docs/channel-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,7 @@ CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:5005 peer channel create -c myc1
```

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

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

### Join a channel
Execute the join command to peer0 in the CLI container.
Expand Down
7 changes: 4 additions & 3 deletions gossip/api/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ type JoinChannelMessage interface {

// AnchorPeer is an anchor peer's certificate and endpoint (host:port)
type AnchorPeer struct {
Cert PeerIdentityType // Cert defines the certificate of the remote peer
Host string // Host is the hostname/ip address of the remote peer
Port int // Port is the port the remote peer is listening on
Host string // Host is the hostname/ip address of the remote peer
Port int // Port is the port the remote peer is listening on
OrgID OrgIdentityType // OrgID is the identity of the organization the anchor peer came from

}

// OrgIdentityType defines the identity of an organization
Expand Down
5 changes: 0 additions & 5 deletions gossip/discovery/discovery_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ func (d *gossipDiscoveryImpl) Connect(member NetworkMember) {
d.logger.Debug("Entering", member)
defer d.logger.Debug("Exiting")

if member.PKIid == nil {
d.logger.Warning("Empty PkiID, aborting")
return
}

d.lock.Lock()
defer d.lock.Unlock()

Expand Down
2 changes: 0 additions & 2 deletions gossip/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ func TestConnect(t *testing.T) {
endpoint := fmt.Sprintf("localhost:%d", 7611+j)
netMember2Connect2 := NetworkMember{Endpoint: endpoint, PKIid: []byte(endpoint)}
inst.Connect(netMember2Connect2)
// Check passing nil PKI-ID doesn't crash peer
inst.Connect(NetworkMember{PKIid: nil, Endpoint: endpoint})
}

fullMembership := func() bool {
Expand Down
6 changes: 1 addition & 5 deletions gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,7 @@ func (gc *gossipChannel) ConfigureChannel(joinMsg api.JoinChannelMessage) {
orgs := []api.OrgIdentityType{}
existingOrgInJoinChanMsg := make(map[string]struct{})
for _, anchorPeer := range joinMsg.AnchorPeers() {
orgID := gc.OrgByPeerIdentity(anchorPeer.Cert)
if orgID == nil {
gc.logger.Warning("Cannot extract org identity from certificate, aborting.")
return
}
orgID := anchorPeer.OrgID
if _, exists := existingOrgInJoinChanMsg[string(orgID)]; !exists {
orgs = append(orgs, orgID)
existingOrgInJoinChanMsg[string(orgID)] = struct{}{}
Expand Down
20 changes: 9 additions & 11 deletions gossip/gossip/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ func init() {
var (
// Organizations: {ORG1, ORG2}
// Channel A: {ORG1}
channelA = common.ChainID("A")
orgInChannelA = api.OrgIdentityType("ORG1")
orgNotInChannelA = api.OrgIdentityType("ORG2")
anchorPeerIdentity = api.PeerIdentityType("identityInOrg1")
pkiIDInOrg1 = common.PKIidType("pkiIDInOrg1")
pkiIDinOrg2 = common.PKIidType("pkiIDinOrg2")
channelA = common.ChainID("A")
orgInChannelA = api.OrgIdentityType("ORG1")
orgNotInChannelA = api.OrgIdentityType("ORG2")
pkiIDInOrg1 = common.PKIidType("pkiIDInOrg1")
pkiIDinOrg2 = common.PKIidType("pkiIDinOrg2")
)

type joinChanMsg struct {
Expand All @@ -83,7 +82,7 @@ func (jcm *joinChanMsg) AnchorPeers() []api.AnchorPeer {
if jcm.anchorPeers != nil {
return jcm.anchorPeers()
}
return []api.AnchorPeer{{Cert: anchorPeerIdentity}}
return []api.AnchorPeer{{OrgID: orgInChannelA}}
}

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

outdatedJoinChanMsg := &joinChanMsg{
anchorPeers: func() []api.AnchorPeer {
return []api.AnchorPeer{{Cert: api.PeerIdentityType(orgNotInChannelA)}}
return []api.AnchorPeer{{OrgID: orgNotInChannelA}}
},
getTS: func() time.Time {
return time.Now()
Expand All @@ -713,7 +711,7 @@ func TestChannelReconfigureChannel(t *testing.T) {

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

updatedJoinChanMsg := &joinChanMsg{
anchorPeers: func() []api.AnchorPeer {
return []api.AnchorPeer{{Cert: api.PeerIdentityType(orgNotInChannelA)}}
return []api.AnchorPeer{{OrgID: orgNotInChannelA}}
},
getTS: func() time.Time {
return time.Now().Add(time.Millisecond * 200)
Expand Down
11 changes: 5 additions & 6 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func (g *gossipServiceImpl) JoinChan(joinMsg api.JoinChannelMessage, chainID com
// joinMsg is supposed to have been already verified
g.chanState.joinChannel(joinMsg, chainID)

selfPkiID := g.mcs.GetPKIidOfCert(g.selfIdentity)
for _, ap := range joinMsg.AnchorPeers() {
if ap.Host == "" {
g.logger.Warning("Got empty hostname, skipping connecting to anchor peer", ap)
Expand All @@ -194,15 +193,15 @@ func (g *gossipServiceImpl) JoinChan(joinMsg api.JoinChannelMessage, chainID com
g.logger.Warning("Got invalid port (0), skipping connecting to anchor peer", ap)
continue
}
pkiID := g.mcs.GetPKIidOfCert(ap.Cert)
endpoint := fmt.Sprintf("%s:%d", ap.Host, ap.Port)
// Skip connecting to self
if bytes.Equal([]byte(pkiID), []byte(selfPkiID)) {
g.logger.Info("Anchor peer with same PKI-ID, skipping connecting to myself")
if g.selfNetworkMember().Endpoint == endpoint || g.selfNetworkMember().InternalEndpoint.Endpoint == endpoint {
g.logger.Info("Anchor peer with same endpoint, skipping connecting to myself")
continue
}
endpoint := fmt.Sprintf("%s:%d", ap.Host, ap.Port)

g.disc.Connect(discovery.NetworkMember{
InternalEndpoint: &proto.SignedEndpoint{Endpoint: endpoint}, PKIid: pkiID})
InternalEndpoint: &proto.SignedEndpoint{Endpoint: endpoint}})
}
}

Expand Down
10 changes: 4 additions & 6 deletions gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func init() {
}

var orgInChannelA = api.OrgIdentityType("ORG1")
var anchorPeerIdentity = api.PeerIdentityType("identityInOrg1")

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

jcm := &joinChanMsg{anchorPeers: []api.AnchorPeer{}}
for i := 0; i < n; i++ {
pkiID := fmt.Sprintf("localhost:%d", portPrefix+i)
ap := api.AnchorPeer{
Port: portPrefix + i,
Host: "localhost",
Cert: []byte(pkiID),
Port: portPrefix + i,
Host: "localhost",
OrgID: orgInChannelA,
}
jcm.anchorPeers = append(jcm.anchorPeers, ap)
}
Expand Down
10 changes: 5 additions & 5 deletions gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ func (g *gossipServiceImpl) InitializeChannel(chainID string, committer committe
// configUpdated constructs a joinChannelMessage and sends it to the gossipSvc
func (g *gossipServiceImpl) configUpdated(config Config) {
jcm := &joinChannelMessage{seqNum: config.Sequence(), anchorPeers: []api.AnchorPeer{}}
for _, org := range config.Organizations() {
for _, ap := range org.AnchorPeers() {
for orgID, appOrg := range config.Organizations() {
for _, ap := range appOrg.AnchorPeers() {
anchorPeer := api.AnchorPeer{
Host: ap.Host,
Port: int(ap.Port),
Cert: api.PeerIdentityType(ap.Cert),
Host: ap.Host,
Port: int(ap.Port),
OrgID: api.OrgIdentityType(orgID),
}
jcm.anchorPeers = append(jcm.anchorPeers, anchorPeer)
}
Expand Down
3 changes: 1 addition & 2 deletions gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var (
)

var orgID = []byte("ORG1")
var anchorPeerIdentity = api.PeerIdentityType("identityInOrg1")

type joinChanMsg struct {
}
Expand All @@ -61,7 +60,7 @@ func (*joinChanMsg) SequenceNumber() uint64 {

// AnchorPeers returns all the anchor peers that are in the channel
func (*joinChanMsg) AnchorPeers() []api.AnchorPeer {
return []api.AnchorPeer{{Cert: anchorPeerIdentity}}
return []api.AnchorPeer{{OrgID: orgID}}
}

type orgCryptoService struct {
Expand Down
48 changes: 6 additions & 42 deletions peer/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ var (
genesisBlockPath string

// create related variables
chainID string
anchorPeerList string
channelTxFile string
chainID string
channelTxFile string
)

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

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

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

// ChannelCmdFactory holds the clients used by ChannelCmdFactory
type ChannelCmdFactory struct {
EndorserClient pb.EndorserClient
Signer msp.SigningIdentity
BroadcastClient common.BroadcastClient
DeliverClient deliverClientIntf
AnchorPeerParser *common.AnchorPeerParser
EndorserClient pb.EndorserClient
Signer msp.SigningIdentity
BroadcastClient common.BroadcastClient
DeliverClient deliverClientIntf
}

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

cmdFact.DeliverClient = newDeliverClient(client, chainID)
cmdFact.AnchorPeerParser = common.GetAnchorPeersParser(anchorPeerList)
}

return cmdFact, nil
}

const anchorPeerUsage = `In case of a newChain command, the list of anchor peer files, separated by commas.
The files should be in the following format:
anchorPeerHost
anchorPeerPort
PEM encoded certificate.
In example:
1.2.3.4
7051
-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIJALRf63iSHa0BMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQwHhcNMTcwMTI2MjMyMzM1WhcNMTgwMTI2MjMyMzM1WjBF
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAzbph0SEHYb/tvNYATWfpl7oAFpw3Tcn2s0icJaScqs2RodjosIOBK6AB
N6fkgGDHwYhYbMNfJzUYSYgXD4MPjDxzPw+/Hz02bjuxFB8pQnmln6b6pVHz79vL
i3UQ8eaCe3zswpX0JJTlOs5wdJGOySNRNatbVKl9HDNWcNl6Ec5MrlK3/v6OGF03
0ak7QYDNjyHaz3rMaOzJumRJeOxtjUO/+TbjN+bkcXSgQH9LjoeaZdkV/QWrCA1I
qGowBOxYcyiX56bKKFvCZ76ZYA55d3HyI/H7S258CTdE6WUTDXNqmXnX5WbBuUiK
dypI+KmGlzrRETahrJSJKdlxxtpPVwIDAQABo1AwTjAdBgNVHQ4EFgQUnK6ITmnz
hfNKFr+57Bcayzio47EwHwYDVR0jBBgwFoAUnK6ITmnzhfNKFr+57Bcayzio47Ew
DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAvYFu4xQDE11C8wdK/5LE
G61E9yjsDjFlhzgsG8+TqWI6LjHzm3hSNj7VMI7f0ckydxxOSQqKEkkQaL5GNS3B
JOwsGtPjgQ2Sxx2KrEyaNozxznm1qZflQCis95NVvjHeiybbLfjQRVKde0+7kSKc
cqBBE+IwxNofNyevlRyCBNsH6v2DLJoiFwvE5PqY6XvAcC17va/TKS16TVCqpxX0
OrngleEKom1hiU1MzGZ29/nGpwP/oD8Lf+BqxipLf3BdiDR2+n5dbrV/ul1VczwQ
F2ht++pZbdiqmv7CRAfvkSzrkwIeL+XfVR6ncFf4Nf92u6DJDnTzc/0K3pLaE+bo
JQ==
-----END CERTIFICATE-----
`
26 changes: 1 addition & 25 deletions peer/channel/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ import (
"time"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/configtx"
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
"github.com/hyperledger/fabric/common/configvalues/msp"
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
"github.com/hyperledger/fabric/peer/common"
cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -63,32 +60,11 @@ func createCmd(cf *ChannelCmdFactory) *cobra.Command {
}

func createChannelFromDefaults(cf *ChannelCmdFactory) (*cb.Envelope, error) {
if cf.AnchorPeerParser == nil {
cf.AnchorPeerParser = common.GetDefaultAnchorPeerParser()
}

anchorPeers, err := cf.AnchorPeerParser.Parse()
if err != nil {
return nil, err
}

oTemplate := configtxtest.OrdererTemplate()
oOrgTemplate := configtxtest.OrdererOrgTemplate()
appOrgTemplate := configtxtest.ApplicationOrgTemplate()
gosscg := configtxapplication.TemplateAnchorPeers("XXXFakeOrg", anchorPeers)

// FIXME: remove this hack as soon as 'peer channel create' is fixed properly
// we add admin policies for this config group, otherwise a majority won't be reached
p := &cb.ConfigPolicy{
Policy: &cb.Policy{
Type: int32(cb.Policy_SIGNATURE),
Policy: cauthdsl.MarshaledAcceptAllPolicy,
},
}
gosscg.Groups[configtxapplication.GroupKey].Groups["XXXFakeOrg"].Policies[msp.AdminsPolicyKey] = p

gossTemplate := configtx.NewSimpleTemplate(gosscg)
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, oOrgTemplate, appOrgTemplate, gossTemplate)
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, oOrgTemplate, appOrgTemplate)

signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()
if err != nil {
Expand Down
Loading

0 comments on commit 41bbdc2

Please sign in to comment.