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 commited 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
grpc:
port: 7050
ordererAddress: orderer3.org1proxy.blockchaincloudpoc.com:443
# Specification for the 2nd organization. Each organization maps to a VPC and a separate k8s cluster
- organization:
name: manufacturer
..
..
attributes:
name: ca
subject: "/C=CH/ST=Zurich/L=Zurich/O=Manufacturer/CN=ca.manufacturer-net.org2proxy.blockchaincloudpoc.com"
type: ca
grpc:
port: 7054
peers:
- peer:
name: peer0
type: anchor # This can be anchor/nonanchor. Atleast one peer should be anchor peer.
gossippeeraddress: peer0.manufacturer-net:7051 # Internal Address of the other peer in same Org for gossip, same peer if there is only one peer
peerAddress: peer0.manufacturer-net.org2proxy.blockchaincloudpoc.com:443 # Must include port, External URI of the peer
certificate: /path/manufacturer/peer0.crt # Path to peer Certificate
cli: disabled # Creates a peer cli pod depending upon the (enabled/disabled) tag.
cactus_connector: disabled # set to enabled to create a cactus connector for Fabric
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: "chaincode_name" #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
maindirectory: "chaincode_main" #The main directory where chaincode is needed to be placed
lang: "golang" # The language in which the chaincode is written ( golang/java/node )
repository:
username: "git_username" # Git Service user who has rights to check-in in all branches
password: "git_access_token"
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
- organization:
name: manufacturer
country: CH
state: Zurich
location: Zurich
subject: "O=Manufacturer,OU=Manufacturer,L=47.38/8.54/Zurich,C=CH"
type: peer
..
..
services:
peers:
- peer:
name: peer0
type: anchor # This can be anchor/nonanchor. Atleast one peer should be anchor peer.
gossippeeraddress: peer0.manufacturer-net:7051 # Internal Address of the other peer in same Org for gossip, same peer if there is only one peer
peerAddress: peer0.manufacturer-net.org2proxy.blockchaincloudpoc.com:443 # Must include port, External URI of the peer
certificate: /home/bevel/build/manufacturer/peer0.crt # Path to peer Certificate
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
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.