一、Fabric网络组织

Fabric网络组织按如下结构组成:Fabric网络-->Channel通道-->组织(成员)-->节点。即整个网络由数个通道组成,每个通道都由多个组织构成,而每个组织内部由数个节点组成(可能由功能或其他划分方式分为多个节点)。如下图所示:

二、主节点(leader peer)选举

一个组织(其实是成员)在一个通道上可以有多个Peer节点,这时候为了提高通信效率,需要选举出来一个主节点(leader)作为代表和排序服务节点通信,负责从排序服务节点处获取最新的区块并在组织内部同步。有如下两种方式:

1. 静态指定

配置文件中配置

    # Gossip related configuration
gossip:
# Defines whenever peer will initialize dynamic algorithm for
# "leader" selection, where leader is the peer to establish
# connection with ordering service and use delivery protocol
# to pull ledger blocks from ordering service
useLeaderElection: false
# Statically defines peer to be an organization "leader",
# where this means that current peer will maintain connection
# with ordering service and disseminate block across peers in
# its own organization
orgLeader: true
2. 动态选举

相关配置:

    # Gossip related configuration
gossip:
# Leader election service configuration
election:
# Longest time peer wait for stable membership during leader election startup (unit: second)
startupGracePeriod: 15s
# Interval gossip membership sampled to check its stability (unit: second)
membershipSampleInterval: 1s
# Time pass since last declaration message before peer decide to go to election (unit: second)
leaderAliveThreshold: 10s
# Time between peer sends propose message and declare itself as a leader (sends declaration message) (unit: second)
leaderElectionDuration: 5s
3. leader节点选举流程

选举流程(简要):

如果当前没有leader,进入选举算法
如果当前是leader:广播leadership declearation,如果收到比自己小的leadership declearation,自己变为follower;
如果当前是follower:指定时间内没有收到leadership declearation,则认为leader离线了,进入选举流程

选举算法(简要):

广播提议自己为leader消息
各个节点收集选举消息
比对ID,如果自己ID最小,则自己为leader

详细过程如下图所示:

伪代码实现:

// Gossip leader election module
// Algorithm properties:
// - Peers break symmetry by comparing IDs
// - Each peer is either a leader or a follower,
// and the aim is to have exactly 1 leader if the membership view
// is the same for all peers
// - If the network is partitioned into 2 or more sets, the number of leaders
// is the number of network partitions, but when the partition heals,
// only 1 leader should be left eventually
// - Peers communicate by gossiping leadership proposal or declaration messages // The Algorithm, in pseudo code:
//
//
// variables:
// leaderKnown = false
//
// Invariant:
// Peer listens for messages from remote peers
// and whenever it receives a leadership declaration,
// leaderKnown is set to true
//
// Startup():
// wait for membership view to stabilize, or for a leadership declaration is received
// or the startup timeout expires.
// goto SteadyState()
//
// SteadyState():
// while true:
// If leaderKnown is false:
// LeaderElection()
// If you are the leader:
// Broadcast leadership declaration
// If a leadership declaration was received from
// a peer with a lower ID,
// become a follower
// Else, you're a follower:
// If haven't received a leadership declaration within
// a time threshold:
// set leaderKnown to false
//
// LeaderElection():
// Gossip leadership proposal message
// Collect messages from other peers sent within a time period
// If received a leadership declaration:
// return
// Iterate over all proposal messages collected.
// If a proposal message from a peer with an ID lower
// than yourself was received, return.
// Else, declare yourself a leader
4. 消息定义
// Leadership Message is sent during leader election to inform
// remote peers about intent of peer to proclaim itself as leader
message LeadershipMessage {
bytes pki_id = 1;
PeerTime timestamp = 2;
bool is_declaration = 3;
}

Fabric网络组织与主节点选举的更多相关文章

  1. 菜鸟系列Fabric——Fabric 网络架构介绍(4)

    Fabric 网络架构介绍 1. 网络架构介绍 如图所示,fabric网络架构主要包含客户端节点.CA节点.Peer节点.Orderer节点这几个部分.并且fabric架构是安装组织来进行划分当,每个 ...

  2. hyperledger中文文档学习-4-构建第一个fabric网络

    接下来的操作都将在hyperledge环境安装构建的虚拟机的环境下进行 参考https://hyperledgercn.github.io/hyperledgerDocs/build_network_ ...

  3. fabric网络环境启动过程详解

    这篇文章对fabric的网络环境启动过程进行讲解,也就是我们上节讲到的启动测试fabric网络环境时运行network_setup.sh这个文件的执行流程 fabric网络环境启动过程详解 上一节我们 ...

  4. 搭建基于hyperledger fabric的联盟社区(五) --启动Fabric网络

    现在所有的文件都已经准备完毕,我们可以启动fabric网络了. 一.启动orderer节点 在orderer服务器上运行: cd ~/go/src/github.com/hyperledger/fab ...

  5. Hyperledger Fabric手动生成CA证书搭建Fabric网络

    之前介绍了使用官方脚本自动化启动一个Fabric网络,并且所有的证书都是通过官方的命令行工具cryptogen直接生成网络中的所有节点的证书.在开发环境可以这么简单进行,但是生成环境下还是需要我们自定 ...

  6. 基于ubuntu16.04快速构建Hyperledger Fabric网络

    前言 最近在参加一个比赛,使用到了区块链的开源软件hyperledger,由于之前从未接触过区块链,以及和区块链开发相关的内容,所有在网上查阅了大量的资料,并且通过学习yeasy(杨宝华)开源的入门书 ...

  7. 搭建Fabric网络(二)下载bin和images

    上一篇已经把运行和开发Fabric需要的程序都安装好了,这一篇主要讲怎么运行一个简单的Fabric网络. 1.  下载官方Sample代码 git clone -b master https://gi ...

  8. Windows下fabric sdk连接Linux上fabric网络的调试过程

    上个月刚入职一家公司从事区块链研发工作,选型采用Hyperledger Fabric作为开发平台.团队的小组成员全部采用的是在VirtualBox上面安装桌面版的Ubuntu 16.04虚拟机,开发工 ...

  9. Fabric网络节点发现及成员管理

    一个新节点通过已知的节点加入到网络中,此时,它所知的网络节点信息是非常有限的,需要通过节点发现获知更多的节点,建立起足够的连接.另外,当一个新节点加入到网络时,原有网络节点也需要通过节点发现感知到新节 ...

随机推荐

  1. 基于Hadoop不同版本搭建hive集群(附配置文件)

    本教程采用了两种方案 一种是hive-1.21版本,hadoop版本为hadoop2.6.5 还有一种是主要讲基于hadoop3.x hive的搭建 先来第一种 一.本地方式(内嵌derby) 步骤 ...

  2. [COCOS2DX-LUA]0-003.根据COCOS2DX热更新

    一.最近有需求就是要基于COCOS2DX-LUA进行游戏的增量更新,找了资料,发现了COCOS2DX有自带一个热更新的类,就是AssetsManager,但是该接口对于我来说有以下的缺陷 1.版本号在 ...

  3. python报错2

    缩进导致的报错 IndentationError: unindent does not match any outer indentation level NameError 命名错误 原因是: na ...

  4. RabbitMQ 高级应用

    本文是作者原创,版权归作者所有.若要转载,请注明出处. 本文RabbitMQ版本为rabbitmq-server-3.7.17,erlang为erlang-22.0.7.请各位去官网查看版本匹配和下载 ...

  5. DM7的聚簇索引和非聚簇索引(cluster属性)

    早期的DM7或者DM8在创建带有主键的表时,默认会加上cluster属性:后期版本则全部为默认非cluster属性. 下面为显示的指定cluster属性: 1.创建主键的为聚集索引. create t ...

  6. jchdl - RTL实例 - Adder

    https://mp.weixin.qq.com/s/9S29BCTcJfbpR62ALjSidA   加法器.   参考链接 https://github.com/wjcdx/jchdl/blob/ ...

  7. 蓝桥杯 算法提高 11-1实现strcmp函数 (JAVA方法)

    蓝桥杯 算法提高 11-1实现strcmp函数 (JAVA方法) 首先这不是一个多难的题,但是网上的我没怎么找到有Java的代码,基本全都是c语言的,小编是个小白,如果有不对的地方请联系小编 问题描述 ...

  8. Java实现 LeetCode 718 最长重复子数组(动态规划)

    718. 最长重复子数组 给两个整数数组 A 和 B ,返回两个数组中公共的.长度最长的子数组的长度. 示例 1: 输入: A: [1,2,3,2,1] B: [3,2,1,4,7] 输出: 3 解释 ...

  9. (Java实现) 过河卒

    过河卒 题目描述 棋盘上AA点有一个过河卒,需要走到目标BB点.卒行走的规则:可以向下.或者向右.同时在棋盘上CC点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点.因此称之为&q ...

  10. Java实现 LeetCode 686 重复叠加字符串匹配

    686. 重复叠加字符串匹配 给定两个字符串 A 和 B, 寻找重复叠加字符串A的最小次数,使得字符串B成为叠加后的字符串A的子串,如果不存在则返回 -1. 举个例子,A = "abcd&q ...