Upgrading chaincode in Hyperledger Fabric¶
- Pre-requisites
- Modifying configuration file
- Run playbook for Fabric version 1.4.x
- Run playbook for Fabric version 2.2.x
- Run playbook for Fabric version 2.2.x with external chaincode
Pre-requisites¶
Hyperledger Fabric network deployed, network.yaml configuration file already set and chaincode is installed and instantiated or packaged, approved and committed in case of Fabric version 2.2.
Modifying configuration file¶
Refer this guide for details on editing the configuration file.
The network.yaml file should contain the specific network.organizations.services.peers.chaincodes[*].arguments, network.organizations.services.peers.chaincodes[*].version and network.organizations.services.peers.chaincodes[*].name variables which are used as arguments while upgrading the chaincode.
For reference, following snippet shows that section of network.yaml
name: orderer2
type: orderer
consensus: raft
grpc:
port: 7050
ordererAddress: orderer2.supplychain-net.org1proxy.hlf.blockchaincloudpoc-develop.com:443
- orderer:
..
..
country: CH
fabric_console: enabled # To deploy Fabric console for this organization
ca_data:
certificate: /path/manufacturer/server.crt
cloud_provider: aws # Options: aws, azure, gcp, digitalocean, minikube
aws:
access_key: "aws_access_key" # AWS Access key, only used when cloud_provider=aws
secret_key: "aws_secret_key" # AWS Secret key, only used when cloud_provider=aws
# Kubernetes cluster deployment variables. The config file path and name has to be provided in case
# the cluster has already been created.
k8s:
region: "cluster_region"
context: "cluster_context"
config_file: "cluster_config"
# Hashicorp Vault server address and root-token. Vault should be unsealed.
# Do not check-in root_token
vault:
url: "vault_addr"
root_token: "vault_root_token"
secret_path: "secretsv2"
# Git Repo details which will be used by GitOps/Flux.
# Do not check-in git_access_token
gitops:
git_protocol: "https" # Option for git over https or ssh
git_url: "https://github.com/<username>/bevel.git" # Gitops https or ssh url for flux value files
branch: "develop" # Git branch where release is being made
release_dir: "platforms/hyperledger-fabric/releases/dev" # Relative Path in the Git repo for flux sync per environment.
component_dir: "platforms/hyperledger-fabric/releases/k8sComponent" # Relative path where values files are stored.
chart_source: "platforms/hyperledger-fabric/charts" # Relative Path where the Helm charts are stored in Git repo
git_repo: "github.com/<username>/bevel.git" # Gitops git repository URL for git push (without https://)
username: "git_username" # Git Service user who has rights to check-in in all branches
password: "git_access_token" # Git Server user password/token (Optional for ssh; Required for https)
email: "git@email.com" # Email to use in git config
When the chaincode is an external service, network.organizations.services.peers.chaincodes[*].upgrade_chaincode variable must also be added to change the version. If only the sequence is modified, it isn't necessary to add this field.
The sequence must be incremented in each execution regardless of whether the version has been modified or not.
For reference, following snippet shows that section of network.yaml
subject: "O=Manufacturer,OU=Manufacturer,L=47.38/8.54/Zurich,C=CH"
external_url_suffix: org2proxy.blockchaincloudpoc.com
org_status: new
orderer_org: supplychain # Name of the organization that provides the ordering service
fabric_console: disabled # To deploy Fabric console for this organization
ca_data:
certificate: /home/bevel/build/manufacturer/server.crt
..
..
port: 7054
cli: enabled # Creates a peer cli pod depending upon the (enabled/disabled) tag.
configpath: /home/bevel/build/peer0-core.yaml # path to custom core.yaml
grpc:
port: 7051
events:
port: 7053
couchdb:
port: 5984
restserver: # This is for the rest-api server
targetPort: 20001
port: 20001
expressapi: # This is for the express api server
targetPort: 3000
port: 3000
chaincodes:
- name: "assettransfer" # This has to be replaced with the name of the chaincode
version: "1" # This has to be replaced with the version of the chaincode
sequence: "1" # Sequence of the chaincode, update this only for chaincode upgrade
external_chaincode: true
init_required: false
tls: true
upgrade_chaincode: false
buildpack_path: /home/fabric-samples/asset-transfer-basic/chaincode-external/sampleBuilder # The path where buildpacks are locally stored
image: ghcr.io/hyperledger/bevel-samples-example:1.0
arguments: '\"InitLedger\",\"\"' # Init Arguments to be passed which will mark chaincode as init-required
crypto_mount_path: /crypto # OPTIONAL | tls: true | Path where crypto shall be mounted for the chaincode server
- organization:
name: carrier
country: GB
state: London
location: London
subject: "O=Carrier,OU=Carrier,L=51.50/-0.13/London,C=GB"
Run playbook for Fabric version 1.4.x¶
The playbook chaincode-upgrade.yaml is used to upgrade chaincode to a new version in the existing fabric network with version 1.4.x. This can be done by using the following command
ansible-playbook platforms/hyperledger-fabric/configuration/chaincode-upgrade.yaml --extra-vars "@path-to-network.yaml"
Run playbook for Fabric version 2.2.x¶
The playbook chaincode-ops.yaml is used to upgrade chaincode to a new version in the existing fabric network with version 2.2.x. This can be done by using the following command
ansible-playbook platforms/hyperledger-fabric/configuration/chaincode-ops.yaml --extra-vars "@path-to-network.yaml"
Run playbook for Fabric version 2.2.x with external chaincode¶
The playbook external-chaincode-ops.yaml is used to upgrade chaincode to a new version in the existing fabric network with version 2.2.x. This can be done by using the following command
ansible-playbook platforms/hyperledger-fabric/configuration/external-chaincode-ops.yaml --extra-vars "@path-to-network.yaml"
NOTE: The Chaincode should be upgraded for all participants of the channel.