Skip to content

Commit

Permalink
FAB-1417 Move peers from request.targets to Chain
Browse files Browse the repository at this point in the history
With the new SDK design, the Chain owns the peers
so the code needs to access the peers from the
the Chain, rather than passing them on the request.
This affects both sendDeploymentProposal and
sendTransactionProposal and both use
_checkProposalRequest, so changes to both functions
are required to allow the headless-tests to
continue to run successfully.

patch set 2: Fix gulp errors and update README.md
with instructions to use Mac natively to build
Docker images.

Change-Id: I48fc30cfcd9c1c688eed2bc820eb8f2f88f6af52
Signed-off-by: cdaughtr <cdaughtr@us.ibm.com>
  • Loading branch information
cdaughtr committed Dec 15, 2016
1 parent 04a9d05 commit 3163575
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 75 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ In the project root folder:

The following tests require setting up a local blockchain network as the target. Because v1.0 is still in active development, you still need the vagrant environment to build the necessary Docker images needed to run the network. Follow the steps below to set it up.
* You will need the COP server (new implementation of the member service) to run the tests. Because the COP project's build script does not yet produce a docker image, you'd need to run the COP server as a native process inside vagrant
* git clone both the *fabric* and *fabric-cop* repositories into the $GOPATH/src/github.com/hyperledger folder in your native host (MacOS, Windows or Ubuntu, etc)
* git clone both the *fabric* and *fabric-cop* repositories into the $GOPATH/src/github.com/hyperledger folder in your native host (MacOS, Windows or Ubuntu, etc).

If you are using a Mac and would like to build the docker images and run them natively instead of using vagrant, do the following:
* If docker is installed and it’s not ‘Docker for Mac’, uninstall and follow Docker’s clean up instructions to uninstall completely.
* Install ‘Docker for Mac’.
* Install Brew: http://brew.sh
* run `brew install gnu-tar —-with-default-names`

* To use vagrant, do the following:
* `cd fabric/devenv`
* Open the file `Vagrantfile` and insert the following statement below the existing `config.vm.network` statements:
* ` config.vm.network :forwarded_port, guest: 7056, host: 7056 # Openchain gRPC services`
Expand All @@ -41,7 +49,7 @@ The following tests require setting up a local blockchain network as the target.
* Once inside vagrant, follow these steps to start the COP server and the Peers network with orderer
* start COP (new membership service)
* cd `$GOPATH/src/github.com/hyperledger/fabric-cop
* follow the instructions in [fabric-cop README](https://github.com/hyperledger/fabric-cop) to build the COP binary
* run `make cop` to build the COP binary or follow the instructions in [fabric-cop README](https://github.com/hyperledger/fabric-cop)
* from the `fabric-cop` folder, launch the following command to start the COP server. The ec.pem and ec-key.pem certificates sets up the COP server as the trusted root that the Peer nodes have been statically configured as a temporary measure. In other words, the Peers will be able to trust any user certificates that have been signed by the COP server. This is important because the endorser code inside the Peer will need to validate the user certificate issued by COP before using it to verify the signature of the transaction proposal.
* `bin/cop server start -address "" -ca testdata/ec.pem -ca-key testdata/ec-key.pem -config testdata/testconfig.json`
* start the Peer network
Expand All @@ -50,7 +58,7 @@ The following tests require setting up a local blockchain network as the target.
* create a docker-compose.yml file in home directory (/home/vagrant), and copy [docker-compose.yml](https://raw.githubusercontent.com/hyperledger/fabric-sdk-node/master/test/fixtures/docker-compose.yml) file content into the file
* from /home/vagrant, run `docker-compose up --force-recreate` to launch the network
* Back in your native host (MacOS, or Windows, or Ubuntu, etc), run the following tests:
* Clear out your previous keyvalue store if needed (rm -fr /tmp/hfc-*)
* Clear out your previous keyvalue store if needed for fabric-sdk-node (rm -fr /tmp/hfc-*) and for fabric-cop (rm $HOME/.cop/cop.db)
* Run `gulp test` to run the entire test bucket and generate coverage reports (both in console output and HTMLs)
* Test user management with a member services, run `node test/unit/ca-tests.js`
* Test happy path from end to end, run `node test/unit/end-to-end.js`
Expand Down
31 changes: 21 additions & 10 deletions hfc/lib/Chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ var Chain = class {
* Sends a deployment proposal to one or more endorsing peers.
*
* @param {Object} request - An object containing the following fields:
* <br>`targets` : required - An array or single Endorsing {@link Peer} objects as the targets of the request
* <br>`chaincodePath` : required - String of the path to location of the source code of the chaincode
* <br>`chaincodeId` : required - String of the name of the chaincode
* <br>`chainId` : required - String of the name of the chain
Expand All @@ -302,6 +301,13 @@ var Chain = class {
sendDeploymentProposal(request) {
var errorMsg = null;

// Verify that a Peer has been added
if (this.getPeers().length < 1) {
errorMsg = 'Missing peer objects in Deployment proposal chain';
logger.error('Chain.sendDeploymentProposal error '+ errorMsg);
return Promise.reject(new Error(errorMsg));
}

// Verify that chaincodePath is being passed
if (request && (!request.chaincodePath || request.chaincodePath === '')) {
errorMsg = 'Missing chaincodePath parameter in Deployment proposal request';
Expand Down Expand Up @@ -376,7 +382,7 @@ var Chain = class {
proposal = self._buildProposal(lcccSpec, header);
let signed_proposal = self._signProposal(userContext.getEnrollment(), proposal);

return Chain._sendPeersProposal(request.targets, signed_proposal);
return Chain._sendPeersProposal(self.getPeers(), signed_proposal);
}
).then(
function(responses) {
Expand Down Expand Up @@ -404,7 +410,6 @@ var Chain = class {
* Sends a transaction proposal to one or more endorsing peers.
*
* @param {Object} request
* <br>`targets` : An array or single Endorsing {@link Peer} objects as the targets of the request
* <br>`chaincodeId` : The id of the chaincode to perform the transaction proposal
* <br>`chainId` : required - String of the name of the chain
* <br>`txId` : required - String of the transaction id
Expand All @@ -415,6 +420,14 @@ var Chain = class {
sendTransactionProposal(request) {
logger.debug('Chain.sendTransactionProposal - start');
var errorMsg = null;

// Verify that a Peer has been added
if (this.getPeers().length < 1) {
errorMsg = 'Missing peer objects in Transaction proposal chain';
logger.error('Chain.sendDeploymentProposal error '+ errorMsg);
return Promise.reject(new Error(errorMsg));
}

// args is not optional because we need for transaction to execute
if (request && !request.args) {
errorMsg = 'Missing "args" in Transaction proposal request';
Expand Down Expand Up @@ -456,7 +469,7 @@ var Chain = class {
proposal = self._buildProposal(invokeSpec, header);
let signed_proposal = self._signProposal(userContext.getEnrollment(), proposal);

return Chain._sendPeersProposal(request.targets, signed_proposal);
return Chain._sendPeersProposal(self.getPeers(), signed_proposal);
}
).then(
function(responses) {
Expand Down Expand Up @@ -604,7 +617,7 @@ var Chain = class {
function(results) {
var responses = results[0];
var proposal = results[1];
logger.debug('Member-sendQueryProposal - response %j', responses);
logger.debug('Chain-queryByChaincode - response %j', responses);
if(responses && Array.isArray(responses)) {
var results = [];
for(let i = 0; i < responses.length; i++) {
Expand Down Expand Up @@ -696,7 +709,7 @@ var Chain = class {
}
).catch(
function(err) {
logger.error('Member-sendPeersProposal - Promise is rejected: %s',err.stack ? err.stack : err);
logger.error('Chain-sendPeersProposal - Promise is rejected: %s',err.stack ? err.stack : err);
return reject(err);
}
);
Expand All @@ -710,10 +723,10 @@ var Chain = class {
.then(function (results) {
results.forEach(function (result) {
if (result.isFulfilled()) {
logger.debug('Member-sendPeersProposal - Promise is fulfilled: '+result.value());
logger.debug('Chain-sendPeersProposal - Promise is fulfilled: '+result.value());
responses.push(result.value());
} else {
logger.debug('Member-sendPeersProposal - Promise is rejected: '+result.reason());
logger.debug('Chain-sendPeersProposal - Promise is rejected: '+result.reason());
responses.push(result.reason());
}
});
Expand Down Expand Up @@ -752,8 +765,6 @@ var Chain = class {
errorMsg = 'Missing "chaincodeId" parameter in the proposal request';
} else if(!request.chainId) {
errorMsg = 'Missing "chainId" parameter in the proposal request';
} else if(!request.targets) {
errorMsg = 'Missing "targets" parameter in the proposal request';
} else if(!request.txId) {
errorMsg = 'Missing "txId" parameter in the proposal request';
} else if(!request.nonce) {
Expand Down
6 changes: 4 additions & 2 deletions test/unit/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ test('End-to-end flow of chaincode deploy, transaction invocation, and query', f
webUser = admin;
tx_id = utils.buildTransactionID({length:12});
nonce = utils.getNonce();
chain.addPeer(peer0);
chain.addPeer(peer1);

// send proposal to endorser
var request = {
targets: [peer0, peer1],
chaincodePath: testUtil.CHAINCODE_PATH,
chaincodeId: chaincode_id,
fcn: 'init',
Expand Down Expand Up @@ -181,9 +182,10 @@ test('End-to-end flow of chaincode deploy, transaction invocation, and query', f
function() {
tx_id = utils.buildTransactionID({length:12});
nonce = utils.getNonce();
chain.addPeer(peer0);
chain.addPeer(peer1);
// send proposal to endorser
var request = {
targets: [peer0, peer1],
chaincodeId : chaincode_id,
fcn: 'invoke',
args: ['move', 'a', 'b','100'],
Expand Down
3 changes: 2 additions & 1 deletion test/unit/endorser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ test('\n\n** TEST ** endorse chaincode deployment good test', function(t) {
function(admin) {
t.pass('Successfully enrolled user \'admin\'');

chain.addPeer(new Peer('grpc://localhost:7051'));
chain.addPeer(new Peer('grpc://localhost:7056'));
// send proposal to endorser
var request = {
targets: [new Peer('grpc://localhost:7051'), new Peer('grpc://localhost:7056')],
chaincodePath: testUtil.CHAINCODE_PATH,
chaincodeId: 'mycc',
fcn: 'init',
Expand Down
Loading

0 comments on commit 3163575

Please sign in to comment.