How to connect to another computer's channel in hyperledger fabric - hyperledger-fabric

How do I join members on a channel configured on another computer?
On one computer, I joined the channel through the consortium definition and authentication process.
I do not know how to access channel B of B computer from Peer of computer A. I would be grateful if you could give me specific instructions on how to access the channel from another computer.

Computer A: Once you create the channel, you have the genesis block. You need the genesis block to join the channel.
Computer B: When you have the genesis block, you should execute the following commands:
peer channel join -b mychannel.block
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile tlsca.example.com-cert.pem
In the channel configuration you should define both Peers

Related

Can I use `peer channel fetch config` with only orderer nodes, no peer nodes?

I've brought up an etcdraft based orderer cluster with 3 nodes and no peer nodes are deployed for now. And now I want to modify the orderer cluster like removing or adding members. Instructions I've found require firstly fetching the current config with the 'peer channel fetch config' command.
My question is how I can do to fetch the current system channel config with 'peer channel fetch config' command before/without any peer up and running, or is there any other way to achieve this.
fabric version: 1.4.4
You need to invoke it against an orderer since you also need to do this for the system channel, and peers don't have the system channel in them.
Use something like:
peer channel fetch config mychannel.block -c mychannel --orderer orderer.example.com:7050 --cafile ca.crt

How to define peer is endorsing peer or Anchor peer

I have doubt on creating the peer, where to configure, peer is endoser or Anchor.Lets say, After defining the peer of any-type,Is it possible to update peer type, from endoser to anchor viceversa.
Only peers with chaincode installed can act as endorser, in order to make a node endorser install the chaincode otherwise it'll be simple verify node.
for Anchor peers you need to provide in channel def.
example:
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile tlsca.example.com-cert.pem
Fabric provide three types of peer:
endorser , anchor and simple peer(verify).
endorser peer: peer on which chaincode is installed is called endorser peer.this peer is used to execute smart contract ad return result to client application. client app select that result which is return same from most endorsers.
Anchor peer: this peer is used when peer from one org need to communicate with other org.
for example:
org1 need to communicate with org2. now communication will be done between anchor peer of org1 and org2.
As you asked in comment peer can act as anchor or endorser peer at same time. Example : you can find it in byfn example. where peer0.org1.example.com is anchor as well as endorser.

Endorsement policy in Hyperledger Fabric

I am using Hyperledger Fabric version 1.2. I have created a channel with 1 orderer and 10 peer nodes, all belonging to the same organisation. I want to instantiate the chaincode with the endorsement policy such that all the peers of ORG1 are the endorsing peer, not just 1. What is the valid expression for the same?
Currently using the following policy:
docker exec -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n chainname -v 1.0 -c '{"Args":[""]}' -P "AND('Org1MSP.member')"
Fabric documentation contains examples of including peers from different organisations.
This can be achived while invoking the chaincode. You have to pass the peer addresses of all the peer nodes who you want to act as endorsing peers
peer chaincode invoke -o orderer0.abc.com:7050 -C abcchannel -n fabcar --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer1.org1.example.com:7051 -c '{"Args":["initLedger"]}'
Unfortunately! there no valid command for that, you can follow two steps if you want to achieve this:
Write your own custom endorsement logic by a plugin. This method is little cumbersome and you can follow this link if you want to do that. Pluggable endorsement and validation logic
Or, you can have an alternate solution by creating 10 Orgs with 1 peer each and define the endorsement policy through the command that you want as:
-P "OutOf(10, 'Org1.peer', 'Org2.peer', ...., 'Org10.peer')"
But, having all the peers as an endorsing peer is never a good idea as if a peer goes down, you will have to face serious problems as no transaction will be committed

hyperledger:Error: code = Unavailable desc = grpc: the connection is unavailable Usage: peer channel create [flags]

root#bq4_node1:/opt/fabric/bin# $FABRIC_ROOT/bin/peer channel create -o orderer.local:7050 -f $FABRIC_CFG_PATH/channel-artifacts/channel.tx -c mychannel -t 30 --tls true --cafile $ordererCa
Error: Error connecting due to rpc error: code = Unavailable desc = grpc: the connection is unavailable
Usage:
peer channel create [flags]
Although, not very clear what exactly you are trying to do, I would guess it's somehow related to the channel creation and joining a new peer to that channel.
First of all please take a look on Hyperledger Fabric documentation and tutorial on Writing Your First Application. There is also "Building Your First Network", also make sure you have followed Prerequisites.
You need to start with creating crypto material for your network entities: peer and ordering service, you can leverage cryptogen tool to receive root CA keys and signed certificates for peers and users. Here is the example of crypto-config.yaml, which will allow to generate orderer organization related crypto material as well as for two peers organizations:
# ---------------------------------------------------------------------------
# "OrdererOrgs" - Definition of organizations managing orderer nodes
# ---------------------------------------------------------------------------
OrdererOrgs:
Specs:
- Hostname: orderer
# ---------------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# ---------------------------------------------------------------------------
PeerOrgs:
- Name: Org1
Domain: org1.example.com
Template:
Count: 2
Users:
Count: 1
# ---------------------------------------------------------------------------
# Org2: See "Org1" for full specification
# ---------------------------------------------------------------------------
- Name: Org2
Domain: org2.example.com
Template:
Count: 2
Users:
Count: 1
You can use cryptogen to generate results:
cryptogen generate --config=crypto-config.yaml --output=.
Next, you can use configtxgen to create configuration transaction which will allow to produce genesis block and create the channel, here an additional example. Command line command:
Generate genesis block for ordering service:
FABRIC_CFG_PATH=. configtxgen -profile TwoOrgsOrdererGenesis -outputBlock genesis.block
Generate config transaction to create new channel:
FABRIC_CFG_PATH=. configtxgen -profile TwoOrgsChannel -channelID mychannel -outputCreateChannelTx=mychannel.tx
Finally you can use peer cli command to create a new channel as you have tried in your question:
peer channel create -o orderer.local:7050 -f mychannel.tx -c mychannel -t 30 --tls true --cafile $ordererCa
Also please make sure that orderer.local is the host name of the available ordering service and also environmental variables for endorsing peers correctly configured and peer is running.

Why peer chaincode instantiate execuate many times successfully

I could execute peer chaincode instantiate many times successfully, it should returns it exist, but no. why?
logs after instantiate command
logs the docker returns
steps:
from my github project chaincode-docker-devmode, I copy msp (peer and orderer use together) 、genesis.block、helloch.tx、docker-compose-with-couch.yaml and so on form other place,it should be ok. When I execute :
docker-compose -f docker-compose-with-couch.yaml up
peer、orderer、couchdb0、cli start and then cli execute script.sh
#script.sh content
peer channel create -c helloch -f helloch.tx -o orderer:7050
peer channel join -b helloch.block
then I simulate cli enviroment using terminal at chaincode-docker-devmode current path by following:
#cli simulation, $pwd is the chaincode-docker-devmode path
export CORE_VM_ENDPOINT=unix:///var/run/run/docker.sock
export CORE_LOGGING_LEVEL=DEBUG
export CORE_PEER_ID=cli
export CORE_PEER_ADDRESS=127.0.0.1:7051
export CORE_PEER_LOCALMSPID=DEFAULT
export CORE_PEER_MSPCONFIGPATH=$pwd/msp
bash
When I execute peer channel list It could shows I have join helloch
channel. Then I execute :
peer chaincode install -n hello -v 1.0 -l java -p chaincode/hsl-hsl-user-guide-examples-v14/mytest
peer chaincode instantiate -o 127.0.0.1:7050 -C helloch -n hello -v 1.0 -l java -c "{\"Args\":[\"init\",\"a\", \"100\", \"b\",\"100\"]}"
But I can instantiate many times and the log does not return error as same as above instantiate logs, actually it does not instantiate successfully, why?
Instantiate of the chaincode is essentially a transaction, therefore it has to be endorsed, ordered and committed to take effect. Now in your case peer cli instantiate command succeeds since the transaction proposal successfully endorsed and signed proposal submitted to the ordering service. While based on the following log output:
peer | 2017-09-05 01:09:23.650 UTC [ConnProducer] NewConnection -> ERRO 6da Failed connecting to 127.0.0.1:7050 , error: context deadline exceeded
peer | 2017-09-05 01:09:23.650 UTC [deliveryClient] connect -> ERRO 6db Failed obtaining connection: Could not connect to any of the endpoints: [127.0.0.1:7050]
Peer cannot get connected to the ordering service endpoint which in your case configured to be 127.0.0.1:7050, therefore eventually instantiate transaction is not committed. Therefore you do able to execute the instantiate command again, since no instantiate transaction record exists on the peer ledger from your previous attempt.
You need to change ordering service endpoint from 127.0.0.1:7050 to orderer:7050 and retry your experiment. This value configured inside configtx.yaml file, e.g.:
Orderer: &OrdererDefaults
# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: solo
Addresses:
- orderer:7050
In my case, this was giving me trouble because I did not give the instantiation process enough time before calling an invoke/query transaction.
Try adding a sleep command between your instantiate and invoke/query transaction:
peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$LANGUAGE" -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
# Sleeping to allow time for chaincode to instantiate on peers
sleep 30
peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[""]}'
This only applies in the case that you are running a "startup" script in a CLI container of some sort. In my case, I have script.sh which runs when I first bring the network up.
You can instantiate a chaincode with same name only once.
peer channel create -c helloch -f helloch.tx -o 127.0.0.1:7050
after above, you could see the helloch.block detail message by command
configtxgen --inspectBlock helloch.block
It shows
"OrdererAddresses": {
"Version": "0",
"ModPolicy": "/Channel/Orderer/Admins",
"Value": {
"addresses": [
"127.0.0.1:7050"
]
}
},
it seems that the connected orderer address which in helloch.block(channel configuration) comes from genesis.block (which generate from configtx.yaml )

Resources