HyperledgerHandsOn / trade-finance-logistics

Trade Finance and Logistics based on Letter of Credit and Proof of Shipment
Apache License 2.0
174 stars 1.49k forks source link

upgrade chain code - help on the right process #39

Closed sahirvsahirv closed 5 years ago

sahirvsahirv commented 5 years ago

Hello Sir, Hello again. I am back to this work after a long break of reading up on energy related papers. I want to work on incremental changes in my chaincode, deploy and test it to see consensus happening.

Following is what I do -

I installed and instantiated the chaincode with v0 on the ledger.

curl -s -X POST http://localhost:4000/chaincode/instantiate -H "authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzM4OTQ4OTIsInVzZXJuYW1lIjoiYWRtaW4iLCJvcmdOYW1lIjoidXRpbGl0eW9yZyIsImlhdCI6MTUzMzg5MDc1Mn0.ckS82mBlP424VmiKRZlpZPVwdlcop5YEc72fBwVJv-s" -H "content-type: application/json" -d '{"ccpath": "github.com/utility_workflow", "ccversion": "v0", "args": ["2kmqtt", "100", "REQUESTED"]}' {"success":true,"message":"Chaincode instantiated"}

Now i wish to upgrade the chaincode. I have two docker containers created with the dev prefix for running the chaincode.

I copy the same code to another directory and rename it with a suffix v1 and run the command

curl -s -X POST http://localhost:4000/chaincode/upgrade -H "authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzYyNzgwMzQsInVzZXJuYW1lIjoiYWRtaW4iLCJvcmdOYW1lIjoidXRpbGl0eW9yZyIsImlhdCI6MTUzNjI3Mzg5NH0.CV4rjs-QgA1G62D7OGbwQz98n2Ydr_1T8SB5khJlm40" -H "content-type: application/json" -d '{"ccpath": "github.com/utility_workflow_v1", "ccversion": "v1", "args": ["2kmqtt", "100", "REQUESTED"]}' {"success":false,"message":"Failed to send install Proposal or receive valid response from org consumerorg: [object Object]"}

The error messages are on the node.js terminal are as follows. I have changed the config_upgrade.json and constants.json in the middleware to accomodate my network

My constants.js refers to : module.exports = { networkConfig: networkConfig, (which is config.json and not config_upgrade.json) And install-chaincode .js has module.exports.installChaincode = installChaincode;

Is there some configuration that i need to change to make upgrade work using the middleware (i also tried deleting the image and containers created by the install and instantiate of the first version of chaincode)?

The error messages are below:

Successfully enrolled user 'admin' info: [packager/Golang.js]: packaging GOLANG from github.com/utility_workflow_v1 500 {{{{{{{{{console.log(results[0][0].response.status);}}}}}}}}}}}}}} error: [install-chaincode]: install proposal was bad from peer undefined in org consumerorg Failed to install chaincode in peers of organization "consumerorg". Error: Failed to send install Proposal or receive valid response from org consumerorg: [object Object] at Client.newDefaultKeyValueStore.then.then.then (/home/hypledvm/go/src/utilitypoc/middleware/install-chaincode.js:137:10) at error: [install-chaincode]: Failed to install chaincode in peers of organization "consumerorg". Error: Failed to send install Proposal or receive valid response from org consumerorg: [object Object] at Client.newDefaultKeyValueStore.then.then.then (/home/hypledvm/go/src/utilitypoc/middleware/install-chaincode.js:137:10) at (node:7080) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent. (node:7080) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Your assistance on this would be greatly appreciated.

Thanks

VRamakrishna commented 5 years ago

Sorry, I don't have time to help you with detailed debugging, so I'll just offer general advice here.

If you use the default code in the repository, a channel update MUST be performed before the chaincode upgrade. This is because the new version of the chaincode as well as the upgrade procedure assume the existence of 5 organizations and 5 peers (one in each org.) The initial channel and chaincode assume 4 orgs. So if you are trying to upgrade the chaincode (using our scripts) without upgrading the channel, you are going to see errors.

Instructions to update the channel as well as chaincode are provided here (and in the book, if you have it.)

If you don't want to upgrade the channel, you'll need to modify the chaincode and the scripts (JS code in middleware.)

sahirvsahirv commented 5 years ago

Thanks for the prompt response.

Channel upgrade should not be required in my case since mine is a 2org 1 peer channel.

I just need to updgrade. I have changed the configuration files - constants.json and config-upgrade.json

I am not sure what else I need to change here.

Thanks Gowri

On Thu, 6 Sep 2018 at 12:14 PM, VRamakrishna notifications@github.com wrote:

Sorry, I don't have time to help you with detailed debugging, so I'll just offer general advice here.

If you use the default code in the repository, a channel update MUST be performed before the chaincode upgrade. This is because the new version of the chaincode as well as the upgrade procedure assume the existence of 5 organizations and 5 peers (one in each org.) The initial channel and chaincode assume 4 orgs. So if you are trying to upgrade the chaincode (using our scripts) without upgrading the channel, you are going to see errors.

Instructions to update the channel as well as chaincode are provided here (and in the book, if you have it.)

If you don't want to upgrade the channel, you'll need to modify the chaincode and the scripts (JS code in middleware.)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HyperledgerHandsOn/trade-finance-logistics/issues/39#issuecomment-418983027, or mute the thread https://github.com/notifications/unsubscribe-auth/ATQGkwfSDiq3ZAYuN5o3FyMt2H2SZPADks5uYMQ1gaJpZM4WcT-a .

VRamakrishna commented 5 years ago

Like I said, if you are using our chaincodes (initial and v1), the former has internal logic that assumes 4 organizations and the latter has internal logic that assumes 5 organizations.

But if you have written your own chaincode, then you'll have to figure out the logic for yourself.

If there's no organization-specific logic within the chaincode, you can freely upgrade it without updating the channel. (so you'll use the old config, the same set of peers, no need to join new peers to the channel; make sure that installation is happening on the right set of peers.)

Please check out the JSON files to understand what they contain. If you change one thing (like the org structure), you'll have to update the various config files. The two config JSON files in middleware represent two specific org structures we were using to illustrate channel updates. If you have different org structures, you'll have to modify them suitably.

sahirvsahirv commented 5 years ago

I have changed the json files already according to the org structure and the chaincode.

When you have time please look into it the error described.

Thanks Gowri

On Thu, 6 Sep 2018 at 12:44 PM, VRamakrishna notifications@github.com wrote:

Like I said, if you are using our chaincodes (initial and v1), the former has internal logic that assumes 4 organizations and the latter has internal logic that assumes 5 organizations.

But if you have written your own chaincode, then you'll have to figure out the logic for yourself.

If there's no organization-specific logic within the chaincode, you can freely upgrade it without updating the channel. (so you'll use the old config, the same set of peers, no need to join new peers to the channel; make sure that installation is happening on the right set of peers.)

Please check out the JSON files to understand what they contain. If you change one thing (like the org structure), you'll have to update the various config files. The two config JSON files in middleware represent two specific org structures we were using to illustrate channel updates. If you have different org structures, you'll have to modify them suitably.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HyperledgerHandsOn/trade-finance-logistics/issues/39#issuecomment-418989971, or mute the thread https://github.com/notifications/unsubscribe-auth/ATQGk4fAfqgUg-uSevWGKVJdWMVMKsRnks5uYMtTgaJpZM4WcT-a .

VRamakrishna commented 5 years ago

I'm sorry, but there are innumerable number of ways to get configurations wrong, especially in a distributed system as complicated as Fabric. Therefore, it's if you understand the basic concepts and then configure your system suitably.

Clearly there's something wrong in your configuration of consumerorg. So you should start looking there. Whatever your configuration in the network portion is should match that in the middleware. The set of peers with the right names and ports, for example. If there's a mismatch, you are bound to get errors like the above, though I cannot diagnose the cause just by looking at an error message.

Besides that, my earlier comment stands. If you are not upgrading channel configuration, new upgrades should work as long as you are installing on the same peers and orgs that were already joined during the original channel creation and installation process. If you are seeing errors, it means you've made an error in a configuration somewhere.

As I mentioned to you a while ago, I cannot provide personalized debugging help for anyone. You'll have to make an attempt to diagnose this yourself after understanding what the process involves.

Good luck!

sahirvsahirv commented 5 years ago

Thanks!

On Thu, 6 Sep 2018 at 1:56 PM, VRamakrishna notifications@github.com wrote:

I'm sorry, but there are innumerable number of ways to get configurations wrong, especially in a distributed system as complicated as Fabric. Therefore, it's if you understand the basic concepts and then configure your system suitably.

Clearly there's something wrong in your configuration of consumerorg. So you should start looking there. Whatever your configuration in the network portion is should match that in the middleware. The set of peers with the right names and ports, for example. If there's a mismatch, you are bound to get errors like the above, though I cannot diagnose the cause just by looking at an error message.

Besides that, my earlier comment stands. If you are not upgrading channel configuration, new upgrades should work as long as you are installing on the same peers and orgs that were already joined during the original channel creation and installation process. If you are seeing errors, it means you've made an error in a configuration somewhere.

As I mentioned to you a while ago, I cannot provide personalized debugging help for anyone. You'll have to make an attempt to diagnose this yourself after understanding what the process involves.

Good luck!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HyperledgerHandsOn/trade-finance-logistics/issues/39#issuecomment-419009288, or mute the thread https://github.com/notifications/unsubscribe-auth/ATQGk_MqY8C9lw1qf5vowdUlz4r1wzrzks5uYNwcgaJpZM4WcT-a .