fabric源码调试三:fabric 2.1 去共识

前言:
(1)网络:一个orderer,两个组织,每个组织一个peer
(2)将orderer脱离容器启动;

1、将下面文件中的ip(192.168.5.83)改成自己的

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network/docker$ vim docker-compose-test-net.yaml 

2、go module是off状态(auto也行)(go env -w GO111MODULE=off)

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network/docker$ go version
go version go1.14.9 linux/amd64
wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network/docker$ go env
GO111MODULE="off"

3、清理环境

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ rm -rf ../orderer/*
wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network/docker$ ./network.sh down

4、启动网络

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network/docker$ ./network.sh up

日志如下:

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ ./network.sh up
Starting nodes with CLI timeout of '2' tries and CLI delay of '0' seconds and using database 'leveldb' with crypto from 'cryptogen'

LOCAL_VERSION=2.2.0
DOCKER_IMAGE_VERSION=2.1.0
=================== WARNING ===================
  Local fabric binaries and docker images are  
  out of  sync. This may cause problems.       
===============================================
/home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/../bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################

##########################################################
############ Create Org1 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
+ set +x
##########################################################
############ Create Org2 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
+ set +x
##########################################################
############ Create Orderer Org Identities ###############
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
+ set +x

Generate CCP files for Org1 and Org2
/home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/../bin/configtxgen
#########  Generating Orderer Genesis block ##############
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2020-09-18 09:46:49.894 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-09-18 09:46:49.931 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: kafka
2020-09-18 09:46:49.931 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.Kafka unset, setting to [127.0.0.1:9092]
2020-09-18 09:46:49.931 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/configtx/configtx.yaml
2020-09-18 09:46:49.934 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2020-09-18 09:46:49.935 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
+ set +x
Creating network "net_test" with the default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_cli" with default driver
Creating peer0.org2.example.com
Creating peer0.org1.example.com
Creating cli
CONTAINER ID        IMAGE                             COMMAND             CREATED             STATUS                  PORTS                              NAMES
bbf01dd58750        hyperledger/fabric-tools:latest   "/bin/sh"           1 second ago        Up Less than a second                                      cli
6546490a6425        hyperledger/fabric-peer:latest    "peer node start"   3 seconds ago       Up 1 second             0.0.0.0:7051->7051/tcp             peer0.org1.example.com
34ddb9864eda        hyperledger/fabric-peer:latest    "peer node start"   3 seconds ago       Up 1 second             7051/tcp, 0.0.0.0:9051->9051/tcp   peer0.org2.example.com

5、启动orderer,orderer是脱离容器启动
在这里插入图片描述
日志:
在这里插入图片描述

6、待orderer启动完毕开始停滞等待交易时,发送交易

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ ./network.sh createChannel

日志如下:

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ ./network.sh createChannel
Creating channel 'mychannel'.

If network is not up, starting nodes with CLI timeout of '2' tries and CLI delay of '0' seconds and using database 'leveldb 

### Generating channel create transaction 'mychannel.tx' ###
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel
2020-09-18 09:50:06.560 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-09-18 09:50:06.595 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/configtx/configtx.yaml
2020-09-18 09:50:06.596 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2020-09-18 09:50:06.603 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
+ res=0
+ set +x

### Generating anchor peer update transactions ###
#######    Generating anchor peer update transaction for Org1MSP  ##########
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2020-09-18 09:50:06.656 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-09-18 09:50:06.697 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/configtx/configtx.yaml
2020-09-18 09:50:06.697 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
2020-09-18 09:50:06.699 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update
+ res=0
+ set +x

#######    Generating anchor peer update transaction for Org2MSP  ##########
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2020-09-18 09:50:06.766 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-09-18 09:50:06.799 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/configtx/configtx.yaml
2020-09-18 09:50:06.799 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
2020-09-18 09:50:06.802 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update
+ res=0
+ set +x

Creating channel mychannel
Using organization 1
+ peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-09-18 09:50:06.916 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-09-18 09:50:07.068 CST [cli.common] readBlock -> INFO 002 Expect block, but got status: &{NOT_FOUND}
2020-09-18 09:50:07.080 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2020-09-18 09:50:07.299 CST [cli.common] readBlock -> INFO 004 Received block: 0

===================== Channel 'mychannel' created ===================== 

Join Org1 peers to the channel...
Using organization 1
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
+ set +x
2020-09-18 09:50:07.494 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-09-18 09:50:07.612 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel

Join Org2 peers to the channel...
Using organization 2
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
+ set +x
2020-09-18 09:50:07.808 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-09-18 09:50:07.888 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel

Updating anchor peers for org1...
Using organization 1
+ peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-09-18 09:50:08.043 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-09-18 09:50:08.165 CST [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' ===================== 

Updating anchor peers for org2...
Using organization 2
+ peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-09-18 09:50:08.375 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-09-18 09:50:08.548 CST [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' ===================== 


========= Channel successfully joined =========== 

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ 

goland端日志:
在这里插入图片描述

7、部署链码以及之后所有步骤

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ ./network.sh deployCC

日志:

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ ./network.sh deployCC
deploying chaincode on channel 'mychannel'

Vendoring Go dependencies ...
~/go/src/github.com/hyperledger/fabric/work_dir/chaincode/fabcar/go ~/go/src/github.com/hyperledger/fabric/work_dir/test-network
~/go/src/github.com/hyperledger/fabric/work_dir/test-network
Finished vendoring Go dependencies
Using organization 1
++ peer lifecycle chaincode package fabcar.tar.gz --path ../chaincode/fabcar/go/ --lang golang --label fabcar_1
++ res=0
++ set +x
===================== Chaincode is packaged on peer0.org1 ===================== 

Installing chaincode on peer0.org1...
Using organization 1
++ peer lifecycle chaincode install fabcar.tar.gz
++ res=0
++ set +x
2020-09-18 09:52:08.640 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nIfabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506\022\010fabcar_1" > 
2020-09-18 09:52:08.640 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506
===================== Chaincode is installed on peer0.org1 ===================== 

Install chaincode on peer0.org2...
Using organization 2
++ peer lifecycle chaincode install fabcar.tar.gz
++ res=0
++ set +x
2020-09-18 09:52:34.763 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nIfabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506\022\010fabcar_1" > 
2020-09-18 09:52:34.763 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506
===================== Chaincode is installed on peer0.org2 ===================== 

Using organization 1
++ peer lifecycle chaincode queryinstalled
++ res=0
++ set +x
Installed chaincodes on peer:
Package ID: fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506, Label: fabcar_1
===================== Query installed successful on peer0.org1 on channel ===================== 

Using organization 1
++ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name fabcar --version 1 --init-required --package-id fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506 --sequence 1
++ set +x
2020-09-18 09:52:37.127 CST [chaincodeCmd] ClientWait -> INFO 001 txid [52c0de67fca3938fed2cb178dd3971334507edd60823de8ddddddbcb7582a74c] committed with status (VALID) at 
===================== Chaincode definition approved on peer0.org1 on channel 'mychannel' ===================== 

Using organization 1
===================== Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 0 seconds.
++ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1 --sequence 1 --output json --init-required
++ res=0
++ set +x
{
    
    
	"approvals": {
    
    
		"Org1MSP": true,
		"Org2MSP": false
	}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel' ===================== 
Using organization 2
===================== Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'... ===================== 
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 0 seconds.
++ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1 --sequence 1 --output json --init-required
++ res=0
++ set +x
{
    
    
	"approvals": {
    
    
		"Org1MSP": true,
		"Org2MSP": false
	}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel' ===================== 
Using organization 2
++ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name fabcar --version 1 --init-required --package-id fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506 --sequence 1
++ set +x
2020-09-18 09:52:39.680 CST [chaincodeCmd] ClientWait -> INFO 001 txid [5e5f88b48058687e5b55f286da2559105d96937f27ed4308b575fbb7deeb006e] committed with status (VALID) at 
===================== Chaincode definition approved on peer0.org2 on channel 'mychannel' ===================== 

Using organization 1
===================== Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 0 seconds.
++ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1 --sequence 1 --output json --init-required
++ res=0
++ set +x
{
    
    
	"approvals": {
    
    
		"Org1MSP": true,
		"Org2MSP": true
	}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel' ===================== 
Using organization 2
===================== Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'... ===================== 
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 0 seconds.
++ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1 --sequence 1 --output json --init-required
++ res=0
++ set +x
{
    
    
	"approvals": {
    
    
		"Org1MSP": true,
		"Org2MSP": true
	}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel' ===================== 
Using organization 1
Using organization 2
++ peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name fabcar --peerAddresses localhost:7051 --tlsRootCertFiles /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --version 1 --sequence 1 --init-required
++ res=0
++ set +x
2020-09-18 09:52:42.704 CST [chaincodeCmd] ClientWait -> INFO 001 txid [01c0086481634194069882aea3c8e5e6d3e472488bce543e5ceb96fa12b4225c] committed with status (VALID) at localhost:7051
2020-09-18 09:52:42.736 CST [chaincodeCmd] ClientWait -> INFO 002 txid [01c0086481634194069882aea3c8e5e6d3e472488bce543e5ceb96fa12b4225c] committed with status (VALID) at localhost:9051
===================== Chaincode definition committed on channel 'mychannel' ===================== 

Using organization 1
===================== Querying chaincode definition on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query committed status on peer0.org1, Retry after 0 seconds.
++ peer lifecycle chaincode querycommitted --channelID mychannel --name fabcar
++ res=0
++ set +x

Committed chaincode definition for chaincode 'fabcar' on channel 'mychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
===================== Query chaincode definition successful on peer0.org1 on channel 'mychannel' ===================== 

Using organization 2
===================== Querying chaincode definition on peer0.org2 on channel 'mychannel'... ===================== 
Attempting to Query committed status on peer0.org2, Retry after 0 seconds.
++ peer lifecycle chaincode querycommitted --channelID mychannel --name fabcar
++ res=0
++ set +x

Committed chaincode definition for chaincode 'fabcar' on channel 'mychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
===================== Query chaincode definition successful on peer0.org2 on channel 'mychannel' ===================== 

Using organization 1
Using organization 2
++ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n fabcar --peerAddresses localhost:7051 --tlsRootCertFiles /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles /home/wang/go/src/github.com/hyperledger/fabric/work_dir/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --isInit -c '{"function":"initLedger","Args":[]}'
++ res=0
++ set +x
2020-09-18 09:52:45.051 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' ===================== 

Querying chaincode on peer0.org1...
Using organization 1
===================== Querying on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query peer0.org1, Retry after 0 seconds.
++ peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'
++ res=0
++ set +x

[{
    
    "Key":"CAR0","Record":{
    
    "make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{
    
    "Key":"CAR1","Record":{
    
    "make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{
    
    "Key":"CAR2","Record":{
    
    "make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{
    
    "Key":"CAR3","Record":{
    
    "make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{
    
    "Key":"CAR4","Record":{
    
    "make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{
    
    "Key":"CAR5","Record":{
    
    "make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{
    
    "Key":"CAR6","Record":{
    
    "make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{
    
    "Key":"CAR7","Record":{
    
    "make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{
    
    "Key":"CAR8","Record":{
    
    "make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{
    
    "Key":"CAR9","Record":{
    
    "make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}]
===================== Query successful on peer0.org1 on channel 'mychannel' ===================== 

wang@wang:~/go/src/github.com/hyperledger/fabric/work_dir/test-network$ 

goland端orderer日志:
在这里插入图片描述
源码只能通过这种方式了,在这里

猜你喜欢

转载自blog.csdn.net/u010931295/article/details/108658511
2.1
今日推荐