Shubham Chadokar
Shubham Chadokar

Reputation: 2773

What install and instantiation chaincode really mean in hyperledger fabric? and what are the differences between them?

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!

Upvotes: 5

Views: 1972

Answers (2)

Shubham Chadokar
Shubham Chadokar

Reputation: 2773

Thanks to @PaulO'Mahony and @kajuken for the resources and explanation.
Following are the summary of my doubts:

  1. A chaincode runs in a Docker container that is associated with any peer that needs to interact with it.
  2. 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.

  1. 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.

  1. 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

Upvotes: 5

kajuken
kajuken

Reputation: 307

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.

  1. install the chaincode on every peer on the channel
  2. 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.

Upvotes: 0

Related Questions