List of:
(a) HyperLedger Fabric 2.0-release test network deployment
(two) Fabric2.0 first-network generates configuration instructions
(three) Fabric2.0 startup script configures network analysis
(four) Fabric2.0 Channel Practice
(five) Fabric2. 0 smart contract practice - and the definition of intelligent installation contracts
(six) Fabric2.0 intelligent practice contract - a contract to upgrade intelligence
table of Contents
Continue the previous chapter, the next contract will be upgraded intelligent contracts
or the first in the console input docker exec -it cli bash
into the console cli, cli default environment variable node peer0.org1.example.com.
1. Review the information you need to upgrade intelligence contract
It has deployed a smart contract to peer0.org1.example.com, cli console, enter the command:
peer lifecycle chaincode queryinstalled
View mycc contracts package_id as follows:
View mycc in contract definition mychannel channel, cli console, enter the command:
peer lifecycle chaincode querycommitted -C mychannel
Specific information can be seen mycc
parameter | Chinese description | value |
---|---|---|
Name | Name of Contract | YCC |
Version | Contract version | 1 |
Sequence | Contract serial number (upgrade 1, plus 1) | 1 |
Endorsement Plugin | Plug endorsement | ESCC |
Validation Plugin | Check plug | vscc |
Performing a query operation convenient later comparison
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
At this time, the console 90 outputs a value
2 Modify Contract Code
If the contract native code does not exist, 2.0 to get the code packet from the node operation
console command input
peer lifecycle chaincode getinstalledpackage --package-id mycc_1:00ef9e95ea103b2c27eacd5a62efd9b34863c672d236a1ce99a7d539b2f9ef7a
packge-id: the use of contract packge_id 1 step queries acquired
The current directory appears mycc.tar.gz package for the contract, extract contract package inside code.tar, edit the code contract
to add a default method plus 10
3. repackaging contract
Enter the following command console package contract:
peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label mycc_1
It will be packaged into a new intelligent packet mycc.tar.gz contract under the new contract codes
4. Reinstall contract
Update contract will need to re-install the code on the node to contract
peer lifecycle chaincode install mycc.tar.gz
Console output contract Installation Information:
At this point we then inquire about the installation contract information node, console input:
peer lifecycle chaincode queryinstalled
Console output:
You can see a new package_id a different mycc, the original is still there.
5. Modify the definition of contract
Real upgrade operation is in fact the definition of contract this step
by entering the following command console,与原来相比将package_id修改为新安装的合约package_id,sequence要改成2,因为install了2次
peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name mycc --version 1 --init-required --package-id mycc_1:2f358faa3475e5c37a90be9a7c0db2f608ecb09b13f64b001f83799be9fccc77 --sequence 2 --waitForEvent
Check the state approve, console input:
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1 --sequence 2 --output json --init-required
sequence要改成2,因为install了2次,否则报错Error: query failed with status: 500 - failed to invoke backing implementation of 'CheckCommitReadiness': requested sequence is 1, but new definition must be sequence 2
6. The operation of the switching node repeats 3,4,5
Environment variable switching peer0.org2.example.com, repeat steps 3, 4, the following results appear to know
7. resubmit the contract definition
After the completion of the contract lifecycle smart strategy, resubmit contract definition
peer lifecycle chaincode commit -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --version 1 --sequence 2 --init-required
注意序列号sequence
Console outputs the following results:
At this time, the value of a query through new intelligent contracts, or 90
8. Verify the new contract codes
Just added addTen this method, in theory, should be a plus 10 equals 100
console, enter the following command to invoke addTen
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["addTen","a"]}'
Really see the results of a successful upgrade to 100