Raft是一种crash fault tolerant (CFT,崩溃故障容错)的共识排序算法。如果有节点故障掉线可以正常运行,前提是要有大多数存活,即保证1/2以上的节点个数正常运行。raft共识是“主从模型”,主节点通过动态选举决定,从节点是主节点的复制。
适用场景
Raft作为Fabric新支持的共识模式,可以替代以往的Kafka共识模式,并且配置更简单,更能体现去中心化特性。在多组织多channel的场景下更为合适,因为其支持为不同channel配置不同的共识节点。
技术实现
Raft共识模块基于etcd开发,除了Raft的基本功能(包括leader选举、动态节点加入等),还具备以下功能:
- 传输层方面,建立GRPC服务Cluster用于处理通信,默认配置共用Orderer client的GRPC服务器,也可以配置成不同端口;
- 支持orderer加入指定的channel,即不同channel可以配置不同的orderer集合;
- 支持orderer替换TLS证书;
- 预计v1.4.2版本和v 2.0.0版本支持Kafka共识迁移到Raft共识,但仅支持单向迁移。即从Kafka共识迁移到Raft共识后,不可以再迁移回Kafka共识。
存在问题:
存在丢交易的现象,比如leader在follower发送交易时候宕机,会丢失交易。
实际操作
【此处参照fabric-sample中提供的first-network示例】
configtx.yaml中需要配置共识模式,共识节点的地址、端口和证书等,具体如下所示:
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
网友评论