hyperledger-fabric peer0 environment - hyperledger-fabric

I am very new to this subject and I have to go through a fabric-sample.
But at this point I have problem
Environment variables
# Environment variables for PEER0
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
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
But my docker-compose-base.yaml file has the following lines
environment:
- CORE_PEER_ID=peer0.org1.example.com
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
When I run this command
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
I have this error message
INFO 004 MSP configuration file not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp/config.yaml]: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp/config.yaml: no such file or directory]
I am sure this error message cased by the missing/different lines in my docker-compose-base.yaml
What could I do in this case?
Just put these lines in my file?
Or something has gone wrong at some point what I did not realize?
Please bear with me as I just have started.
Thank you
edit: I have this error message
Error: Got unexpected status: BAD_REQUEST
Usage:
peer channel create [flags]

That's not an error message, but an INFO one.
an MSP can be configured to have an OU by having that config file with the following fields in it:
OrganizationalUnitIdentifiers:
- Certificate: "cacerts/cacert.pem"
OrganizationalUnitIdentifier: "COP"
It's perfectly fine not to have this file and to see this INFO message.

Related

Restore Back up From Hyperledger Fabric v2.0

https://www.devprovider.com/how-to-take-backup-from-hyperledger-fabric/
https://www.devprovider.com/how-to-restore-hyperledger-fabric-from-backup/
I follow this 2 tutorials for back up and restore my Blockchain,I did everything the same except:
Make back up:
1:
cp –r crypto-config/ backup/
On my own its organizations folder:
test-network/organizations$ ls
ccp-generate.sh ccp-template.json ccp-template.yaml cryptogen fabric-ca ordererOrganizations peerOrganizations
And then:
./network down for restore on next steps
2:
I need to sudo cp instead of cp, cause else cant copy .key files, after that, i run chown too for set my profile as owner
Restore Back up:
1:
cd backup/ && cp -r * ../ && cd ../
Change it by sudo cp ... and do it on 2 steps(its same that creating back up)
2:
./byfn.sh up
I havent that script, but tutorial said:
Previously the network was started using ./byfn.sh up command. Use the same command
$ ./byfn.sh up
or if the network was started using a different script, use it. You’ll notice the peers will automatically join the channel created previously before the network is brought down. The ledger data will be restored and the number of blocks will resume from where the previous network left off.
So i use
./network.sh up createChannel -c mychannel -ca for create my channel
as i always did, it get me errors:
output:
Creating channel 'mychannel'.
If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb
Generating channel create transaction 'mychannel.tx'
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel
2021-03-30 09:53:34.546 CEST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-03-30 09:53:34.560 CEST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/luis/Escritorio/Bchain/asset-Prueba/test-network/configtx/configtx.yaml
2021-03-30 09:53:34.560 CEST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2021-03-30 09:53:34.562 CEST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
+ res=0
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/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=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/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=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/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=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/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=1
Error: failed to create deliver client for orderer: orderer client failed to connect to localhost:7050: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:7050: connect: connection refused"
edit 1:
As you said i think im doing all well, then, i can start network with ./network up, and do it correctly
output:
./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.2.1
DOCKER_IMAGE_VERSION=2.2.1
/home/luis/Escritorio/Bchain/asset-Prueba/test-network/../bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Creating Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Creating Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generating CCP files for Org1 and Org2
/home/luis/Escritorio/Bchain/asset-Prueba/test-network/../bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2021-03-31 08:50:54.035 CEST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-03-31 08:50:54.047 CEST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2021-03-31 08:50:54.047 CEST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
2021-03-31 08:50:54.047 CEST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/luis/Escritorio/Bchain/asset-Prueba/test-network/configtx/configtx.yaml
2021-03-31 08:50:54.048 CEST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2021-03-31 08:50:54.049 CEST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
Creating network "net_test" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating orderer.example.com ... done
Creating peer0.org2.example.com ... done
Creating peer0.org1.example.com ... done
Creating cli ... done
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4ad5fed6957 hyperledger/fabric-ccenv:2.2 "/bin/sh -c '\nset -e…" 1 second ago Created epic_lichterman
64d6650eb7f1 hyperledger/fabric-ccenv:2.2 "/bin/sh -c '\nset -e…" 1 second ago Created kind_chaplygin
c9fe6c8f20f4 hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli
1f20728228a3 hyperledger/fabric-peer:latest "peer node start" 3 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com
7732b7cd55d7 hyperledger/fabric-orderer:latest "orderer" 3 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com
4a2c0207f3d2 hyperledger/fabric-peer:latest "peer node start" 3 seconds ago Up Less than a second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
Then, i should can invoke orderer,not?
But when i try:
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":"getAllAssets","Args":[]}'
output:
Error: error endorsing invoke: rpc error: code = Unknown desc = error validating proposal: access denied: channel [mychannel] creator org [Org1MSP] - proposal response: <nil>
Then orderer go down
Thanks for support
any ideas?
edit 2:
more info:
docker ps -a
...
32ba6c3ff55d hyperledger/fabric-orderer:latest "orderer" About a minute ago Exited (2) 28 seconds ago orderer.example.com
My orderer go down 1 min after i get up it
according to your describe,in the tourial ,fabric version is v1.4.X,and the fabric you now use is v2.x.x,so in v1.4.x the test script is byfn.sh and in v2.x.x the test script is network.sh,these two scripts are different.
if you want to backup a fabric network and restore,you need just backup crypto-config(organizations in v2.x.x),ledger data which obtain from /var/hyperledger/fabric of docker container,and start your orderer and peer container ,you need not create channel or join channel ,you can query and invoke chaincode.
I have answer another question about restore fabric network,you can reference it In Hyperledger Fabric, is there a way to reuse the data of previous network?
--------------new answer-------------------------------
if you exec you peer chaincode invoke command in terminal,you should add this env,and you can invoke success.
## ebable tls
export CORE_PEER_TLS_ENABLED=true
#MSP ID
export CORE_PEER_LOCALMSPID="Org1MSP"
#ca.crt of peer0.org1.example.com , you should change it to absolute path
export CORE_PEER_TLS_ROOTCERT_FILE=crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
#msp of peer0.org1.example.com,you should change it to absolute path
export CORE_PEER_MSPCONFIGPATH=crypto-config/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp
#peer address,
export CORE_PEER_ADDRESS=localhost:7051

Hyperledger Fabric: "err: bad proposal response 500: access denied" when trying to join peer to channel

Built a network, added orderers to the channel here referenced as: channelname
The following folders are mounted on the container
# docker-compose.yaml
volumes:
- "~/container-volumes/$docker_peer0/production:/var/hyperledger/production"
- "~/organizations/peerOrganizations/$company/peers/$docker_peer0/msp:/etc/hyperledger/fabric/msp"
- "~/organizations/peerOrganizations/$company/peers/$docker_peer0/tls:/etc/hyperledger/fabric/tls"
Trying to join a peer to a channel, but gives bad proposal response 500: access denied.
Build the channel configuration block with the following command:
./configtxgen -profile SampleAppChannelEtcdRaft -outputBlock genesis_block.pb -channelID channelname
Next joined the orderers to the channel using the following command with an identity enrolled with role admin
./osnadmin channel join --channel-id channelname --config-block ~/Downloads/bin/genesis_block.pb -o localhost:9440 --ca-file $OSN_TLS_CA_ROOT_CERT --client-cert $ADMIN_TLS_SIGN_CERT --client-key $ADMIN_TLS_PRIVATE_KEY
Next I copy the generated genesis_block.pb to a mounted folder on the container so it is reachable for the following command which we use to join the peer to the channel:
docker exec -it peer0 peer channel join -b /var/hyperledger/production/genesis_block.pb -o vm01:9440 --clientauth --cafile /etc/hyperledger/fabric/msp/tls/tls-ca-cert.pem --certfile /etc/hyperledger/fabric/msp/user/peer-admin/tls/cert.pem --keyfile /etc/hyperledger/fabric/msp/user/peer-admin/tls/key.pem
This results in the following error
[channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Error: proposal failed (err: bad proposal response 500: access denied for [JoinChain][channelname]: [Failed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy [Admins]: [The identity is not an admin under this MSP [org1msp]: The identity does not contain OU [ADMIN], MSP: [org1msp]]])
The admin used for this command is peer-admin that was enrolled with the TLS-CA and the organizational CA. Also the config.yaml for OU's is present in peer-admin msp.
I also tried to set the CORE_PEER_MSPCONFIGPATH to the msp dir of peer-admin (peer0/msp/user/peer-admin/msp), but this results on a hard exit of the container on startup. fabric-chaincode-500-access-errors
I can't seem to figure out where it goes wrong, has it something to do with the --cafile, --certfile or --keyfile that you have to set within the peer channel join command or something else?
Edit:
This is the config file.
$docker_peer1_service_name:
image: hyperledger/fabric-peer:2.3
container_name: $docker_peer1_container_name
environment:
- FABRIC_CFG_PATH=/etc/hyperledger/fabric
- CORE_PEER_ID=$docker_peer1
- CORE_PEER_NETWORKID=test
- CORE_PEER_LISTENADDRESS=0.0.0.0:7081
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7082
- CORE_PEER_CHAINCODEADDRESS=localhost:7082
- CORE_PEER_ADDRESS=localhost:7081
- CORE_PEER_MSPCONFIGPATH=msp
- CORE_PEER_LOCALMSPID=$company
- CORE_PEER_FILESYSTEMPATH=/var/hyperledger/production
- CORE_PEER_GOSSIP_BOOTSTRAP=127.0.0.1:7091
- CORE_PEER_GOSSIP_ENDPOINT=localhost:7081
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=localhost:7081
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CLIENTAUTHREQUIRED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/cert.pem
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/key.pem
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/tls-ca-cert.pem
- CORE_PEER_TLS_CLIENTROOTCAS_FILES=tls/tls-ca-cert.pem
- CORE_PEER_TLS_CLIENTCERT_FILE=/etc/hyperledger/fabric/tls/cert.pem
- CORE_PEER_TLS_CLIENTKEY_FILE=/etc/hyperledger/fabric/tls/key.pem
- CORE_PEER_LEDGER_STATE_STATEDATABASE=CouchDB
- CORE_PEER_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=peer1-couchdb:5985
- CORE_PEER_LEDGER_STATE_COUCHDBCONFIG_USERNAME=$docker_peer1_couchdb_username
- CORE_PEER_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=$docker_peer1_couchdb_pass
- CORE_PEER_LEDGER_SNAPSHOTS=var/hyperledger/production/snapshots
#- CORE_PEER_OPERATIONS_LISTENADDRESS=127.0.0.1:9443
#- CORE_PEER_OPERATIONS_TLS_ENABLED=true
#- CORE_PEER_OPERATIONS_TLS_CERT_FILE=
#- CORE_PEER_OPERATIONS_TLS_KEY_FILE=
#- CORE_PEER_OPERATIONS_TLS_CLIENTAUTHREQUIRED=true
- CORE_PEER_METRICS_PROVIDER=disabled
#- CORE_PEER_METRICS_STATSD_ADDRESS=127.0.0.1:8125
#- FABRIC_CA_SERVER_OPERATIONS_LISTENADDRESS=127.0.0.1:9444
ports:
- "7081:7081"
- "7082:7082"
- "7091:7091"
volumes:
- "~/container-volumes/$docker_peer1/production:/var/hyperledger/production"
- "~/organizations/peerOrganizations/$company/peers/$docker_peer1/msp:/etc/hyperledger/fabric/msp"
- "~/organizations/peerOrganizations/$company/peers/$docker_peer1/tls:/etc/hyperledger/fabric/tls"
I believe you will need to set the MSPID to use when you are running the peer channel join ... command.
Try setting CORE_PEER_LOCALMSPID to org1msp

How to nicely format ("pretty print") Fabric chaincode query output?

I'm trying to generate a nicely formatted view of a specific ledger entry (or range of entries) with all related values.
When I run a chaincode query, I get an output like the following:
user#server:~/fabric-samples/test-network$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA -C mychannel -n myFirstChaincode --peerAddresses localhost:7051 --tlsRootCertFiles $PEER1_TLS -c '{"function":"queryOrder","Args":["004"]}'
2020-11-08 16:01:05.166 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 payload:"{\"actualDimensions\":{\"DIM1\":{},\"DIM2\":{},\"DIM3\":{},\"DIM4\":{}},\"customer\":\"GM\",\"dueDate\":\"tomorrow\",\"manufacturer\":\"undefined\",\"manufacturingData\":{},\"numOfDims\":\"5\",\"orderStatus\":\"new\",\"partID\":\"004\",\"partName\":\"Test Part\",\"requiredDimensions\":{\"DIM1\":{},\"DIM2\":{},\"DIM3\":{},\"DIM4\":{}}}"
This output looks like a long JSON string that has newlines replaced with \.
I'm looking for a human readable output. While I can read this above entry, the associated data structure is very simple. If I query another entry with several nested objects, it quickly becomes too messy to easily read.
I've tried adding something like JSON.stringify(value,null,4) to the chaincode query function, but that doesn't help:
2020-11-07 23:40:41.964 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 payload:"{\n \"actualDimensions\": {\n \"DIM1\": {},\n \"DIM2\": {},\n \"DIM3\": {},\n \"DIM4\": {}\n },\n \"customer\": \"GM\",\n \"dueDate\": \"tomorrow\",\n \"manufacturer\": \"undefined\",\n \"manufacturingData\": {},\n \"numOfDims\": \"5\",\n \"orderStatus\": \"new\",\n \"partID\": \"004\",\n \"partName\": \"Test Part\",\n \"requiredDimensions\": {\n \"DIM1\": {},\n \"DIM2\": {},\n \"DIM3\": {},\n \"DIM4\": {}\n }\n}"
It seems that the peer command may be formatting the output after JSON.stringify...
This page suggests that you can modify the logging format used for the peer command with an environmental variable, though I didn't find any examples or details of this beyond that one webpage.
When I tried adding an environmental variable to my cli:
export FABRIC_LOGGING_FORMAT=json, it didn't much help (it added more '/' instead of newlines):
student#hlfmc:~/fabric-samples/test-network$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles $PEER1_TLS --peerAddresses localhost:9051 --tlsRootCertFiles $PEER2_TLS -c '{"function":"GetAllAssets","Args":[]}'
{"level":"info","ts":1605042675.2069416,"name":"chaincodeCmd","caller":"chaincode/common.go:160","msg":"Chaincode invoke successful. result: status:200 payload:\"[{\\\"Key\\\":\\\"asset1\\\",\\\"Record\\\":{\\\"ID\\\":\\\"asset1\\\",\\\"Color\\\":\\\"blue\\\",\\\"Size\\\":5,\\\"Owner\\\":\\\"Tomoko\\\",\\\"AppraisedValue\\\":300,\\\"docType\\\":\\\"asset\\\"}},{\\\"Key\\\":\\\"asset2\\\",\\\"Record\\\":{\\\"ID\\\":\\\"asset2\\\",\\\"Color\\\":\\\"red\\\",\\\"Size\\\":5,\\\"Owner\\\":\\\"Brad\\\",\\\"AppraisedValue\\\":400,\\\"docType\\\":\\\"asset\\\"}},{\\\"Key\\\":\\\"asset3\\\",\\\"Record\\\":{\\\"ID\\\":\\\"asset3\\\",\\\"Color\\\":\\\"green\\\",\\\"Size\\\":10,\\\"Owner\\\":\\\"Jin Soo\\\",\\\"AppraisedValue\\\":500,\\\"docType\\\":\\\"asset\\\"}},{\\\"Key\\\":\\\"asset4\\\",\\\"Record\\\":{\\\"ID\\\":\\\"asset4\\\",\\\"Color\\\":\\\"yellow\\\",\\\"Size\\\":10,\\\"Owner\\\":\\\"Max\\\",\\\"AppraisedValue\\\":600,\\\"docType\\\":\\\"asset\\\"}},{\\\"Key\\\":\\\"asset5\\\",\\\"Record\\\":{\\\"ID\\\":\\\"asset5\\\",\\\"Color\\\":\\\"black\\\",\\\"Size\\\":15,\\\"Owner\\\":\\\"Adriana\\\",\\\"AppraisedValue\\\":700,\\\"docType\\\":\\\"asset\\\"}},{\\\"Key\\\":\\\"asset6\\\",\\\"Record\\\":{\\\"ID\\\":\\\"asset6\\\",\\\"Color\\\":\\\"white\\\",\\\"Size\\\":15,\\\"Owner\\\":\\\"Michel\\\",\\\"AppraisedValue\\\":800,\\\"docType\\\":\\\"asset\\\"}}]\" "}
(The above test was run on a separate server using the stock "asset-transfer-basic" sample chaincode.)
Note: I also tried updating the fabric-samples/config/core.yaml file with "format: json" and then re-running the chaincode (after properly bringing everything down and freshly starting the network). This gave the same output as before (no change from original output). I also tried editing the peer docker container's internal core.yaml file at /etc/hyperledger/fabric/core.yaml, which also did not appear to affect the output.
I've also tried calling the chaincode from an application (as opposed to directly from the CLI). The resulting output string no longer has '/' (but still no newlines/indentation):
user#server$ node query2.js
Wallet path: /home/user/Project/application/wallet
Transaction has been evaluated, result is: {"actualDimensions":{"DIM1":{},"DIM2":{},"DIM3":{},"DIM4":{}},"customer":"GM","dueDate":"tomorrow","manufacturer":"undefined","manufacturingData":{},"numOfDims":"5","orderStatus":"new","partID":"004","partName":"Test Part","requiredDimensions":{"DIM1":{},"DIM2":{},"DIM3":{},"DIM4":{}}}
If I try to use JSON.stringify on the output string, I get the '/' again:
user#server$ node query2.js
Wallet path: /home/user/Project/application/wallet
Transaction has been evaluated, result is: "{\"actualDimensions\":{\"DIM1\":{},\"DIM2\":{},\"DIM3\":{},\"DIM4\":{}},\"customer\":\"GM\",\"dueDate\":\"tomorrow\",\"manufacturer\":\"undefined\",\"manufacturingData\":{},\"numOfDims\":\"5\",\"orderStatus\":\"new\",\"partID\":\"004\",\"partName\":\"Test Part\",\"requiredDimensions\":{\"DIM1\":{},\"DIM2\":{},\"DIM3\":{},\"DIM4\":{}}}"
Here's the application code: (line 48 is original; 46-47 is second version)
45 ¦ ¦ ¦ const result = await contract.evaluateTransaction('queryOrder','004');
46 ¦ ¦ ¦ const stringResult=result.toString();
47 ¦ ¦ ¦ console.log(`Transaction has been evaluated, result is: ${JSON.stringify(stringResult,null,4)}`);
48 ¦ ¦ ¦ //console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
I saw this post with a similar question, but it did not provide any solution for pretty formatting.
Are there any current solutions/suggestions for this?
I'd be happy with JSON formatting or anything else that has spacing/newlines and makes the current output more human-readable.
You can update core.yaml or you can use "FABRIC_LOGGING_FORMAT" in your docker compose file.
An example with core.yaml is given below:
# Logging section for the chaincode container
logging:
# Default level for all loggers within the chaincode container
level: info
# Override default level for the 'shim' logger
shim: warning
# Format for the chaincode container logs
format: json
You can find core.yaml into "fabric-samples/config" directory.
Link: https://github.com/hyperledger/fabric/blob/master/sampleconfig/core.yaml
If you download latest fabric samples, you can find sample core.yaml at "fabric-samples/config" directory.
An example with "FABRIC_LOGGING_FORMAT" in your docker compose file is given below:
You have to edit the environment of cli container with "- FABRIC_LOGGING_FORMAT=json"
cli:
container_name: cli
image: hyperledger/fabric-tools:$IMAGE_TAG
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- FABRIC_LOGGING_SPEC=DEBUG
- FABRIC_LOGGING_FORMAT=json
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- 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_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_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_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- orderer.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
networks:
- byfn

Hyperledger Fabric: TLS handshake failed with error tls

I have set up a network with raft ordering service (5 orderers), 2 orgs and one peer each, the TLS and client authentication are both enabled. I have created the channel and joined it successfully, but I am getting TLS handshake failed error when updating the anchor peer from cli to orderer, and I am not able to create a second channel for the same error. Besides this TLS error why I was able to create the first channel I am very confused, surely incorrect configs causing that.
CLI Commands:
export ORDERER_CA=crypto/ordererOrganizations/example.com/tlsca/ca-chain.pem
export CLIENT_KEY_FILE=crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/tls/client.key
export CLIENT_CERT_FILE=crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/tls/client.pem
*Worked: peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls --cafile $ORDERER_CA --clientauth --keyfile $CLIENT_KEY_FILE --certfile $CLIENT_CERT_FILE
*Worked: peer channel join -b muchannel.block
*FAILED: peer channel update -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/anchors_channel.tx --tls --cafile $ORDERER_CA --clientauth --keyfile $CLIENT_KEY_FILE --certfile $CLIENT_CERT_FILE
CLI yaml config:
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.pem
- CORE_PEER_TLS_KEY_FILE=crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=crypto/peerOrganizations/org1.example.com/tlsca/ca-chain.pem
- CORE_PEER_TLS_CLIENTAUTHREQUIRED=true
- CORE_PEER_TLS_CLIENTCERT_FILE=crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/tls/client.pem
- CORE_PEER_TLS_CLIENTKEY_FILE=crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/tls/client.key
Orderer yaml config:
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/server.pem
- ORDERER_GENERAL_TLS_ROOTCAS=[crypto/ordererOrganizations/example.com/tls/ca-chain.pem]
- ORDERER_GENERAL_TLS_CLIENTAUTHREQUIRED=true
- ORDERER_GENERAL_TLS_CLIENTROOTCAS=[crypto/ordererOrganizations/example.com/tlsca/ca-chain.pem,crypto/peerOrganizations/org1.example.com/tlsca/ca-chain.pem,crypto/peerOrganizations/org2.example.com/tlsca/ca-chain.pem]
Try running the command with following environment in your CLI container:
export CORE_PEER_ADDRESS=orderer.example.com:7050
export CORE_PEER_LOCALMSPID=OrdererMSP
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin#example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
export CHANNEL_NAME=mychannel
This is because issuing channel update transaction requires updating the channel configuration file, which according to your present policies, must be signed by an Orderer Organization admin.

Connection error when invoking a transaction on the peers

I am trying to execute a chaincode I have written with couchdb and java. I use the first-network example for creating the network and instantiate the code. The network is created and the chaincode got installed without any problem. Then I enter the container and execute the transactions. At first it worked fine but suddenly it started giving me this error and now I can’t find a solution. I don't know if it is related with couchdb connection or not.
Error: error getting endorser client for invoke: endorser client failed to
connect to peer0.org2.example.com:7051: failed to create new connection:
connection error: desc = "transport: error while dialing: dial tcp
172.24.0.9:7051: connect: connection refused"
The comand i use to invocke the chaincode is the next one.
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["createCustomer","c1","tom"]}'
UPDATE:
Many have asked if the chaincode was installed on peers, I can confirm it is.
#Egoes , it means your port is not open for the peers, check the snippet ports section, your peer docker file should look like this.
peer0.org1.example.com:
container_name: peer0.org1.example.com
image: hyperledger/fabric-peer
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer0.org1.example.com
- FABRIC_LOGGING_SPEC=info
- CORE_CHAINCODE_LOGGING_LEVEL=info
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
# # the following setting starts chaincode containers on the same
# # bridge network as the peers
# # https://docs.docker.com/compose/networking/
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
- CORE_LEDGER_STATE_STATEDATABASE=CouchDB
- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
# The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
# provide the credentials for ledger to connect to CouchDB. The username and password must
# match the username and password set for the associated CouchDB.
- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start
# command: peer node start --peer-chaincodedev=true
ports:
- 7051:7051
- 7053:7053

Resources