Unable to install custom chaincode
thanosgn opened this issue · 12 comments
Environment
Ubuntu 16.04.2 LTS
Docker version 17.03.1-ce, build c6d412e
How to repeat the problem?
I have pulled all necessary images and used docker-compose-2orgs-4peers.yaml
succesfully to run the 4 peers scenario.
After that, I edited the chaincode_example02.go
under /go/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
directory in all containers (fabric-cli, peer1.org2.example.com, peer0.org1.example.com, peer1.org1.example.com, peer0.org2.example.com, orderer.example.com). Despite all this, It seems that the initial chaincode is installed and running. The same thing happens even if I change the path to the chaincode in the peer chaincode install
command, and supply a path to my custom chaincode.
According to your problem description and my understanding, I can provide a way.
You can add a volumes at service cli
in docker-compose-2orgs-4peers.yaml
.
like this:
"""
volumes:
#- ./e2e_cli/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples
"""
Putting your changed chaincode in ./e2e_cli/examples
.
Hope can help you.
Thanks for the response, I have already tried it without success.
More specifically, I have placed my chaincode inside e2e_cli/examples/chaincode/go/chaincode_example02/chaincode_example02.go
file. I have uncommented the line you suggested, and then I ran the initialize.sh
script. However it seems that the default chaincode is still installed.
What should be the path (-p
) value in the peer chaincode install
command? I have it set to the default github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
.
@thanosgn it would be helpful if you could post the detailed steps to repeat.
cannot guess out what happens...
- Edit the
e2e_cli/examples/chaincode/go/chaincode_example02/chaincode_example02.go
and place custom chaincode. (e.g. change the invoke function) - Copy
e2e_cli/examples/chaincode/go/chaincode_example02/chaincode_example02.go
file in all 6 containers (fabric-cli, peer1.org2.example.com, peer0.org1.example.com, peer1.org1.example.com, peer0.org2.example.com, orderer.example.com) usingdocker cp
command. The file is placed in/go/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
directory. - Edit
docker-compose-2orgs-4peers.yaml
and uncomment line 61, as suggested above. - Run
docker-compose -f docker-compose-2orgs-4peers.yaml up -d
(I have previously removed all docker containers). - Enter the
fabric-cli
container - Run
scripts/initialize.sh
script - Call the
invoke
function or anything else that tests your chaincode. E.g. you could runscripts/test_4peers.sh
After doing theese steps, I cannot execute my own chaincode, but I keep getting the results from the "default" chaincode that was initially in /go/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/chaincode_example02.go
@thanosgn I just test with following steps, just like yours
- Add some test label in chaincode_example02.go, such as change Println.
- Uncomment line 61
then I get the output look like:
"""
ex02 Init======test whether is replaced or still default chaincode =====================================================
Aval = 100, Bval = 200
ex02 Invoke======test whether is replaced or still default chaincode =====================================================
Query Response:{"Name":"a","Amount":"100"}
"""
Obviously using the changed one.
Have you followed the seven steps that I suggested? If not, can you please provide a step by step execution? I frankly could not manage to execute my chaincode whatever I tried.
OK, this is my steps and whether it meets your test requirements?
- Change something in "https://github.com/yeasy/docker-compose-files/blob/master/hyperledger/1.0/e2e_cli/examples/chaincode/go/chaincode_example02/chaincode_example02.go"
- change
invoke
toinvoke_test
- change
fmt.Println("ex02 Init")
tofmt.Println("ex02 Init===has been changed===")
changefmt.Println("ex02 Invoke")
tofmt.Println("ex02 Invoke===has been changed to Invoke_test====")
-
Uncomment line 61 in "https://github.com/yeasy/docker-compose-files/blob/master/hyperledger/1.0/docker-compose-2orgs-4peers.yaml"
-
Change
invoke
toinvoke_test
at line 93,95 in test_4.sh, such as{"Args":["invoke_test","a","b","10"]}'
-
docker-compose -f docker-compose-2orgs-4peers.yaml up
-
in container execute
bash ./scripts/initailize.sh
andbash ./scripts/test_4.sh
-
then check the log at new generated container:
$ docker logs 819a5679e94b
ex02 Init===has been changed===
Aval = 100, Bval = 200
ex02 Invoke===has been changed to Invoke_test====
Query Response:{"Name":"a","Amount":"100"}
$ docker logs af1c137ccb26
ex02 Invoke===has been changed to Invoke_test====
Query Response:{"Name":"a","Amount":"90"}
ex02 Invoke===has been changed to Invoke_test====
Aval = 80, Bval = 220
ex02 Invoke===has been changed to Invoke_test====
Query Response:{"Name":"a","Amount":"80"}
$ docker logs af1c137ccb26
ex02 Invoke===has been changed to Invoke_test====
Query Response:{"Name":"a","Amount":"90"}
ex02 Invoke===has been changed to Invoke_test====
Aval = 80, Bval = 220
ex02 Invoke===has been changed to Invoke_test====
Query Response:{"Name":"a","Amount":"80"}
I followed your steps exactly but made no difference. The only step that differed was 4, where I ran sudo docker-compose -f docker-compose-2orgs-4peers-event.yaml up -d
instead of sudo docker-compose -f docker-compose-2orgs-4peers-event.yaml up
. For some reason I get a lot of errors without the -d
parameter.
My output was the following:
sudo docker logs 510753bb903c
ex02 Invoke
Query Response:{"Name":"a","Amount":"90"}
ex02 Invoke
Aval = 80, Bval = 220
ex02 Invoke
Query Response:{"Name":"a","Amount":"80"}
sudo docker logs 431b719bf66d
ex02 Invoke
Aval = 90, Bval = 210
sudo docker logs c34605c0dc80
ex02 Init
Aval = 100, Bval = 200
ex02 Invoke
Query Response:{"Name":"a","Amount":"100"}
The version of docker doesn't matter, Check whether rmi
new-generate images like dev-peer0.org2.example.com-mycc-1.0
@qiang0723 Thanks for your help! Can you please explain the last comment a bit more? I could not understand what you suggested.
I mean each time you want to re-start fabric network , clean both container and new-generated-images first, like
docker ps
2f20f7a46ef9 dev-peer1.org2.example.com-mycc-1.0 "chaincode -peer.addr" Less than a second ago Up 8 seconds dev-peer1.org2.example.com-mycc-1.0
dbbfb49276a2 dev-peer1.org1.example.com-mycc-1.0 "chaincode -peer.addr" Less than a second ago Up 27 seconds dev-peer1.org1.example.com-mycc-1.0
f34b05b3b38b dev-peer0.org2.example.com-mycc-1.0 "chaincode -peer.addr" Less than a second ago Up About a minute
and new-generated-images
docker images
dev-peer1.org2.example.com-mycc-1.0 latest ffa42829b2ef Less than a second ago 172.9 MB
dev-peer1.org1.example.com-mycc-1.0 latest 4bd694f8f60a Less than a second ago 172.9 MB
dev-peer0.org2.example.com-mycc-1.0 latest 1710aae8e3d8 Less than a second ago 172.9 MB
and delete them all
echo "clean containers...."
docker rm -f `docker ps -aq`
echo "clean images ..."
docker rmi -f `docker images|grep mycc-1.0|awk '{print $3}'`
Thank you! The solution was to remove the newly generated images as well as the containers, as you suggested.