Skip to content

Commit

Permalink
[FAB-18194] Fix service discovery for legacy installed chaincodes
Browse files Browse the repository at this point in the history
Service discovery endorsers query fails with errors:
"failed constructing descriptor for chaincodes"
"required chaincodes are not installed on sufficient peers"

The chaincodes installed with legacy chaincode lifecycle were not getting recognized
after peer restart since the path to installed chaincodes was set after
the legacy chaincode cache initialized.
Setting the installed chaincode path earlier in peer start sequence resolves the issue.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
(cherry picked from commit 0c10c0a)
  • Loading branch information
denyeart authored and guoger committed Sep 4, 2020
1 parent 0bd0ab2 commit 99332da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 25 additions & 0 deletions integration/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ var _ = Describe("Gossip State Transfer and Membership", func() {
basePeerForTransactions := peer0Org1
nwo.DeployChaincodeLegacy(network, channelName, orderer, chaincode, basePeerForTransactions)

By("verifying peer0Org1 discovers all the peers and the legacy chaincode before starting the tests")
Eventually(nwo.DiscoverPeers(network, peer0Org1, "User1", "testchannel"), network.EventuallyTimeout).Should(ConsistOf(
network.DiscoveredPeer(peer0Org1, "_lifecycle", "mycc"),
network.DiscoveredPeer(peer1Org1, "_lifecycle"),
network.DiscoveredPeer(peer0Org2, "_lifecycle"),
network.DiscoveredPeer(peer1Org2, "_lifecycle"),
))

By("STATE TRANSFER TEST 1: newly joined peers should receive blocks from the peers that are already up")

// Note, a better test would be to bring orderer down before joining the two peers.
Expand All @@ -142,6 +150,14 @@ var _ = Describe("Gossip State Transfer and Membership", func() {
basePeerForTransactions = peer1Org1
nwo.InstallChaincodeLegacy(network, chaincode, basePeerForTransactions)

By("verifying peer0Org1 discovers all the peers and the additional legacy chaincode installed on peer1Org1")
Eventually(nwo.DiscoverPeers(network, peer0Org1, "User1", "testchannel"), network.EventuallyTimeout).Should(ConsistOf(
network.DiscoveredPeer(peer0Org1, "_lifecycle", "mycc"),
network.DiscoveredPeer(peer1Org1, "_lifecycle", "mycc"),
network.DiscoveredPeer(peer0Org2, "_lifecycle"),
network.DiscoveredPeer(peer1Org2, "_lifecycle"),
))

By("stopping peer0Org1 (currently elected leader in Org1) and peer1Org2 (static leader in Org2)")
stopPeers(nwprocs, peer0Org1, peer1Org2)

Expand All @@ -152,6 +168,15 @@ var _ = Describe("Gossip State Transfer and Membership", func() {
// This effectively tests leader election as well, since the newly elected leader in Org1 (peer1Org1) will be the only peer
// that receives blocks from orderer and will therefore serve as the provider of blocks to all other peers.
sendTransactionsAndSyncUpPeers(nwprocs, orderer, basePeerForTransactions, channelName, peer0Org1, peer1Org2)

By("verifying peer0Org1 can still discover all the peers and the legacy chaincode after it has been restarted")
Eventually(nwo.DiscoverPeers(network, peer0Org1, "User1", "testchannel"), network.EventuallyTimeout).Should(ConsistOf(
network.DiscoveredPeer(peer0Org1, "_lifecycle", "mycc"),
network.DiscoveredPeer(peer1Org1, "_lifecycle", "mycc"),
network.DiscoveredPeer(peer0Org2, "_lifecycle"),
network.DiscoveredPeer(peer1Org2, "_lifecycle"),
))

})

When("gossip connection is lost and restored", func() {
Expand Down
8 changes: 4 additions & 4 deletions internal/peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func serve(args []string) error {
LegacyDeployedCCInfoProvider: &lscc.DeployedCCInfoProvider{},
}

// Configure CC package storage before ccInfoFSImpl.ListInstalledChaincodes() gets called
lsccInstallPath := filepath.Join(coreconfig.GetPath("peer.fileSystemPath"), "chaincodes")
ccprovider.SetChaincodesPath(lsccInstallPath)

ccInfoFSImpl := &ccprovider.CCInfoFSImpl{GetHasher: factory.GetDefault()}

// legacyMetadataManager collects metadata information from the legacy
Expand Down Expand Up @@ -464,10 +468,6 @@ func serve(args []string) error {

peerInstance.GossipService = gossipService

// Configure CC package storage
lsccInstallPath := filepath.Join(coreconfig.GetPath("peer.fileSystemPath"), "chaincodes")
ccprovider.SetChaincodesPath(lsccInstallPath)

if err := lifecycleCache.InitializeLocalChaincodes(); err != nil {
return errors.WithMessage(err, "could not initialize local chaincodes")
}
Expand Down

0 comments on commit 99332da

Please sign in to comment.