Skip to content

Commit cc35a7c

Browse files
author
Srinivasan Muralidharan
committed
FAB-2128 get dev mode to work with the new CC model
https://jira.hyperledger.org/browse/FAB-2128 Dev mode was broken when the new install/instantiate model was introduced. This CR fixes that bug. Also added documentation for the dev mode. Change-Id: I6b4bb0f3d8a20c64cc4e2ac2bfd070a385a0909f Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent dfc3077 commit cc35a7c

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

core/chaincode/handler.go

+17
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,23 @@ func (handler *Handler) notifyDuringStartup(val bool) {
480480
handler.readyNotify <- val
481481
} else {
482482
chaincodeLogger.Debug("nothing to notify (dev mode ?)")
483+
//In theory, we don't even need a devmode flag in the peer anymore
484+
//as the chaincode is brought up without any context (ledger context
485+
//in particular). What this means is we can have - in theory - a nondev
486+
//environment where we can attach a chaincode manually. This could be
487+
//useful .... but for now lets just be conservative and allow manual
488+
//chaincode only in dev mode (ie, peer started with --peer-chaincodedev=true)
489+
if handler.chaincodeSupport.userRunsCC {
490+
if val {
491+
chaincodeLogger.Debug("sending READY")
492+
ccMsg := &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY}
493+
go handler.triggerNextState(ccMsg, true)
494+
} else {
495+
chaincodeLogger.Errorf("Error during startup .. not sending READY")
496+
}
497+
} else {
498+
chaincodeLogger.Warningf("trying to manually run chaincode when not in devmode ?")
499+
}
483500
}
484501
}
485502

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Using dev mode
2+
==============
3+
4+
Normally chaincodes are started and maintained by peer. However in “dev”
5+
mode, chaincode is built and started by the user. This mode is useful
6+
during chaincode development phase for rapid code/build/run/debug cycle
7+
turnaround.
8+
9+
To keep this a realistic “dev” environment, we are going to keep it “out
10+
of the box” - with one exception: we create two channels instead of
11+
using the default ``testchainid`` channel to show how the single running
12+
instance can be accessed from multiple channels.
13+
14+
Start the orderer
15+
-----------------
16+
17+
::
18+
19+
orderer
20+
21+
The above starts the orderer in the local environment using default
22+
orderer configuration as defined in ``orderer/orderer.yaml``.
23+
24+
Start the peer in dev mode
25+
--------------------------
26+
27+
::
28+
29+
peer node start --peer-defaultchain=false --peer-chaincodedev=true
30+
31+
The above command starts the peer using the default ``msp/sampleconfig``
32+
MSP. The ``--peer-chaincodedev=true`` puts it in “dev” mode. ##Create
33+
channels ch1 and ch2
34+
35+
::
36+
37+
peer channel create -o 127.0.0.1:7050 -c ch1
38+
peer channel create -o 127.0.0.1:7050 -c ch2
39+
40+
Above assumes orderer is reachable on ``127.0.0.1:7050``. The orderer
41+
now is tracking channels ch1 and ch2 for the default configuration.
42+
43+
::
44+
45+
peer channel join -b ch1.block
46+
peer channel join -b ch2.block
47+
48+
The peer has now joined channels cha1 and ch2.
49+
50+
Start the chaincode
51+
-------------------
52+
53+
::
54+
55+
cd examples/chaincode/go/chaincode_example02
56+
go build
57+
CORE_CHAINCODE_LOGLEVEL=debug CORE_PEER_ADDRESS=127.0.0.1:7051 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
58+
59+
The chaincode is started with peer and chaincode logs showing it got
60+
registered successfully with the peer.
61+
62+
Use the chaincode
63+
-----------------
64+
65+
::
66+
67+
peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch1
68+
69+
peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch2
70+
71+
The above instantiates the chaincode with the two channels. With default
72+
settings it might take a few seconds for the transactions to be
73+
committed.
74+
75+
::
76+
77+
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch1
78+
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch2
79+
80+
The above invokes the chaincode using the two channels.
81+
82+
::
83+
84+
peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch1
85+
peer chaincode invoke -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch2

0 commit comments

Comments
 (0)