Skip to content

Commit

Permalink
FAB-16544 Properly detect node-readdition
Browse files Browse the repository at this point in the history
As pointed our in the review of the CR above, there was a logic bug in
handling removed organizations.  This CR adds a tests case and a fix.

Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
Change-Id: I6b4d7d0bb3d602867144860508b6683d7b23eb5e
  • Loading branch information
Jason Yellick authored and mastersingh24 committed Nov 9, 2019
1 parent ffa3335 commit 2448b5e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/pkg/peer/orderers/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (cs *ConnectionSource) Update(globalAddrs []string, orgs map[string]Orderer
defer cs.mutex.Unlock()
cs.logger.Debug("Processing updates for orderer endpoints")

newOrgToEndpointsHash := map[string][]byte{}

anyChange := false
hasOrgEndpoints := false
for orgName, org := range orgs {
Expand All @@ -73,8 +75,9 @@ func (cs *ConnectionSource) Update(globalAddrs []string, orgs map[string]Orderer
}
hash := hasher.Sum(nil)

newOrgToEndpointsHash[orgName] = hash

lastHash, ok := cs.orgToEndpointsHash[orgName]
cs.orgToEndpointsHash[orgName] = hash
if ok && bytes.Equal(hash, lastHash) {
continue
}
Expand All @@ -91,6 +94,8 @@ func (cs *ConnectionSource) Update(globalAddrs []string, orgs map[string]Orderer
}
}

cs.orgToEndpointsHash = newOrgToEndpointsHash

if hasOrgEndpoints && len(globalAddrs) > 0 {
cs.logger.Warning("Config defines both orderer org specific endpoints and global endpoints, global endpoints will be ignored")
}
Expand Down
33 changes: 33 additions & 0 deletions internal/pkg/peer/orderers/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,39 @@ var _ = Describe("Connection", func() {
Expect(endpoint.Refreshed).To(BeClosed())
}
})

When("the org is added back", func() {
BeforeEach(func() {
cs.Update(nil, map[string]orderers.OrdererOrg{
"org1": org1,
"org2": org2,
})
})

It("returns to the set of orderer endpoints", func() {
newEndpoints := cs.Endpoints()
Expect(stripEndpoints(newEndpoints)).To(ConsistOf(
stripEndpoints([]*orderers.Endpoint{
{
Address: "org1-address1",
CertPool: org1CertPool,
},
{
Address: "org1-address2",
CertPool: org1CertPool,
},
{
Address: "org2-address1",
CertPool: org2CertPool,
},
{
Address: "org2-address2",
CertPool: org2CertPool,
},
}),
))
})
})
})

When("an update modifies the global endpoints but does does not affect the org endpoints", func() {
Expand Down

0 comments on commit 2448b5e

Please sign in to comment.