Hyperledger-Fabric源码分析-共识算法-前言

1.概述

​ Hyperledger Fabric的各个节点的交易信息统一由排序服务节点(orderer service node)处理,保证每个节点上的交易顺序一致,天然避免了分叉问题。目前,Hyperledger Fabric提供三种排序算法:

  • Solo

​ 单节点排序,不适合实际生产环境,一般用在测试环境中

  • kafka

    利用ZooKeeper 进行管理,集群管理开销较大

  • raft

    基于 etcdRaft 协议实现的崩溃容错(Crash Fault Tolerant,CFT)排序服务,比基于 Kafka 的排序服务容易设置和管理。

2.接口定义
2.1 Consenter接口定义

​ 主要定义了HandleChain方法,用来创建具体的共识实例

type Consenter interface {
   HandleChain(support ConsenterSupport, metadata *cb.Metadata) (Chain, error)
}
2.2Chain接口定义

​ 每个共识算法都实现了Chain接口

type Chain interface { 
   //普通交易排序
   Order(env *cb.Envelope, configSeq uint64) error
    
   //配置交易排序
   Configure(config *cb.Envelope, configSeq uint64) error

   //等待排序集群可用
   WaitReady() error

   //当排序集群发送错误时,会关闭返回的通道
   Errored() <-chan struct{}

   //启动当前共识算法
   Start()

   // 停止当前共识算法
   Halt()
}
2.3ConsenterSupport接口定义
type ConsenterSupport interface {
   crypto.LocalSigner
   msgprocessor.Processor

   // VerifyBlockSignature verifies a signature of a block with a given optional
   // configuration (can be nil).
   VerifyBlockSignature([]*cb.SignedData, *cb.ConfigEnvelope) error

   // BlockCutter returns the block cutting helper for this channel.
   BlockCutter() blockcutter.Receiver

   // SharedConfig provides the shared config from the channel's current config block.
   SharedConfig() channelconfig.Orderer

   // ChannelConfig provides the channel config from the channel's current config block.
   ChannelConfig() channelconfig.Channel

   // CreateNextBlock takes a list of messages and creates the next block based on the block with highest block number committed to the ledger
   // Note that either WriteBlock or WriteConfigBlock must be called before invoking this method a second time.
   CreateNextBlock(messages []*cb.Envelope) *cb.Block

   // Block returns a block with the given number,
   // or nil if such a block doesn't exist.
   Block(number uint64) *cb.Block

   // WriteBlock commits a block to the ledger.
   WriteBlock(block *cb.Block, encodedMetadataValue []byte)

   // WriteConfigBlock commits a block to the ledger, and applies the config update inside.
   WriteConfigBlock(block *cb.Block, encodedMetadataValue []byte)

   // Sequence returns the current config squence.
   Sequence() uint64

   // ChainID returns the channel ID this support is associated with.
   ChainID() string

   // Height returns the number of blocks in the chain this channel is associated with.
   Height() uint64

   // Append appends a new block to the ledger in its raw form,
   // unlike WriteBlock that also mutates its metadata.
   Append(block *cb.Block) error
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值