今天在读Fabric-Node-sdk源代码时看到了LSCC这个变量,在instantiate某一个chaincode的时候,需要先使用它,故而查了下,发现一篇文章,做如下记录:

System Chaincodes in Hyperledger Fabric v1.1

Hyperledger Fabric v1.1 provides a variety of special chaincodes called system chaincodes to perform certain privileged tasks. The goal of this article is to provide pointers to the implementation of various system chaincodes in Fabric, their functionalities and usage. Like a user chaincode, system chaincodes also implement Init() and Invoke() functions. There are five system chaincodes and are listed below:

  1. Configuration System Chaincode (CSCC) -- core/scc/cscc/configure.go Life
  2. Cycle System Chaincode (LSCC) -- core/scc/lscc/lscc.go
  3. Query System Chaincode (QSCC) -- core/scc/qscc/query.go
  4. Endorser System Chaincode (ESCC) -- core/scc/escc/endorser_onevalidsignature.go
  5. Validator System Chaincode (VSCC) -- core/scc/vscc/validator_onevalidsignature.go

Next, we present the functionalities provided by each of these system chaincodes along with the usage. Note that we might not be able to easily invoke/query all functions supported by system chaincodes using the command line (CLI) as we might need to pass certain serialized protobuf bytes of golang structs. Hence, for such functions, it is advisable to use SDK. In this article, we execute invoke/query using CLI only for applicable functions.

1. Configuration System Chaincode (CSCC)

The CSCC manages channel related information on a peer and process channel configuration transactions. It provides the following five functions: (i) JoinChain, (ii) GetConfigBlock, (iii) GetConfigTree, (iv) SimulateConfigTreeUpdate and (v) GetChannels. Next, we show the usage of each of this functionality. We assume that all commands are executed from client pointing to peer0 in our sample network (refer to setup). To run CSCC related command, we need to use peer channel and peer chaincode CLI commands.

The JoinChain functionality is invoked to make a peer join a channel. It expects one argument that is the serialized protobuf bytes of channel configuration block which is received from orderer as a result of execution of peer channel create command (refer to setup). The following peer CLI command makes a peer join a channel called ch1. The peer channel join command takes care of reading the ch1.block and passing it as bytes while invoking CSCC. However, if we need to use peer chaincode invoke, it is not easy to put the content of ch1.block in the CLI query itself.

$ peer channel join -b ch1.block

The GetConfigBlock is invoked to get the current configuration block for a given channel. It expects one argument that is the byte representation of the channel name. Any one of the following two peer CLI commands can be used to get the config block of channel ch1.

$ peer chaincode query -C "" -n cscc -c '{"Args":["GetConfigBlock", "ch1"]}'
  (or)
$ peer channel fetch -o orderer0:7050 config -c ch1

The GetChannels is invoked to get the information about all channels which the peer has joined so far. The following two peer CLI commands can be used to get all channels.

$ peer chaincode query -C "" -n cscc -c '{"Args":["GetChannels"]}'
  (or)
$ peer channel list

Exercise for the reader: Use CLI commands to query/invoke GetConfigTree and SimulateConfigTreeUpdate. To add or remove an organization from a channel, config tree must be fetched to make modification and get an endorsement from CSCC by invoking the SimulateConfigTreeUpdate function.

2. Life Cycle System Chaincode (LSCC)

The LSCC manages the lifecycle of chaincodes --- a chaincode can be installed on a peer, deployed on a channel, be upgraded, and a user can get information about running chaincodes. It provides the following eight functions: (i) install, (ii) deploy, (iii) upgrade, (iv) getid, (v) getdepspec, (vi) getccdata, (vii) getchaincodes, and (viii) getinstalledchaincodes.

The install functionality is invoked to store a chaincode program on a peer filesystem (/var/hyperledger/production/chaincodes). It expects one argument that is the serialized protobuf bytes of chaincode deployment spec (core/common/ccprovider/cdspackage.go). Though we can directly invoke LSCC, as we need to pass the content of whole chaincode, it would be better to use peer chaincode install command which would internally invoke on LSCC by reading the chaincode content.

$ peer chaincode install -n generic-chaincode -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/generic-chaincode

The deploy functionality is invoked to instantiate a chaincode on a given channel. It can accept five arguments out of which the first two, i.e., channel name and chaincode deployment spec are necessary. Whereas other three arguments, i.e., endorsement policy, the name of the endorser system chaincode and name of the validator system chaincode are optional.

$ peer chaincode instantiate -o orderer0:7050 -C ch1 -n generic-chaincode -v 1.0 -c '{"Args":["init"]}' -P "AND ('Org0MSP.member','Org1MSP.member', 'Org2MSP.member', 'Org3MSP.member')"

The getdepspec functionality is used to get a deployment spec of a chaincode installed on a peer. The following command retrieves the deployment spec of a chaincode named generic-chaincode from channel ch1.

$ peer chaincode query -C "ch1" -n lscc -c '{"Args":["getdepspec", "ch1", "generic-chaincode"]}'

The getchaincodes functionality is used to get a list of deployed chaincodes on a channel. The following command retrieves a list of chaincode instantiated on channel ch1.

$ peer chaincode query -C "ch1" -n lscc -c '{"Args":["getchaincodes"]}'

The getinstalledchaincodes functionality is used to get a list of installed chaincodes on a peer. The following command retrieves a list of chaincode installed on a peer.

$ peer chaincode query -C "" -n lscc -c '{"Args":["getinstalledchaincodes"]}'

Exercise for the reader: Use CLI commands to upgrade a chaincode, getid of a chaincode, and getccdata (i.e., a chaincode data).

3. Query System Chaincode (QSCC)

The LSCC exposes certain functions to user so that blocks and transactions stored on block storage can be queried. It provides the following five functions: (i) GetChainInfo, (ii) GetBlockByNumber, (iii) GetBlockByHash, (iv) GetTransactionByID, and (v) GetBlockByTxID

The GetBlockByNumber functionality is used to get a serialized block. The following command retrieves a block number 3 from channel ch1.

$ peer chaincode query -C "" -n qscc -c '{"Args":["GetBlockByNumber", "ch1", "3"]}'

Exercise for the reader: Usage of other functionalities are very similar to the above CLI command.

4. Endorser System Chaincode (ESCC)

The ESCC is invoked by the endorsing peer (core/endorser/endorser.go), after executing a transaction, to put its signature on the transaction response message which includes the result of transaction execution (i.e., transaction status, chaincode events, read/write set). An invoke function can accept between 5 to 7 parameters. These parameters are Header, ChaincodeProposalPayload, ChaincodeID, Response, simulation results, events, and payload visibility.

5. Validator System Chaincode (VSCC)

The VSCC is invoked by the committing peer (core/committer/txvalidator/validator.go) to validate each transactions' signature set against the endorsement policy of the chaincode.

results matching ""

    No results matching ""