github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/docs/source/enable_cc_lifecycle.md (about) 1 # Enabling the new chaincode lifecycle 2 3 Users upgrading from v1.4.x to v2.x will have to edit their channel configurations to enable the new lifecycle features. This process involves a series of [channel configuration updates](./config_update.html) the relevant users will have to perform. 4 5 Note that the `Channel` and `Application` [capabilities](./capabilities_concept.html) of your application channels will have to be updated to `V2_0` for the new chaincode lifecycle to work. Check out [Considerations for getting to 2.0](./upgrade_to_newest_version.html#chaincode-lifecycle) for more information. 6 7 Updating a channel configuration is, at a high level, a three step process (for each channel): 8 9 1. Get the latest channel config 10 2. Create a modified channel config 11 3. Create a config update transaction 12 13 We will be performing these channel configuration updates by leveraging a file called `enable_lifecycle.json`, which contains all of the updates we will be making in the channel configurations. Note that in a production setting it is likely that multiple users would be making these channel update requests. However, for the sake of simplicity, we are presenting all of the updates as how they would appear in a single file. 14 15 Note: this topic describes a network that does not use a "system channel", a channel that the ordering service is bootstrapped with and the ordering service exclusively controls. Since the release of v2.3, using a system channel is now considered the legacy process as compared to the new process to [Create a channel](./create_channel/create_channel_participation.html) without a system channel. For a version of this topic that includes information about the system channel, check out [Enabling the new chaincode lifecycle](https://hyperledger-fabric.readthedocs.io/en/release-2.2/enable_cc_lifecycle.html) from the v2.2 documentation. 16 17 ## Create `enable_lifecycle.json` 18 19 Note that in addition to using `enable_lifecycle.json`, this tutorial also uses `jq` to apply the edits to the modified config file. The modified config can also be edited manually (after it has been pulled, translated, and scoped). Check out this [sample channel configuration](./config_update.html#sample-channel-configuration) for reference. 20 21 However, the process described here (using a JSON file and a tool like `jq`) does have the advantage of being scriptable, making it suitable for proposing configuration updates to a large number of channels, and is the recommended process for editing a channel configuration. 22 23 Note that the `enable_lifecycle.json` uses sample values, for example `org1Policies` and the `Org1ExampleCom`, which will be specific to your deployment): 24 25 ``` 26 { 27 "org1Policies": { 28 "Endorsement": { 29 "mod_policy": "Admins", 30 "policy": { 31 "type": 1, 32 "value": { 33 "identities": [ 34 { 35 "principal": { 36 "msp_identifier": "Org1ExampleCom", 37 "role": "PEER" 38 }, 39 "principal_classification": "ROLE" 40 } 41 ], 42 "rule": { 43 "n_out_of": { 44 "n": 1, 45 "rules": [ 46 { 47 "signed_by": 0 48 } 49 ] 50 } 51 }, 52 "version": 0 53 } 54 }, 55 "version": "0" 56 } 57 }, 58 "org2Policies": { 59 "Endorsement": { 60 "mod_policy": "Admins", 61 "policy": { 62 "type": 1, 63 "value": { 64 "identities": [ 65 { 66 "principal": { 67 "msp_identifier": "Org2ExampleCom", 68 "role": "PEER" 69 }, 70 "principal_classification": "ROLE" 71 } 72 ], 73 "rule": { 74 "n_out_of": { 75 "n": 1, 76 "rules": [ 77 { 78 "signed_by": 0 79 } 80 ] 81 } 82 }, 83 "version": 0 84 } 85 }, 86 "version": "0" 87 } 88 }, 89 "appPolicies": { 90 "Endorsement": { 91 "mod_policy": "Admins", 92 "policy": { 93 "type": 3, 94 "value": { 95 "rule": "MAJORITY", 96 "sub_policy": "Endorsement" 97 } 98 }, 99 "version": "0" 100 }, 101 "LifecycleEndorsement": { 102 "mod_policy": "Admins", 103 "policy": { 104 "type": 3, 105 "value": { 106 "rule": "MAJORITY", 107 "sub_policy": "Endorsement" 108 } 109 }, 110 "version": "0" 111 } 112 }, 113 "acls": { 114 "_lifecycle/CheckCommitReadiness": { 115 "policy_ref": "/Channel/Application/Writers" 116 }, 117 "_lifecycle/CommitChaincodeDefinition": { 118 "policy_ref": "/Channel/Application/Writers" 119 }, 120 "_lifecycle/QueryChaincodeDefinition": { 121 "policy_ref": "/Channel/Application/Writers" 122 }, 123 "_lifecycle/QueryChaincodeDefinitions": { 124 "policy_ref": "/Channel/Application/Writers" 125 } 126 } 127 } 128 ``` 129 130 **Note: the "role" field of these new policies should say `'PEER'` if [NodeOUs](./msp.html#organizational-units) are enabled for the org, and `'MEMBER'` if they are not.** 131 132 ## Edit the channel configurations 133 134 To fully enable the new chaincode lifecycle, you must first edit the configuration of your own organization as it exists in a channel configuration, and then you must update the channel itself to include a default endorsement policy for the channel. You can then optionally update your channel access control list. 135 136 Note: this topic leverages the instructions on how to update a channel configuration that are found in the [Updating a channel configuration](./config_update.html) tutorial. The environment variables listed here work in conjunction with those commands to update your channels. 137 138 ### Edit the peer organizations 139 140 By default, peer organizations are able to make configuration update requests to their own organization on an application channel without needing the approval of any other peer organizations. However, if you are attempting to make a change to a different organization, that organization will have to approve the change. 141 142 You will need to export the following variables: 143 144 * `CH_NAME`: the name of the application channel being updated. 145 * `ORGNAME`: The name of the organization you are currently updating. 146 * `TLS_ROOT_CA`: the absolute path to the TLS cert of your ordering node. 147 * `CORE_PEER_MSPCONFIGPATH`: the absolute path to the MSP representing your organization. 148 * `CORE_PEER_LOCALMSPID`: the MSP ID of the organization proposing the channel update. This will be the MSP of one of the peer organizations. 149 * `ORDERER_CONTAINER`: the name of an ordering node container. When targeting the ordering service, you can target any particular node in the ordering service. Your requests will be forwarded to the leader automatically. 150 151 Once you have set the environment variables, navigate to [Step 1: Pull and translate the config](./config_update.html#step-1-pull-and-translate-the-config). 152 153 Then, add the lifecycle organization policy (as listed in `enable_lifecycle.json`) to a file called `modified_config.json` using this command: 154 155 ``` 156 jq -s ".[0] * {\"channel_group\":{\"groups\":{\"Application\": {\"groups\": {\"$ORGNAME\": {\"policies\": .[1].${ORGNAME}Policies}}}}}}" config.json ./enable_lifecycle.json > modified_config.json 157 ``` 158 159 Then, follow the steps at [Step 3: Re-encode and submit the config](./config_update.html#step-3-re-encode-and-submit-the-config). 160 161 ### Edit the application channels 162 163 After all of the application channels have been [updated to include V2_0 capabilities](./upgrade_to_newest_version.html#capabilities), endorsement policies for the new chaincode lifecycle must be added to each channel. 164 165 You can set the same environment variables you set when updating the peer organizations. Note that in this case you will not be updating the configuration of an org in the configuration, so the `ORGNAME` variable will not be used. 166 167 Once you have set the environment variables, navigate to [Step 1: Pull and translate the config](./config_update.html#step-1-pull-and-translate-the-config). 168 169 Then, add the lifecycle organization policy (as listed in `enable_lifecycle.json`) to a file called `modified_config.json` using this command: 170 171 ``` 172 jq -s '.[0] * {"channel_group":{"groups":{"Application": {"policies": .[1].appPolicies}}}}' config.json ./enable_lifecycle.json > modified_config.json 173 ``` 174 175 Then, follow the steps at [Step 3: Re-encode and submit the config](./config_update.html#step-3-re-encode-and-submit-the-config). 176 177 For this channel update to be approved, the policy for modifying the `Channel/Application` section of the configuration must be satisfied. By default, this is a `MAJORITY` of the peer organizations on the channel. 178 179 #### Edit channel ACLs (optional) 180 181 The following [Access Control List (ACL)](./access_control.html) in `enable_lifecycle.json` are the default values for the new lifecycle, though you have the option to change them depending on your use case. 182 183 ``` 184 "acls": { 185 "_lifecycle/CheckCommitReadiness": { 186 "policy_ref": "/Channel/Application/Writers" 187 }, 188 "_lifecycle/CommitChaincodeDefinition": { 189 "policy_ref": "/Channel/Application/Writers" 190 }, 191 "_lifecycle/QueryChaincodeDefinition": { 192 "policy_ref": "/Channel/Application/Readers" 193 }, 194 "_lifecycle/QueryChaincodeDefinitions": { 195 "policy_ref": "/Channel/Application/Readers" 196 ``` 197 198 You can leave the same environment in place as when you previously edited application channels. 199 200 Once you have the environment variables set, navigate to [Step 1: Pull and translate the config](./config_update.html#step-1-pull-and-translate-the-config). 201 202 Then, add the ACLs (as listed in `enable_lifecycle.json`) and create a file called `modified_config.json` using this command: 203 204 ``` 205 jq -s '.[0] * {"channel_group":{"groups":{"Application": {"values": {"ACLs": {"value": {"acls": .[1].acls}}}}}}}' config.json ./enable_lifecycle.json > modified_config.json 206 ``` 207 208 Then, follow the steps at [Step 3: Re-encode and submit the config](./config_update.html#step-3-re-encode-and-submit-the-config). 209 210 For this channel update to be approved, the policy for modifying the `Channel/Application` section of the configuration must be satisfied. By default, this is a `MAJORITY` of the peer organizations on the channel. 211 212 ## Enable new lifecycle in `core.yaml` 213 214 If you follow [the recommended process](./upgrading_your_components.html#overview) for using a tool like `diff` to compare the new version of `core.yaml` packaged with the binaries with your old one, you will not need to add `_lifecycle: enable` to the list of enabled system chaincodes because the new `core.yaml` has added it under `chaincode/system`. 215 216 However, if you are updating your old node YAML file directly, you will have to add `_lifecycle: enable` to the list of enabled system chaincodes. 217 218 For more information about upgrading nodes, check out [Upgrading your components](./upgrading_your_components.html). 219 220 <!--- Licensed under Creative Commons Attribution 4.0 International License 221 https://creativecommons.org/licenses/by/4.0/ -->