Skip to content

Instantly share code, notes, and snippets.

@mbwhite
Last active June 25, 2020 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbwhite/e98cb76626bd870be6315871e4c97a67 to your computer and use it in GitHub Desktop.
Save mbwhite/e98cb76626bd870be6315871e4c97a67 to your computer and use it in GitHub Desktop.
Fabric Chaincode Lifecycle

Chaincode Package

The starting point of deploying a brand new chaincode starts with the chaincode package.

Irrespective of what language or api you have used to write your contract or chaincode, from the peer's perspective when deploying it can be considered a BLOB (Binary Object). Therefore the package is made up of your code (treated as a BLOB) and some metadata.

This metadata is a JSON file with

  • Code Path : for when the BLOG is unpacked where in the resulting directory tree the code is
  • Type : to indicate what type of builder is needed
  • Label : a user specified identifier

All that is bundled up into a .tar.gz file. This can be used by your organization or other organizations. This needs to be installed on all the peers that will be expected to endorse transactions for the chaincode.

From the Fabric CLI, the chaincode package can be installed with

....

The PackageID is important as that is a unique identifier of this package; with the prefix of the user specified label.

Chaincode Definition

When deploying chaincodes, it important to understand the concept of the 'Chaincode Definition'. This is a logical entity that is created; in effect the data structure that is used within Fabric to manage the chaincodes.

The definition will be comprised of

  • Name : the name the chaincode will be referred to on the CLI and by client applications
  • Version : A free-form field that the you can use to indentify different versions of the chaincode. Fabric does NOT imply any implicity version checks, eg semver, on this field.
  • Sequence : If a chaincode definition is modified, then this field must be incremented by 1
  • Endorsement Policy: Endorsement policy of the chaincode
  • Collection Configuartion: Specification of the location of the private data collections
  • initialization: is the initialization function to be called
  • ESCC/VSCC: Custom endorsement or validation plugins to be used.

Within each channel the set of chaincode definitions are indexed by their name. Therefore within a channel the name has to be unique. Each time the chaincode definition is updated, then the sequence number has updated by 1 as well. In effect you are creating an ordered list of chaincode definitions.

Approving a Chaincode Definition

So far there you won't have seen an obvious link between the Chaincode Definition and the Chaincode Package. The "Approval" of a definition is the imporant connection. The 'approval' links a chaincode definition and a package id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment