Fabric Source Analysis 8--peer System Chaincode

Source: Internet
Author: User
Fabric Source Analysis 8--peer System Chaincode Summary

For system Chaincode, the following is referred to as the chain code . This is a personal translation, based on the nature of the Chaincode is registered to store a section of the chain of logic code, so personal habits called Chaincode as chain code , fabric documents also disguised as intelligent contract. However, because Chaincode is a special noun, the individual feels that it is best to use it directly without translating it.

In the serve function in Start.go, in the function Registerchaincodesupport (Peerserver.server ()) that registers the Chaincodesupport service for Peerserver, Registered System Chaincode:scc.RegisterSysCCs () was implemented.

The core code of the system chain is under /fabric/core/common/sysccprovider and /FABRIC/CORE/SCC , and the SCC is System Chaincode's initials. The system chain code is divided into five kinds:CSCC,ESCC,LSCC,QSCC,VSCC, each system chain code abbreviation. System chain code has implemented the /fabric/core/chaincode/shim/interfaces.go defined in the Chaincode interface , from this point can be seen, the system chain code also belongs to Chaincode , just a little bit special: cscc:configuration system Chaincode lscc:lifecycle system Chaincode escc:endorser system Chaincode Vscc:validator system Chaincode Qscc:querier system Chaincode

The files in the sysccprovider directory are: sysccprovider.go-Define system chain code service Provider Interface

The files under the SCC directory are: Sysccapi.go-system chain code of various API operations Importsysccs.go-Import five predefined system chain code Sccproviderimpl.go- The specific implementation of the system chain Code service provider and its operation are defined.

Structure Chart :

pre-defined and registered

In the /fabric/core/scc/importsysccs.go :

Predefined five system chain codes are stored in the array
var systemchaincodes = []*systemchaincode{
    {
        Enabled:           true,
        Name:              " CSCC ",
        Path:              " GITHUB.COM/HYPERLEDGER/FABRIC/CORE/SCC/CSCC ",
        Initargs:          [][]byte{[]byte (" ")} ,
        Chaincode:         &cscc. peerconfiger{},
        invokableexternal:true,//CSCC is invoked to join a channel
    },{...},{...},{...},{...},
}
Register five system chain Code
func Registersysccs () {
    for _, SYSCC: = Range Systemchaincodes {
        REGISTERSYSCC (SYSCC)
    }
}

Registersysccs traverses all the system chain codes in Systemchaincodes and calls REGISTERSYSCC for registration in turn. REGISTERSYSCC is defined in/fabric/core/scc/sysccapi.go:

The system chain code is open and in the whitelist
if!SYSCC. Enabled | | !iswhitelisted (SYSCC) {...}
The system chain code is eventually registered in the system
err: = Inproccontroller. Register (SYSCC. Path, SYSCC. Chaincode)

Inproccontroller. Register defined in /fabric/core/container/inproccontroller/inproccontroller.go:

Store the installed Chaincode to Chaincode's path as key
Typeregistry = Make (Map[string]*inproccontainer)
// Register to the Typeregistry
func Register (path string, CC shim. Chaincode) Error {
    tmp: = Typeregistry[path]
    if tmp!= nil {return
        sysccregisterederr (path)
    }
    Typeregistry[path] = &inproccontainer{chaincode:cc} return
    nil
}

The Register function Inproccontainer The system chain into the typeregistry map by using the system chain code Path member value as key, and the value of the system chain code. At this point, the system chain code registration completed. Interpretation

The following text is translated from the portion of the fabric document about the system chain code (systems Chaincode).

System chain code, like the general Chaincode, has the same programming model, but the system chain code is run in the peer program, that is, it is part of the peer program, and the General Chaincode is run in a separate container. Therefore, the system chain code is built inside the peer program and does not follow the life cycle of the general Chaincode. In particular, install,instantiate and upgrade operations are not applied to system chain codes.

The purpose of system chain code difference and general Chaincode is to shorten the time consuming of GRPC communication between peer node and Chaincode (because peer node is in a container, Chaincode is a separate container) and weigh management flexibility. For example, a system chain code can be upgraded only by upgrading the binary package of the peer program. System chain code can be registered with predefined elements and compiled into the peer program, and does not need to be similar to the endorsement strategy or endorsement functions such as miscellaneous functions.

The system chain code is used in fabric to manipulate the configuration performance of the entire system, so that the system can be changed to the appropriate state at any time.

List of currently existing system chain codes: LSCC lifecycle System chaincode, processing lifecycle requests. I understand that life cycle requests should refer to a series of operational requests that are Chaincode, instantiated, upgraded, unloaded, etc. that are critical to their lifecycle. CSCC Configuration system Chaincode, which handles channel configuration at the peer end of the program. QSCC query System Chaincode, which provides a ledger query interface, such as obtaining blocks and transaction information. ESCC Endorsement System Chaincode provides endorsement functions by signing the response information for the transaction request. VSCC Validation system Chaincode handles transaction checksums, including checking endorsement policies and versioning during concurrency.

Attention must be paid to modifying or replacing the system chain code, especially LSCC,ESCC and VSCC, as they are in important trading links. Take VSCC as an example, because the transaction data in the regional chain is persistent, therefore, it is not worth the VSCC to verify the block before submitting it to the ledger, and it is important that all peer in the same channel must compute the same certificate (the certificate that validates the output) in order to avoid conflicting books. It is therefore particularly noteworthy to avoid conflicts with previously generated transaction data when VSCC is modified or replaced.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.