I am new to hyperledger fabric and I am currently studying it for one of my project. Project needs implementation of both endorsing peer as well as commiting peer. Till now I am able to run test network and add a new endorsing peer to running network. But I don't know how implement( in Java) commiting peer in hyperledger fabric network. Can somebody please help me with this?
committing peer is a peer that maintains the ledger and chaincode, and basically all peers are committing peers.
See the official documentation below
fabric/v2.2/Types of peers
Every peer node in a channel is a committing peer.
It receives blocks of generated transactions, which are subsequently validated before they are committed to the peer node’s copy of the ledger as an append operation.
In other words, peer, whether endorsing or not, plays the role of a committing peer.
If you want to use a specific peer as a committing peer, set it in the connection-profile configure of fabric-sdk.
(In this case peer used only as a committing peer, the peer has an endorsing function, but simply does not request endorsing.)
fabric-sdk/v2.2/sample/connection-profile endorsingPeer: false
...
82: peer3.magnetocorp.example.com:
83: endorsingPeer: false
84: chaincodeQuery: false
85: ledgerQuery: true
86: eventSource: true
...
[P.S] the peer type (committer, endorser) and role (leader, anchor) are different, so don't get confused.
Related
Here is the log of Hyperledger Fabric test network. There are 2 peer node(peer0.org1.example.com & peer0.org2.example.com) and 2 orderer node(orderer.example.com & orderer2.example.com).
My question is what 「writeBlock」,「StoreBlock」,「Validate」「commit」stage actually does? I know that at 「propose」stage, a chosen orderer(in this case, orderer.example.com) will create a block and then send the created block to other orderer such as orderer2.example.com. However, I don't understand what orderers does at「writeBlock」stage. Do they sign the created block at 「writeBlock」stage? Next, peer nodes received the block from who? orderer.example.com or orderer2.example.com? In my guess, I think it's from orderer.example.com but I'm not sure.
I don't understand what orderers does at「writeBlock」stage.
I'm not sure about those stages (writeBlock looks self-explanatory). I don't know about "StoreBlock", it isn't mentioned in the official docs. I'm wondering which Fabric version you are using.
Next, peer nodes received the block from who?
In a RAFT network you have a leader/follower model. You can think of a leader peer as an entry point/doorman for all communication coming from the ordering nodes. An ordering node sends blocks to the leading peer(s) of each organization; the leading peer is then responsible for distributing those blocks to other peers belonging to the same organization. Distribution is done using gossip protocol.
Hyperledger Fabric is a complex system, with many components and a lot of moving parts.
The log that you are referring to is the log of the orderer node - orderer.example.com. It's a part of the Fabric test network. You can see what's happening in detail by looking at the logs of other Fabric components, such as peer node logs.
The Fabric network has a set of orderer nodes, which are responsible for ordering the transactions and creating blocks in the blockchain.
The orderer nodes are configured to use a consensus algorithm (such as Solo or Kafka) to achieve a consensus about the order of the transactions.
A Fabric network has a set of peer nodes, which are responsible for executing the chaincode (smart contracts) and catching and validating the transactions.
The Fabric test network consists of one orderer node, which is configured to use Solo consensus algorithm. This orderer node is orderer.example.com.
The Fabric test network consists of two peer nodes, which are peer0.org1.example.com and peer0.org2.example.com.
The log that you are referring to is the log of the orderer node - ord
My hyperledger fabric network consists of 1 orderer, 1 organization and 3 peers. I tampered ledger of first peer and then tried to do another transaction on the same peer, then the following error was thrown:
"Error: deliver completed with status (SERVICE_UNAVAILABLE) before txid received - proposal response: "
But the transaction was executed and also the block was added in tampered ledger of peer. But the tampered data was not restored to previous state.
With the reference of the answer in this link - "https://intellipaat.com/community/17752/in-hyperledger-fabric-blocks-locations-and-validity-criteria", I came to know that if the tampering is done, "the state database can be dropped and rebuilt from the blockchain". So this process of dropping and rebuilding the database is done automatically by peer or we need to do it manually?
In short, if tampering is done in ledger of peer, how can be the previous state of ledger restored?
If the state data is in doubt, you can stop peer, drop state database, and upon restart peer will rebuild state database. When peer is stopped, the command peer node rebuild-dbs will drop state database for you. See the command documentation.
If the blockchain ledger itself is in doubt, you will need to either replace the peer or reset the peer to genesis blocks using peer node reset command. See the command documentation.
What steps are required in order to add an endorsing peer to a blockchain network (in hyperledger-fabric)? What about promoting a committing peer in an endorsing one?
Should I just alter files crypto-config.yaml and configtx.yaml by adding the new peer?
I am using the fabcar example from the fabric-samples repo (https://github.com/hyperledger/fabric-samples), so should I change the docker-compose(-cli).yaml also? When starting the network with startFabric.sh script, should I just install chaincode on the new peers, or are other steps requires also?
I tried it with just installing a chaincode on the new peers, however I got an error stating that "... Consortium was not met when instantiating the chaincode ..."
Edit:
I was able to install the chaincode on all four peers and instantiate it on the channel. Initial non-query transaction is successful and another one after it. However, after the first two transactions I get:
Failed to submit transaction createInquiry: Error: Peer localhost:8051 has rejected transaction "e8a83c12bfbcae97c7a3f2baaad7735fe8b44195a0ce252a3533a7b4a2a8103b" with code "ENDORSEMENT_POLICY_FAILURE"
can you stop, remove and kill containers and try once again to instantiate.
I have query, i am reading the hyperledger fabric article, In article its mention that, User User1 sends a transaction Tx1 to Peer P1, Peer P1 endose E1, the transaction Tx1, the transaction received back to user1 and he pass it to order or1, And order will validate the Tx1 and create the block and it will commit.
My Question is :
1. when order is committing the block, why it will send to peer P1 back.
2. In article they mention Peer P1 is also validate Tx1, How Peer will
verify the Tx1.
3. If Peer P1 verify the Tx1, does Peer P1 also keep the record of all the Peers and Orderer details.
4. If Peer also can Validate the Tx1, best thing is to apply the
block/Batch creation mechanism to Peer directly, so no need of orderer. i have doubt please suggest me.
The application “broadcasts” the transaction proposal and response
within a “transaction message” to the ordering service. The
transaction will contain the read/write sets, the endorsing peers
signatures and the Channel ID. The ordering service does not need to
inspect the entire content of a transaction in order to perform its
operation, it simply receives transactions from all channels in the
network, orders them chronologically by channel, and creates blocks of
transactions per channel.
Read this doc: https://hyperledger-fabric.readthedocs.io/en/release-1.4/txflow.html
However, I will answer to your questions:
when order is committing the block, why it will send to peer P1 back.
A) Orderer will just receive pool of transactions and form blocks and ship to committing peers, it will not do any validation and it creates blocks so orderer also will have a copy of the ledger
In the article they mention Peer P1 is also validate Tx1, How Peer will
verify the Tx1.
A) If Peer1 is an endorsing peer then it will simulate the ledger by making the transaction commit and it will record the behavior it will send back to the user.
If Peer P1 verify the Tx1, does Peer P1 also keep the record of all the Peers and Orderer details.
A) By default all endorsing peers are commiting peers, so yes it will keep
If Peer also can Validate the Tx1, best thing is to apply the
block/Batch creation mechanism to Peer directly, so no need of orderer. i have doubt please suggest me.
A) Here if you come from ethereum background orderer is like a miner, here he will not do any calculations simply form batches and ship to peers like a postman job.
In the hyperledger fabric documentation, there are 2 terms used
1. Install the chaincode on peers and
2. Instantiate the chaincode on the channel
What are the major differences between these two?
In the documentation it said that a chaincode can be installed on multiple peers but can be instantiated once. I understood this point as a channel only needs the information about the channel.
I was following the balance-transfer example, so after channel creation, peers need to be joined to that channel.
There are 2 peers which joined the channel ["peer0.org1.example.com", "peer0.org1.example.com"], so when I am instantiating the chaincode it is creating 2 docker images of chaincode
dev-peer0.org1.example.com-chaincode-v0
dev-peer1.org1.example.com-chaincode-v0
What these 2 images really mean?
Isn't initializing the chaincode means for the channel?
Or channel initialize it on all the peers who joined it?
Where actually this initialization is happening?
Thanks!
Thanks to #PaulO'Mahony and #kajuken for the resources and explanation.
Following are the summary of my doubts:
A chaincode runs in a Docker container that is associated with any peer that needs to interact with it.
Chaincode is installed on a peer, then instantiated on a channel.
All members that want to submit transactions or read data by using a chaincode need to install the chaincode on their peer.
Instantiation will input the initial data used by the chaincode, and then start the chaincode containers on peers joined to the channel with the chaincode installed.
Note that only one network member needs to instantiate a chaincode. If a peer with a chaincode installed joins a channel where it has already been instantiated, the chaincode container will start automatically.
a chaincode is installed onto the file system of every peer that joins a channel, the chaincode must then be instantiated on the channel so that peers can interact with the ledger via the chaincode container. The instantiation performs any necessary initialization of the chaincode. This will often involve setting the key value pairs that comprise a chaincode's initial world state.
A peer can the install the chaincode once, and then use the same chaincode container on any channel where it has been instantiated.
References:
install and instantiate the chaincode
instantiate the chaincode
What these 2 images really mean?
Isn't initializing the chaincode means for the channel?
Yes and no. Every peer needs the same version of the chaincode installed on itself since everybody needs to be able to execute and verify incoming queries/invokes.
So there are 2 steps to do.
install the chaincode on every peer on the channel
instantiate the chaincode on the channel
Where actually this initialization is happening?
So the instantiating of chaincode is happening last after every peer has "knowledge" of the chaincode and it can be verified.