在上一篇博客中我们已经成功启动了Fabric网络,接下来让我们来看看它在启动过程中发生了什么事。
一、日志输出分析
出现此输出,代表网络启动成功
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
Build your first network (BYFN) end-to-end test
在启动成功后,会自动执行scripts目录下的脚本,去做一些创建通道,加入通道,更新通道以及安装链码等操作。
1、首先创建通道(中间部分过长,省略输出):
Channel name : mychannel
Creating channel...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
*
*
*
*
*
*
===================== Channel "mychannel" is created successfully =====================
2、让所有节点加入通道:
Having all peers join the channel...
……
……(输出省略)
……
/**组织1的peer0节点加入通道*/
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
2019-12-05 13:41:32.281 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:41:32.282 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:41:32.287 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-12-05 13:41:32.289 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C088C92A4EF0510...E1C0406CFACF1A080A000A000A000A00
2019-12-05 13:41:32.289 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: 811F8513657C4F21342ED396947D18FAFB85A40C218788C3208E6C0245A994D3
2019-12-05 13:41:32.431 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2019-12-05 13:41:32.431 UTC [main] main -> INFO 007 Exiting.....
===================== PEER0 joined on the channel "mychannel" =====================
/**组织1的peer1节点加入通道*/
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
2019-12-05 13:41:35.598 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:41:35.598 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:41:35.610 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-12-05 13:41:35.611 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C088F92A4EF0510...E1C0406CFACF1A080A000A000A000A00
2019-12-05 13:41:35.611 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: 321D6D6E235EAAEED1DEEFFC44D5DA1E4FA96F6D9542DD959ABF99A0421F9414
2019-12-05 13:41:35.714 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2019-12-05 13:41:35.714 UTC [main] main -> INFO 007 Exiting.....
===================== PEER1 joined on the channel "mychannel" =====================
/**组织2的peer0节点加入通道*/
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
2019-12-05 13:41:38.925 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:41:38.925 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:41:38.929 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-12-05 13:41:38.931 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A8A070A5C08011A0C089292A4EF0510...E1C0406CFACF1A080A000A000A000A00
2019-12-05 13:41:38.931 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: 4B1598F5DD4D1B47D3910B7226E376EC60DDF819C00C8CBD084D43C0BAA2D89F
2019-12-05 13:41:39.009 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2019-12-05 13:41:39.010 UTC [main] main -> INFO 007 Exiting.....
===================== PEER2 joined on the channel "mychannel" =====================
/**组织2的peer1节点加入通道*/
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
2019-12-05 13:41:42.132 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:41:42.132 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:41:42.135 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-12-05 13:41:42.135 UTC [msp/identity] Sign -> DEBU 004 Sign: plaintext: 0A89070A5B08011A0B089692A4EF0510...E1C0406CFACF1A080A000A000A000A00
2019-12-05 13:41:42.135 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: A4A340BC93DBFF39D53E83AE7C2AD9245D1EBE17C192BB31E22D4CB88A4E6F76
2019-12-05 13:41:42.363 UTC [channelCmd] executeJoin -> INFO 006 Peer joined the channel!
2019-12-05 13:41:42.363 UTC [main] main -> INFO 007 Exiting.....
===================== PEER3 joined on the channel "mychannel" =====================
3、更新两个组织的锚节点:
Updating anchor peers for org1...
……
……
……
/**组织1的信息设立在peer0节点上*/
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
………
2019-12-05 13:41:45.943 UTC [main] main -> INFO 010 Exiting.....
===================== Anchor peers for org "Org1MSP" on "mychannel" is updated successfully =====================
Updating anchor peers for org2...
……
……
/**组织2的信息设立在peer0节点上*/
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
……
===================== Anchor peers for org "Org2MSP" on "mychannel" is updated successfully =====================
4、安装chaincode
Installing chaincode on org1/peer0...
……
/**在组织1的peer0节点上安装chaincode*/
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
……
===================== Chaincode is installed on remote peer PEER0 =====================
Install chaincode on org2/peer2...
……
/**在组织2的peer0节点上安装chaincode*/
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
……
===================== Chaincode is installed on remote peer PEER2 =====================
5、智能合约的初始化,在组织2的peer0节点上初始化。
Instantiating chaincode on org2/peer2...
……
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
2019-12-05 13:41:56.969 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:41:56.970 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:41:56.973 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2019-12-05 13:41:56.973 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2019-12-05 13:41:56.973 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A95070A6708031A0C08A492A4EF0510...324D53500A04657363630A0476736363
2019-12-05 13:41:56.973 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 0C4CD7014996C5942DBEB483EA41058BB56FCD70D7F4460ABE9E75B70F4BD70E
2019-12-05 13:44:14.928 UTC [msp/identity] Sign -> DEBU 007 Sign: plaintext: 0A95070A6708031A0C08A492A4EF0510...99BAE0A5D346552009B08B05BE6139E2
2019-12-05 13:44:14.986 UTC [msp/identity] Sign -> DEBU 008 Sign: digest: 85F257C748AACC082978E2342BE71D565D44DE6625AEF7F8A96A9851396C9108
2019-12-05 13:44:15.624 UTC [main] main -> INFO 009 Exiting.....
===================== Chaincode Instantiation on PEER2 on channel 'mychannel' is successful =====================
6、初始化完成后,执行结束后进行一次查询与交互操作
Querying chaincode on org1/peer0...
===================== Querying on PEER0 on channel 'mychannel'... =====================
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
Attempting to Query PEER0 ...3 secs
2019-12-05 13:44:20.357 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:44:20.368 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:44:20.368 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2019-12-05 13:44:20.368 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2019-12-05 13:44:20.369 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A95070A6708031A0C08B493A4EF0510...6D7963631A0A0A0571756572790A0161
2019-12-05 13:44:20.369 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: F65FAAA5EAFC4F7AD889922767A5C5E22A1D746EEF9478C842CAD5D216A4FCC5
/**查询结果是100,在智能合约分析时会讲到*/
Query Result: 100
2019-12-05 13:45:54.440 UTC [main] main -> INFO 007 Exiting.....
===================== Query on PEER0 on channel 'mychannel' is successful =====================
/**执行一次交互操作*/
Sending invoke transaction on org1/peer0...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
2019-12-05 13:45:57.219 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:45:57.222 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:45:57.466 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2019-12-05 13:45:57.467 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2019-12-05 13:45:57.477 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A95070A6708031A0C089594A4EF0510...696E766F6B650A01610A01620A023130
2019-12-05 13:45:57.477 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: D53D985495786FBA903E99CE200DBDA97D610E831BE497EF9C7729F6A207E626
2019-12-05 13:45:57.838 UTC [msp/identity] Sign -> DEBU 007 Sign: plaintext: 0A95070A6708031A0C089594A4EF0510...19514344A25946749495D11A2F0E91C3
2019-12-05 13:45:57.838 UTC [msp/identity] Sign -> DEBU 008 Sign: digest: 5A68DB01F8C9D44967BCC8D09F7DEC99A4BB9BC939513C1FDD1AA33A567FA4A9
2019-12-05 13:45:57.946 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 009 ESCC invoke result: version:1 response: payload:"\n \317\343\377\0005\234u\247\261\276\3375\342\001\352\272\376\346\227\373\366\336\305\371a\206\204\024\\M\374I\022Y\nE\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\010\003\022-\n\004mycc\022%\n\007\n\001a\022\002\010\003\n\007\n\001b\022\002\010\003\032\007\n\001a\032\00290\032\010\n\001b\032\003210\032\003\010\310\001\"\013\022\004mycc\032\0031.0" endorsement:
2019-12-05 13:45:57.946 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00a Chaincode invoke successful. result: status:200
2019-12-05 13:45:57.946 UTC [main] main -> INFO 00b Exiting.....
===================== Invoke transaction on PEER0 on channel 'mychannel' is successful =====================
7、组织2的peer1上安装chaincode并且做一次查询操作过程跟以上相仿。
Installing chaincode on org2/peer3...
……
……
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
2019-12-05 13:45:58.151 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
……
……
2019-12-05 13:45:58.153 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default
response:
2019-12-05 13:46:02.830 UTC [main] main -> INFO 00e Exiting.....
===================== Chaincode is installed on remote peer PEER3 =====================
Querying chaincode on org2/peer3...
===================== Querying on PEER3 on channel 'mychannel'... =====================
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
Attempting to Query PEER3 ...3 secs
2019-12-05 13:46:06.057 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-05 13:46:06.059 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-05 13:46:06.059 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2019-12-05 13:46:06.059 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2019-12-05 13:46:06.060 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A94070A6608031A0B089E94A4EF0510...6D7963631A0A0A0571756572790A0161
2019-12-05 13:46:06.060 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: AC2491396F120F9321D130612AA7C5219FFAD64D359D4DD72ED4D47F0DC9BC26
Query Result: 90
2019-12-05 13:48:04.075 UTC [main] main -> INFO 007 Exiting.....
===================== Query on PEER3 on channel 'mychannel' is successful =====================
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
二、执行过程中生成的容器分析
1、执行docker ps -a命令,可以看到在这个过程中生成了哪些容器:
生成了10个容器:order节点、2个组织的4个peer节点 、cli客户端节点(远程连接4个peer节点并做一些链码安装和初始化的操作)、还有dev开头是3个链码(在刚刚的过程中所安装)。
2、输入docker images查看安装的镜像,下图所示就是三个链码,我们可以看到链码的名字是mycc
3、进入~/go/src/github.com/hyperledger/fabric-samples/first-network/scripts目录下,执行
less script.sh
在其中找到installChaincode()函数,就可找到mycc的安装路径:
4、根据上图,我们执行以下命令:
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
就找到了链码所在的位置,如图所示:
本篇到此结束,下一章我们会分析一下链码的源码以及script.sh的内容。
参考:学习Hyperledger Fabric实战联盟链