Hyperledger fabric sample network
Using the Fabric test network
Bring up the test network
cd /home/namho46/hyperledger/fabric-samples/test-network
remove any containers or artifacts from any previous runs:
./network.sh down
bring up the network
./network.sh up
Creating a channel
You can use the network.sh script to create a channel
between Org1 and Org2 and join their peers to the channel.
create a channel with the default name of mychannel
:
./network.sh createChannel
create a channel with custom name:
./network.sh createChannel -c channel1
create a second channel named channel2:
./network.sh createChannel -c channel2
bring up the network and create a channel in a single step:
./network.sh up createChannel
Starting a chaincode on the channel
The deployCC
subcommand will install the asset-transfer (basic) chaincode
on peer0.org1.example.com
and peer0.org2.example.com
and then deploy
the chaincode on the channel specified using the channel flag
(or mychannel
if no channel is specified).
start a chaincode on the channel:
./network.sh deployCC
Interacting with the network
add binaries to your CLI Path
also set the FABRIC_CFG_PATH
to point to the core.yaml
file
in the fabric-samples repository:
export PATH=${PWD}/../bin:$PATH \
export FABRIC_CFG_PATH=$PWD/../config/
Environment variables for Org1
set the environment variables that allow you to operate the peer CLI as Org1:
export CORE_PEER_TLS_ENABLED=true \
export CORE_PEER_LOCALMSPID="Org1MSP" \
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp \
export CORE_PEER_ADDRESS=localhost:7051
initialize the ledger with assets:
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'
get the list of assets that were added to your channel ledger:
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
the endorsement policy for the asset-transfer (basic) chaincode requires the transaction to be signed by Org1 and Org2
change the owner of an asset on the ledger by invoking the asset-transfer (basic) chaincode:
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'
Environment variables for Org2
operate as Org2:
export CORE_PEER_TLS_ENABLED=true \
export CORE_PEER_LOCALMSPID="Org2MSP" \
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp \
export CORE_PEER_ADDRESS=localhost:9051
query the asset-transfer (basic) chaincode running on peer0.org2.example.com:
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'
Bring down the network
bring down the network:
./network.sh down
Fabric CA
Bring up the network with Certificate Authorities
bring down any running networks:
./network.sh down
bring up the network with the CA flag:
./network.sh up -ca
examine the MSP folder of the Org1 admin user:
tree organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/
The command will reveal the MSP folder structure and configuration file:
organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/
└── msp
├── IssuerPublicKey
├── IssuerRevocationPublicKey
├── cacerts
│ └── localhost-7054-ca-org1.pem
├── config.yaml
├── keystore
│ └── 54148a5aa8db839cea417f6df2c45ac6824e543d0712f4e3c65ea2ab0b920d51_sk
├── signcerts
│ └── cert.pem
└── user
What’s happening behind the scenes?
issue the command of ./network.sh up
.
./network.sh
creates the certificates and keys for two peer organizations and the orderer organization. By default, the script uses the cryptogen tool using the configuration files located in theorganizations/cryptogen
folder. If you use the-ca
flag to create Certificate Authorities, the script uses Fabric CA server configuration files andregisterEnroll.sh
script located in theorganizations/fabric-ca
folder. Both cryptogen and the Fabric CAs create the crypto material and MSP folders for all three organizations in theorganizations
folder.- The script uses configtxgen tool to create the system channel genesis block. Configtxgen consumes the
TwoOrgsOrdererGenesis
channel profile in theconfigtx/configtx.yaml
file to create the genesis block. The block is stored in thesystem-genesis-block
folder. - Once the organization crypto material and the system channel genesis block have been generated, the
network.sh
can bring up the nodes of the network. The script uses thedocker-compose-test-net.yaml
file in thedocker
folder to create the peer and orderer nodes. Thedocker
folder also contains thedocker-compose-e2e.yaml
file that brings up the nodes of the network alongside three Fabric CAs. This file is meant to be used to run end-to-end tests by the Fabric SDK. Refer to the Node SDK repo for details on running these tests. - If you use the
createChannel
subcommand,./network.sh
runs thecreateChannel.sh
script in thescripts
folder to create a channel using the supplied channel name. The script uses theconfigtx.yaml
file to create the channel creation transaction, as well as two anchor peer update transactions. The script uses the peer cli to create the channel, joinpeer0.org1.example.com
andpeer0.org2.example.com
to the channel, and make both of the peers anchor peers. - If you issue the
deployCC
command,./network.sh
runs thedeployCC.sh
script to install the asset-transfer (basic) chaincode on both peers and then define then chaincode on the channel. Once the chaincode definition is committed to the channel, the peer cli initializes the chaincode using theInit
and invokes the chaincode to put initial data on the ledger.
'Hyperledger Fabric' 카테고리의 다른 글
[Paper Summary] Performance Benchmarking and Optimizing Hyperledger Fabric Blockchain Platform (0) | 2020.07.29 |
---|---|
[Hyperledger Fabric v2.0] Policies (0) | 2020.07.28 |
[Hyperledger Fabric v2.0] Transaction Workflow (0) | 2020.07.27 |
[Hyperledger Fabric v2.0] MSP structure (0) | 2020.07.21 |
[Hyperledger Fabric v2.0] Network, Identity, MSP (0) | 2020.07.20 |
댓글