Skip to content

Commit 9d43d67

Browse files
committed
Install Instantiate Instructions
update flow for instantiation update explanations in .md file yml updates update core peer ID to peer1 change filename, remove old file replace peerX with peer1 add conclusion doc for new CLI commands yml file for network will add to table of contents once new format is merged [ci skip] Change-Id: I1d6a1720f7aa2c6a45468ad36db4a32bec1f0654 Signed-off-by: Nick Gaski <[email protected]>
1 parent 7e35a64 commit 9d43d67

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed

docs/docker-2peer.yml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
version: '2'
2+
networks:
3+
bridge:
4+
5+
services:
6+
orderer:
7+
container_name: orderer
8+
image: hyperledger/fabric-orderer
9+
environment:
10+
- ORDERER_GENERAL_LEDGERTYPE=ram
11+
- ORDERER_GENERAL_BATCHTIMEOUT=10s
12+
- ORDERER_GENERAL_BATCHSIZE_MAXMESSAGECOUNT=10
13+
- ORDERER_GENERAL_MAXWINDOWSIZE=1000
14+
- ORDERER_GENERAL_ORDERERTYPE=solo
15+
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
16+
- ORDERER_GENERAL_LISTENPORT=5005
17+
- ORDERER_RAMLEDGER_HISTORY_SIZE=100
18+
- ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/fabric/msp/sampleconfig
19+
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
20+
command: orderer
21+
ports:
22+
- 5005:5005
23+
networks:
24+
- bridge
25+
26+
peer0:
27+
container_name: peer0
28+
image: hyperledger/fabric-peer
29+
environment:
30+
- CORE_PEER_ADDRESSAUTODETECT=true
31+
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
32+
- CORE_PEER_NETWORKID=peer0
33+
- CORE_NEXT=true
34+
- CORE_PEER_ENDORSER_ENABLED=true
35+
- CORE_PEER_ID=peer0
36+
- CORE_PEER_PROFILE_ENABLED=true
37+
- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:5005
38+
- CORE_PEER_GOSSIP_ORGLEADER=true
39+
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp/sampleconfig
40+
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
41+
command: peer node start --peer-defaultchain=false
42+
links:
43+
- orderer:orderer
44+
volumes:
45+
- /var/run/:/host/var/run/
46+
#in the "- <HOST>:/opt/gopath/src/github.com/hyperledger/fabric/examples/" mapping below, the HOST part
47+
#should be modified to the path on the host. This will work as is in the Vagrant environment
48+
- /opt/gopath/src/github.com/hyperledger/fabric/examples/:/opt/gopath/src/github.com/hyperledger/fabric/examples/
49+
depends_on:
50+
- orderer
51+
networks:
52+
- bridge
53+
54+
peer1:
55+
container_name: peer1
56+
image: hyperledger/fabric-peer
57+
environment:
58+
- CORE_PEER_ADDRESSAUTODETECT=true
59+
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
60+
- CORE_PEER_NETWORKID=peer1
61+
- CORE_NEXT=true
62+
- CORE_PEER_ENDORSER_ENABLED=true
63+
- CORE_PEER_ID=peer1
64+
- CORE_PEER_PROFILE_ENABLED=true
65+
- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:5005
66+
- CORE_PEER_GOSSIP_ORGLEADER=true
67+
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp/sampleconfig
68+
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
69+
command: peer node start --peer-defaultchain=false
70+
links:
71+
- orderer:orderer
72+
volumes:
73+
- /var/run/:/host/var/run/
74+
#in the "- <HOST>:/opt/gopath/src/github.com/hyperledger/fabric/examples/" mapping below, the HOST part
75+
#should be modified to the path on the host. This will work as is in the Vagrant environment
76+
- /opt/gopath/src/github.com/hyperledger/fabric/examples/:/opt/gopath/src/github.com/hyperledger/fabric/examples/
77+
depends_on:
78+
- orderer
79+
networks:
80+
- bridge
81+
82+
cli:
83+
container_name: cli
84+
image: hyperledger/fabric-peer
85+
tty: true
86+
environment:
87+
- GOPATH=/opt/gopath
88+
- CORE_PEER_ADDRESSAUTODETECT=true
89+
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
90+
- CORE_NEXT=true
91+
- CORE_PEER_ID=cli
92+
- CORE_PEER_ENDORSER_ENABLED=true
93+
- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:5005
94+
- CORE_PEER_ADDRESS=peer0:7051
95+
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp/sampleconfig
96+
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
97+
command: /bin/sh
98+
links:
99+
- orderer:orderer
100+
- peer0:peer0
101+
volumes:
102+
- /var/run/:/host/var/run/
103+
#in the "- <HOST>:/opt/gopath/src/github.com/hyperledger/fabric/examples/" mapping below, the HOST part
104+
#should be modified to the path on the host. This will work as is in the Vagrant environment
105+
- /opt/gopath/src/github.com/hyperledger/fabric/examples/:/opt/gopath/src/github.com/hyperledger/fabric/examples/
106+
depends_on:
107+
- orderer
108+
- peer0
109+
- peer1
110+
networks:
111+
- bridge

docs/install_instantiate.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Install and Instantiate
2+
3+
This tutorial requires the latest builds for `hyperledger/fabric-baseimage`, `hyperledger/fabric-peer`
4+
and `hyperledger/fabric-orderer`. Rather than pull from docker hub, you can compile
5+
these images locally to ensure they are up to date. It is up to the user how to build
6+
the images, although a typical approach is through vagrant. If you do choose to build
7+
through vagrant, make sure you have followed the steps outlined in
8+
[setting up the development environment](dev-setup/devenv.md). Then from the
9+
fabric directory within your vagrant environment, execute the `make peer-docker`
10+
and `make orderer-docker` commands.
11+
12+
### Start the network of 2 peers, an orderer, and a CLI
13+
Navigate to the fabric/docs directory in your vagrant environment and start your network:
14+
```bash
15+
docker-compose -f docker-2peer.yml up
16+
```
17+
View all your containers:
18+
```bash
19+
# active and non-active
20+
docker ps -a
21+
```
22+
23+
### Get into the CLI container
24+
Now, open a second terminal and navigate once again to your vagrant environment.
25+
```bash
26+
docker exec -it cli bash
27+
```
28+
You should see the following in your terminal:
29+
```bash
30+
root@ccd3308afc73:/opt/gopath/src/github.com/hyperledger/fabric/peer#
31+
```
32+
33+
### Create and join channel from the remote CLI
34+
From your second terminal, lets create a channel by the name of "myc":
35+
```bash
36+
peer channel create -c myc
37+
```
38+
This will generate a genesis block - `myc.block` - and place it into the same directory
39+
from which you issued your `peer channel create` command. Now, from the same directory,
40+
direct both peers to join channel - `myc` - by passing in the genesis block
41+
- `myc.block` - with a `peer channel join` command:
42+
```bash
43+
CORE_PEER_ADDRESS=peer0:7051 peer channel join -b myc.block
44+
CORE_PEER_ADDRESS=peer1:7051 peer channel join -b myc.block
45+
```
46+
47+
### Install the chaincode on peer0 from the remote CLI
48+
From your second terminal, and still within the CLI container, issue the following
49+
command to install a chaincode named `mycc` with a version of `v0` onto `peer0`.
50+
```bash
51+
CORE_PEER_ADDRESS=peer0:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0
52+
```
53+
54+
### Instantiate the chaincode on the channel from the remote CLI
55+
Now, still within the cli container in your second terminal, instantiate the chaincode
56+
`mycc` with version `v0` onto `peer0`. This instantiation will initialize the chaincode
57+
with key value pairs of ["a","100"] and ["b","200"].
58+
```bash
59+
CORE_PEER_ADDRESS=peer0:7051 peer chaincode instantiate -C myc -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0 -c '{"Args":["init","a","100","b","200"]}'
60+
```
61+
__Continue operating within your second terminal for the remainder of the commands__
62+
63+
### Query for the value of "a" to make sure the chaincode container has successfully started
64+
Send a query to `peer0` for the value of key `"a"`:
65+
```bash
66+
CORE_PEER_ADDRESS=peer0:7051 peer chaincode query -C myc -n mycc -v v0 -c '{"Args":["query","a"]}'
67+
```
68+
This query should return "100".
69+
70+
### Invoke to make a state change
71+
Send an invoke request to `peer0` to move 10 units from "a" to "b":
72+
```bash
73+
CORE_PEER_ADDRESS=peer0:7051 peer chaincode invoke -C myc -n mycc -v v0 -c '{"Args":["invoke","a","b","10"]}'
74+
```
75+
76+
### Query on the second peer
77+
Issue a query against the key "a" to `peer1`. Recall that `peer1` has successfully
78+
joined the channel.
79+
```bash
80+
CORE_PEER_ADDRESS=peer1:7051 peer chaincode query -C myc -n mycc -v v0 -c '{"Args":["query","a"]}'
81+
```
82+
This will return an error response because `peer1` does not have the chaincode installed.
83+
84+
### Install on the second peer
85+
Now add the chaincode to `peer1` so that you can successfully perform read/write operations.
86+
```bash
87+
CORE_PEER_ADDRESS=peer1:7051 peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v v0
88+
```
89+
__Note__: The initial instantiation applies to all peers in the channel, and is
90+
affected upon any peer that has the chaincode installed. Therefore, we installed
91+
the chaincode on `peer0` in order to execute the instantiate command through it.
92+
Now that we want to access the chaincode on `peer1`, we must install the chaincode
93+
on `peer1` as well. In general, a chaincode has to be installed only on those peers
94+
through which the chaincode needs to be accessed from. In particular, the
95+
chaincode must be installed on any peer receiving endorsement requests for that chaincode.
96+
97+
### Query on the second peer
98+
Now issue the same query request to `peer1`.
99+
```bash
100+
CORE_PEER_ADDRESS=peer1:7051 peer chaincode query -C myc -n mycc -v v0 -c '{"Args":["query","a"]}'
101+
```
102+
Query will now succeed.
103+
104+
### What does this demonstrate?
105+
- The ability to invoke (alter key value states) is restricted to peers that have the chaincode installed.
106+
- Just as state changes due to invoke on a peer affects all peers in the channel, the instantiate on a peer will
107+
likewise affect all peers in the channel.
108+
- The world state of the chaincode is available to all peers on the channel - even those that do not have the chaincode installed.
109+
- Once the chaincode is installed on a peer, invokes and queries can access those states normally.

0 commit comments

Comments
 (0)