<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java隨記

    堅(jiān)持就是勝利!

     

    Fabric 1.1源代碼分析之 系統(tǒng)鏈碼初始化過(guò)程(哥哥篇)

    # Fabric 1.1源代碼分析之 Fabric 1.1源代碼分析 系統(tǒng)鏈碼初始化過(guò)程

    * 鏈碼這一塊的代碼非常的繞。基本上就是一個(gè)大循環(huán)。限于水平或者其它原因,差露可能難免,各位看官包涵則個(gè)...

    ## 1、系統(tǒng)鏈碼

    * 系統(tǒng)鏈碼跟智能合約鏈碼涉及到的文件差不多,流程也差不多。只是智能合約是grpc,系統(tǒng)鏈碼是chan實(shí)現(xiàn)調(diào)用.
    LSCC Lifecycle system chaincode,處理生命周期請(qǐng)求。我理解的生命周期請(qǐng)求應(yīng)該指的是一個(gè)chaincode的安裝,實(shí)例化,升級(jí),
    卸載等對(duì)其生命周期起關(guān)鍵作用的一系列操作請(qǐng)求。
    CSCC Configuration system chaincode,處理在peer程序端的channel配置。
    QSCC Query system chaincode,提供賬本查詢接口,如獲取塊和交易信息。
    ESCC Endorsement system chaincode,通過(guò)對(duì)交易申請(qǐng)的應(yīng)答信息進(jìn)行簽名,來(lái)提供背書功能。
    VSCC Validation system chaincode,處理交易校驗(yàn),包括檢查背書策略和版本在并發(fā)時(shí)的控制。

    ## 2、系統(tǒng)鏈碼注冊(cè)
    * 在/core/chaincode/shim/interfaces_stable.go中實(shí)現(xiàn)了下面的接口
    ```go
    type Chaincode interface {
        // Init is called during Instantiate transaction after the chaincode container
        // has been established for the first time, allowing the chaincode to
        // initialize its internal data
        Init(stub ChaincodeStubInterface) pb.Response

        // Invoke is called to update or query the ledger in a proposal transaction.
        // Updated state variables are not committed to the ledger until the
        // transaction is committed.
        Invoke(stub ChaincodeStubInterface) pb.Response
    }
    ```

    * 在core/scc/sysccapi.go中定義了SystemChaincode結(jié)構(gòu)體,其中定義了 Chaincode接口變量
    ```go
    type SystemChaincode struct {
        //Unique name of the system chaincode
        Name string

        //Path to the system chaincode; currently not used
        Path string

        //InitArgs initialization arguments to startup the system chaincode
        InitArgs [][]byte

        // Chaincode is the actual chaincode object
        Chaincode shim.Chaincode

        // InvokableExternal keeps track of whether
        // this system chaincode can be invoked
        // through a proposal sent to this peer
        InvokableExternal bool

        // InvokableCC2CC keeps track of whether
        // this system chaincode can be invoked
        // by way of a chaincode-to-chaincode
        // invocation
        InvokableCC2CC bool

        // Enabled a convenient switch to enable/disable system chaincode without
        // having to remove entry from importsysccs.go
        Enabled bool
    }
    ```

    * 在 core/scc/importsysccs.go文件中對(duì)系統(tǒng)鏈碼進(jìn)行了初始化,并且每個(gè)Chainoce指定了具體實(shí)現(xiàn)
    ```go
    //see systemchaincode_test.go for an example using "sample_syscc"
    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
        },
        {
            Enabled: true,
            Name: "lscc",
            Path: "github.com/hyperledger/fabric/core/scc/lscc",
            InitArgs: [][]byte{[]byte("")},
            Chaincode: lscc.NewLifeCycleSysCC(),
            InvokableExternal: true, // lscc is invoked to deploy new chaincodes
            InvokableCC2CC: true, // lscc can be invoked by other chaincodes
        },
        {
            Enabled: true,
            Name: "escc",
            Path: "github.com/hyperledger/fabric/core/scc/escc",
            InitArgs: [][]byte{[]byte("")},
            Chaincode: &escc.EndorserOneValidSignature{},
        },
        {
            Enabled: true,
            Name: "vscc",
            Path: "github.com/hyperledger/fabric/core/scc/vscc",
            InitArgs: [][]byte{[]byte("")},
            Chaincode: &vscc.ValidatorOneValidSignature{},
        },
        {
            Enabled: true,
            Name: "qscc",
            Path: "github.com/hyperledger/fabric/core/chaincode/qscc",
            InitArgs: [][]byte{[]byte("")},
            Chaincode: &qscc.LedgerQuerier{},
            InvokableExternal: true, // qscc can be invoked to retrieve blocks
            InvokableCC2CC: true, // qscc can be invoked to retrieve blocks also by a cc
        },
    }
    ```
    * 注冊(cè)流程圖
    ![](systemcoderegist.png)


    ## 3、系統(tǒng)鏈碼初始化
    * 系統(tǒng)注冊(cè)完成后會(huì)對(duì)鏈碼初始化.跟一般chaincode稍有不同的是chaincode在合約里通過(guò)grpc與peer節(jié)點(diǎn)交互。
    而系統(tǒng)鏈碼則是在協(xié)程里通過(guò)chan 實(shí)現(xiàn)交互.下面代碼創(chuàng)建兩個(gè) peerRcvCCSend := make(chan *pb.ChaincodeMessage)
        ccRcvPeerSend := make(chan *pb.ChaincodeMessage) ,是客戶端和服務(wù)端共同的參數(shù)
    ```go

    func (ipc *inprocContainer) launchInProc(ctxt context.Context, id string, args []string, env []string, ccSupport ccintf.CCSupport) error {
        peerRcvCCSend := make(chan *pb.ChaincodeMessage)
        ccRcvPeerSend := make(chan *pb.ChaincodeMessage)
        var err error
        ccchan := make(chan struct{}, 1)
        ccsupportchan := make(chan struct{}, 1)
        //啟動(dòng)客戶端處理
        go func() {
            defer close(ccchan)
            inprocLogger.Debugf("chaincode started for %s", id)
            if args == nil {
                args = ipc.args
            }
            if env == nil {
                env = ipc.env
            }
            err := _shimStartInProc(env, args, ipc.chaincode, ccRcvPeerSend, peerRcvCCSend)
            if err != nil {
                err = fmt.Errorf("chaincode-support ended with err: %s", err)
                _inprocLoggerErrorf("%s", err)
            }
            inprocLogger.Debugf("chaincode ended with for %s with err: %s", id, err)
        }()
    //啟動(dòng)服務(wù)端處理
        go func() {
            defer close(ccsupportchan)
            inprocStream := newInProcStream(peerRcvCCSend, ccRcvPeerSend)
            inprocLogger.Debugf("chaincode-support started for %s", id)
            err := ccSupport.HandleChaincodeStream(ctxt, inprocStream)
            if err != nil {
                err = fmt.Errorf("chaincode ended with err: %s", err)
                _inprocLoggerErrorf("%s", err)
            }
            inprocLogger.Debugf("chaincode-support ended with for %s with err: %s", id, err)
        }()

        select {
        case <-ccchan:
            close(peerRcvCCSend)
            inprocLogger.Debugf("chaincode %s quit", id)
        case <-ccsupportchan:
            close(ccRcvPeerSend)
            inprocLogger.Debugf("chaincode support %s quit", id)
        case <-ipc.stopChan:
            close(ccRcvPeerSend)
            close(peerRcvCCSend)
            inprocLogger.Debugf("chaincode %s stopped", id)
        }
        return err
    }

    ```


    * 初始化流程圖
    ![](systemcodeinit.png)


    ## 4、系統(tǒng)鏈碼的執(zhí)行
    ...

    posted on 2018-06-12 15:00 傻 瓜 閱讀(1019) 評(píng)論(0)  編輯  收藏 所屬分類: 雜項(xiàng)

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(7)

    我參與的團(tuán)隊(duì)

    隨筆分類

    隨筆檔案

    文章分類

    友情鏈接

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲精品久久久www| 亚洲国产精品xo在线观看| 人妻无码一区二区三区免费| 亚洲国产成人精品无码区在线秒播| 免费无毒a网站在线观看| 久久精品国产亚洲一区二区| 免费无码AV片在线观看软件| 一级做a爰片久久毛片免费陪 | 亚洲国产黄在线观看| 免费A级毛片无码专区| 朝桐光亚洲专区在线中文字幕| 亚洲免费观看视频| 在线播放高清国语自产拍免费 | 色天使色婷婷在线影院亚洲| 亚洲成A∨人片在线观看不卡| 最近免费中文字幕视频高清在线看| 和老外3p爽粗大免费视频| 亚洲日韩乱码久久久久久| 亚洲伊人成无码综合网| 久久久久久久免费视频| 五月天国产成人AV免费观看| 亚洲不卡1卡2卡三卡2021麻豆| 综合亚洲伊人午夜网 | 一个人看的免费观看日本视频www| 亚洲福利秒拍一区二区| 亚洲免费日韩无码系列| 三年片在线观看免费大全| 麻豆精品不卡国产免费看| 老妇激情毛片免费| 亚洲一区二区三区在线| 亚洲国产精品lv| 国产成人精品曰本亚洲79ren| 成年女人免费视频播放体验区| 免费的全黄一级录像带| 男女猛烈无遮掩视频免费软件| 亚洲校园春色另类激情| 亚洲四虎永久在线播放| 亚洲乳大丰满中文字幕| 亚洲国产av无码精品| 在线播放免费人成视频在线观看| 中文字幕亚洲免费无线观看日本|