Chaincode Life Cycle

(Hyperledger Fabric v2.x) The chaincode life cycle describes the process of installing chaincode on peers and deploying it on a channel.

The chaincode life cycle is based on the capabilities of the Hyperledger Fabric v2.x platform, which allows for the decentralized governance of chaincodes. Multiple organizations can agree on chaincode parameters, including the chaincode endorsement policy, before a chaincode can interact with the ledger. These functions are implemented in the new quick deployment and advanced deployment options, as well as in the REST API. For more information about the new life cycle, see Fabric chaincode lifecycle in the Hyperledger Fabric v2.2.4 documentation.

Typically, to deploy an installed chaincode, you use quick deployment or advanced deployment in the console. The deployment process includes packaging and installing the chaincode as well as approving and committing the chaincode definition. You can also use the REST API to complete the approval and commitment operations separately.

Package and Install a Chaincode

When you install chaincode in Oracle Blockchain Platform, the chaincode is packaged, installed, and a package ID is generated automatically. The package ID is displayed on the Chaincodes tab of the console.

Approve a Chaincode Definition

Before a chaincode can be deployed to a channel, the chaincode definition must be approved by enough organizations to satisfy the LifecycleEndorsement policy of the channel. The default LifecycleEndorsement policy in Oracle Blockchain Platform lets any organization approve the chaincode definition (as opposed to a majority of organizations). The chaincode definition includes the following parameters, which must be the same for all organizations: Chaincode Name, Version, Sequence, Endorsement Policy, Private Data Collection, and Init-required. A chaincode definition can also include a Package ID, which does not have to be the same for all organizations.

After a chaincode definition is approved, one organization can collect endorsements from peers of the approving organizations and then commit the chaincode definition to the channel.

To approve a chaincode definition by using the REST API, see Approve a Chaincode Definition in a Channel.

In the console, when you use quick deployment or advanced deployment the approval and commitment steps are both attempted.

Commit a Chaincode Definition

To commit an approved chaincode definition by using the REST API, see Commit a Chaincode Definition in a Channel.

In the console, you can see chaincode definitions that are approved but not committed on the Deployed Chaincodes page for the channel. You can use the More Actions menu to commit the approved chaincode.

Chaincode Life Cycle Scenarios

Scenario Description
Join a channel

Typically in the console you do not approve a chaincode definition without then committing it. If you join a shared channel where a chaincode definition was committed by another organization, you will see the chaincode definition listed as committed but not approved on the Deployed Chaincodes page for the channel. You can use the More Actions menu to approve the chaincode definition and also to associate a package ID. You do not need to commit the package definition again.

Update an endorsement policy

You can update the endorsement policy in the chaincode definition without reinstalling the chaincode. On the Deployed Chaincodes page for the channel, use the More Actions menu to upgrade the chaincode definition. Expand Endorsement Policy and specify a new policy, then click Upgrade.

Approve a definition without installing

In a multiple organization scenario, to approve a chaincode definition without installing the chaincode package, do not specify a package ID. You endorse the definition of the chaincode that is committed to the channel, but the chaincode is not installed on peers in your organization. You will not be able to use the chaincode to endorse transactions or query the ledger.

Disagreement on definitions

In a multiple organization scenario, an organization that doesn't approve a chaincode definition or approves a different chaincode definition is not able to run the chaincode on their peers. If other organizations get enough endorsements to commit the definition to the channel, those organizations can use the chaincode. Transactions are still added to the ledger on the peers of all organizations.

If organizations do not agree on a chaincode definition and no organizations get enough endorsements to commit the definition to the channel, the definition cannot be committed and therefore the chaincode cannot run.

Multiple organizations install different packages

You can specify a different package ID when you approve a chaincode definition for a channel with multiple organizations. If the definition name and endorsement policy are the same, then channel members can install chaincode that is specific to their organization, but which reads and writes data to the same chaincode namespace.

Create multiple chaincodes from one package

Similarly, you can approve and commit the same chaincode package multiple times, specifying a different name for each definition. Multiple instances of the chaincode run on the channel. If you also specify a different endorsement policy for each definition, then each chaincode instance is subject to a different endorsement policy.