Hyperledger Fabric 1.4 特性調(diào)研之Raft共識(shí)(一)

Raft是一種crash fault tolerant (CFT,崩潰故障容錯(cuò))的共識(shí)排序算法。如果有節(jié)點(diǎn)故障掉線可以正常運(yùn)行,前提是要有大多數(shù)存活,即保證1/2以上的節(jié)點(diǎn)個(gè)數(shù)正常運(yùn)行。raft共識(shí)是“主從模型”,主節(jié)點(diǎn)通過動(dòng)態(tài)選舉決定,從節(jié)點(diǎn)是主節(jié)點(diǎn)的復(fù)制。

適用場(chǎng)景

Raft作為Fabric新支持的共識(shí)模式,可以替代以往的Kafka共識(shí)模式,并且配置更簡(jiǎn)單,更能體現(xiàn)去中心化特性。在多組織多channel的場(chǎng)景下更為合適,因?yàn)槠渲С譃椴煌琧hannel配置不同的共識(shí)節(jié)點(diǎn)。

技術(shù)實(shí)現(xiàn)

Raft共識(shí)模塊基于etcd開發(fā),除了Raft的基本功能(包括leader選舉、動(dòng)態(tài)節(jié)點(diǎn)加入等),還具備以下功能:

  • 傳輸層方面,建立GRPC服務(wù)Cluster用于處理通信,默認(rèn)配置共用Orderer client的GRPC服務(wù)器,也可以配置成不同端口;
  • 支持orderer加入指定的channel,即不同channel可以配置不同的orderer集合;
  • 支持orderer替換TLS證書;
  • 預(yù)計(jì)v1.4.2版本和v 2.0.0版本支持Kafka共識(shí)遷移到Raft共識(shí),但僅支持單向遷移。即從Kafka共識(shí)遷移到Raft共識(shí)后,不可以再遷移回Kafka共識(shí)。

存在問題:
存在丟交易的現(xiàn)象,比如leader在follower發(fā)送交易時(shí)候宕機(jī),會(huì)丟失交易。

實(shí)際操作

【此處參照fabric-sample中提供的first-network示例】
configtx.yaml中需要配置共識(shí)模式,共識(shí)節(jié)點(diǎn)的地址、端口和證書等,具體如下所示:

SampleMultiNodeEtcdRaft:
        <<: *ChannelDefaults
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            OrdererType: etcdraft
            EtcdRaft:
                Consenters:
                - Host: orderer.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                - Host: orderer2.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                - Host: orderer3.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                - Host: orderer4.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                - Host: orderer5.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
            Addresses:
                - orderer.example.com:7050
                - orderer2.example.com:7050
                - orderer3.example.com:7050
                - orderer4.example.com:7050
                - orderer5.example.com:7050

            Organizations:
            - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Application:
            <<: *ApplicationDefaults
            Organizations:
            - <<: *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                - *Org1
                - *Org2
                - *Org1Idemix
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容