Adding the new organization to the network

The new organization is logically added to the channel through a configuration update. To physically add it to our trade network and make it participate in shared ledger transactions, we need to:

  • Join the exporting entity organization's peers to tradechannel
  • Install the current version of the chaincode on the newly added peers

The good news is that there is nothing new to be done here. We have already implemented functions for both these procedures (joinChannel in join-channel.js and installChaincode in install-chaincode.js, respectively), and we just need to exercise them on behalf of the new organization's resources.

Before running these steps, we must augment the network configuration used by the middleware. Earlier, we used config.json in the middleware folder to represent the 4-organization network. We will now replace that with config_upgrade.json in the same folder. All this file contains is one extra property in trade-network called exportingentityorg (which is how the middleware code will recognize our new organization) as follows:

"exportingentityorg": { 
  "name": "peerExportingEntityOrg", 
  "mspid": "ExportingEntityOrgMSP", 
  "ca": { 
    "url": "https://localhost:11054", 
      "name": "ca-exportingentityorg" 
  }, 
  "peer1": { 
    "requests": "grpcs://localhost:11051", 
    "events": "grpcs://localhost:11053", 
    "server-hostname": "peer0.exportingentityorg.trade.com", 
    "tls_cacerts": "../network/crypto-config/peerOrganizations/exportingentityorg.trade.com/peers/peer0.exportingentityorg.trade.com/msp/tlscacerts/tlsca.exportingentityorg.trade.com-cert.pem" 
  } 
} 

Note that the ports indicated previously match those specified in the docker-compose-exportingEntityOrg.yaml file we used to start the MSP and peer for this organization. The path to the certificate matches what was generated using cryptogen earlier in this section, and the names match what was specified in the configtx.yaml. The organization has just one peer, which is exactly what we specified in the latter file.

To ensure that the middleware functions load the right configuration, we need to change the value of the networkConfig variable in constants.js from config.json to config_upgrade.json. We do that in the file new-org-join-channel.js as follows:

var Constants = require('./constants.js'), 
Constants.networkConfig = './config_upgrade.json';

Now we are ready to run the channel join procedure for the single peer belonging to the exporting entity's organization. The code for this in new-org-join-channel.js is as follows:

var joinChannel = require('./join-channel.js'), 
Client.addConfigFile(path.join(__dirname, Constants.networkConfig)); 
var ORGS = Client.getConfigSetting(Constants.networkId); 
joinChannel.joinChannel('exportingentityorg', ORGS, Constants); 

The call to joinChannel has the effect of joining the peer whose details are specified in the trade-network:exportingentityorg:peer1 section in config_upgrade.js to tradechannel. To execute this operation, just run the following:

node new-org-join-channel.js 

The new peer is now part of the channel and will eventually sync the contents of the shared ledger for the channel through the gossip protocol from the existing network peers.

Similarly, we can install the chaincode on this peer by calling the installChaincode function in install-chaincode.js. But as it happens, we would like to demonstrate the chaincode upgrade capability at this time. So instead of running the installation procedure twice, we can straightaway install the new version on all 5 peers. We will describe that procedure in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.7.102