Chaincode Definition Approval

A chaincode is governed by a chaincode definition. When channel members approve the chaincode definition, the approval acts as a vote by an organization on the chaincode parameters it accepts. These approved organization definitions allow channel members to agree on a chaincode before it can be used on a channel. The chaincode definition includes the following parameters, which need to be consistent across organizations.

Parameters in the Chaincode Definition

Name

The name that applications will use when invoking a chaincode, e.g., mycc.

Version

A version associated with a given chaincode package. The version does not have a predefined format: any valid string is acceptable, e.g., v1.0, 1.0.0, version-1.0, etc.

Sequence

A sequential number of the chaincode definition. This value is an integer and is used to keep track of chaincode upgrades. For example, when you first install and approve a chaincode definition, the sequence number will be 1. Along with the next chaincode upgrade, the sequence number will be incremented to 2.

Endorsement policy

The endorsement policy defines a set of organizations required to execute and validate, or endorse, chaincode transactions.

Collection configuration

The path to the private data collection definition file associated with a chaincode. The private data concept will be discussed in detail in the Private Data Collections chapter.

ESCC/VSCC plugins

The name of a custom endorsement or validation plugin to be used by a chaincode. These plugins are not a subject for this course. More information on plugin implementation can be found in the official documentation.

Initialization

If a chaincode requires initialization (e.g., setting some initial state), the initialization function should be implemented in the chaincode, and the --init-required flag should be set during the chaincode definition approval. If --init-required is set, the chaincode will wait for an invocation marked with the --isInit flag and then start a normal transaction processing. All transactions submitted before the initialization will be rejected.

Package identifier

A package identifier is a required parameter for each organization that wants to use the chaincode. The package ID does not need to be the same for all organizations. An organization can approve a chaincode definition without installing a chaincode package or including the identifier in the definition. The package ID can be obtained by querying the packages installed on the peer.

peer lifecycle chaincode queryinstalled

Each channel member that wants to use a chaincode should approve a chaincode definition for their organization. This approval should be submitted by the organization’s administrator to the ordering service that will distribute it to all peers. After an approval transaction has been successfully submitted, an approved definition is stored in a private data collection available to all the peers of the organization. As a result, the chaincode definition can be approved once per organization, even if the organization has multiple peers. An example of the chaincode definition approval is provided below.

export CC_PACKAGE_ID=chaincode_1.0:69de748301770f6ef64b42aa6bb6cb291df20aa39542c3ef94008615704007f3
peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --channelID mychannel --name chaincode --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1

Last updated

Was this helpful?