IBM-Blockchain-Archive / marbles

WARNING: This repository is no longer maintained ⚠️ This repository will not be updated. The repository will be kept available in read-only mode.
Apache License 2.0
1.03k stars 979 forks source link

Modify the chaincode #136

Closed SBerda closed 7 years ago

SBerda commented 7 years ago

Hello,

What we trying to archieve Modify the chaincode content to add our custom fields to marbles project.

To do that, as a first step, we would like to modify the output text of a blockchain function . Let's take for exemple « fmt.Println("starting init_marble FizzBuzz") » If we do our work correctly, « docker logs » of dev-peer0-marbles-v0  should output the added content.

What we have tried so far :

Install and instantiate the chaincode Then go inside the container « dev-peer0-marbles-v0 » and remplace /usr/local/bin/chaincode with our chaincode binary and launch marbles as usual.

Note : We cannot modify the chaincode between « install » and « instantiate » because the docker container is not launched yet.

We also wondered if it was related to : https://hyperledger-fabric.readthedocs.io/en/v1.0.0-beta/cc-packaging-and-signing.html# A file is generated in peer0 at the following path : /var/hyperledger/production/chaincodes/marbles.v0

If you have any idea about it ?

Thank you in advance for your help Best regards

SBerda

dshuffma-ibm commented 7 years ago

but why? why don't you guys write your modified chaincode and install/instantiate THAT chaincode. am I missing something?

SBerda commented 7 years ago

Yes I sorry, I have explained badly.

We are writting our modified chaincode but it's based on the marbles chaincode, we wanted to take a working exemple and modified it.

But it's seems that the marbles project don't want to use our custom chaincode and use it's own even if we only modify juste a little .

Do you have any idea why ?

Thanks again for you help

ajpauwels commented 7 years ago

It seems that you are not following the proper procedure for editing, installing, and instantiating a new version of the chaincode. In order to edit chaincode, you can't simply login to the container and replace the existing binary (well, maybe you could, but that is definitely not the system that's been put in place to do so, and as you can see it's causing issues).

The general procedure for editing an existing chaincode to a new version is as follows:

  1. Edit the .go file containing your chaincode
  2. Emit an install transaction which installs the chaincode on a peer. You should emit an installation on every peer you wish the chaincode to run on.
  3. Emit one upgrade (not instantiate, instantiate is for starting new chaincode, upgrade is for updating an existing chaincode to a new version) transaction to the orderer which then starts the new chaincode container (its name will change to reflect the new version)
  4. All invocations to that chaincode will now be performed on the latest version

The exact implementation of this procedure depends on the network you have setup to run marbles. Are you running a local Fabric network, or through Bluemix? If you are running a local network, which network did you choose? Basic or byfn? If it's a custom network, please post the docker-compose.yaml file you used to setup your network,

mrshah-at-ibm commented 7 years ago

Thanks @ajpauwels

@SBerda did the above comment solve the issue? Can we close this?

SBerda commented 7 years ago

Hi, Yes, thank you @ajpauwels for your help . :)

Rohit-shopasky commented 5 years ago

But every time when we debug our chaincode, should we install new version of chaincode? Is there any shortcut way to edit the installed chaincode?

ajpauwels commented 5 years ago

Yes, every time you change the chaincode you install the new version of it. As outlined in any Hyperledger Fabric doc or tutorial you may find. That is how chaincode and Hyperledger Fabric works.

I suggest writing a script which automates the commands to install and upgrade the chaincode. On a local devnet this process takes 1-2 seconds.

mrshah-at-ibm commented 5 years ago

You can try running your peer in chaincode-dev mode. Then you can run your chaincode and connect it manually to the peer. You can keep iterating on your chaincode without the need to reinstall/instantiate.

Ref: https://hyperledger-fabric.readthedocs.io/en/release-1.4/peer-chaincode-devmode.html