Goosip协议

去中心化、容错和最终一致性的算法

信息达到同步的最优时间:log(N)。

功能

节点发现

数据广播

gossip中有三种基本的操作:

  • push - A节点将数据(key,value,version)及对应的版本号推送给B节点,B节点更新A中比自己新的数据
  • pull - A仅将数据key,version推送给B,B将本地比A新的数据(Key,value,version)推送给A,A更新本地
  • push/pull - 与pull类似,只是多了一步,A再将本地比B新的数据推送给B,B更新本地

说到底,gossip服务是处理消息的,每种类型的消息有不同的用途

消息类型

gossip服务使用不同模块处理不同类型的消息。消息类型原型在/protos/message.proto中定义。gossip中传播的消息以GossipMessage形式传递,具体的消息数据存放在GossipMessage中的Content成员中。

节点关系消息

与频道成员身份、关系和存续相关的消息类型。

AliveMessage - alive消息

MembershipRequest - 成员关系请求消息

MembershipResponse -成员关系应答消息

pull机制消息

pull进来的可以是以块数据为内容的消息,也可以是身份数据为内容的消息,下述4种消息中都有一个成员MsgType来表明这个消息中所携带的数据内容。从pull步骤上分为四种:

GossipHello - hello消息

DataDigest - 消息摘要

DataRequest - 摘要请求

DataUpdate - 摘要应答

state消息

和状态有关的消息。这里的状态指的是chain的数据状态,如一个结点所存储的块数据是否一致,可以说这里所谓的状态接近数据的意思。

StateInfo - 状态消息

DataMessage - 数据消息(block)

TransactionMessage - 交易数据;

辅助类消息

这类消息不承担具体传送传播数据的任务,而是辅助性的:

Empty - 空消息,用于结点间的Ping(来测试结点是否连通)和测试。

ConnEstablish - 用于gossip之间的握手,即任何时候一个peer想与另一个peer连接通信,都需要先发送这个消息以证明其身份。

gossip模块

主要功能

gossip部分接口

type Gossip interface {
// Send sends a message to remote peers
Send(msg *proto.GossipMessage, peers ...*comm.RemotePeer)
// GetPeers returns the NetworkMembers considered alive
Peers() []discovery.NetworkMember // PeersOfChannel returns the NetworkMembers considered alive
// and also subscribed to the channel given
PeersOfChannel(common.ChainID) []discovery.NetworkMember
// UpdateLedgerHeight updates the ledger height the peer
// publishes to other peers in the channel
UpdateLedgerHeight(height uint64, chainID common.ChainID) // Gossip sends a message to other peers to the network
Gossip(msg *proto.GossipMessage) // Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
// If passThrough is false, the messages are processed by the gossip layer beforehand.
// If passThrough is true, the gossip layer doesn't intervene and the messages
// can be used to send a reply back to the sender
Accept(acceptor common.MessageAcceptor, passThrough bool) (<-chan *proto.GossipMessage, <-chan proto.ReceivedMessage) // JoinChan makes the Gossip instance join a channel
JoinChan(joinMsg api.JoinChannelMessage, chainID common.ChainID) // LeaveChan makes the Gossip instance leave a channel.
// It still disseminates stateInfo message, but doesn't participate
// in block pulling anymore, and can't return anymore a list of peers
// in the channel.
LeaveChan(chainID common.ChainID) // Stop stops the gossip component
Stop()
}

主要模块

初始化和服务启动

消息广播

PeerA通过gossip协议广播消息,PeerB为其中一个消息接收节点。

代码应用框架

//初始化并加入通道‘A’
gossip = NewGossipInstance(15000, 1, 1000, isBoot)
gossip.JoinChan(&JoinChanMsg{}, common.ChainID("A"))
gossip.UpdateLedgerHeight(1, common.ChainID("A"))
acceptChan, _ := gossip.Accept(AcceptData, false) //AcceptData未消息选择器 //通过gossip的方式来发送消息
gossip.Gossip(msg *pb.GossipMessage)

注:gossip发送消息后,对端节点接收到消息,会把过滤的消息坊到accetpChan通道中。

gossip pull机制

消息类型

pull机制主要涉及四种消息类型

GossipHello - hello消息

DataDigest - 消息摘要

DataRequest - 摘要请求

DataUpdate - 摘要应答

具体pull的内容包括: 未定义消息,块消息,身份消息

初始化

pull机制的四个步骤

关键参数和函数

PullPeerNum //从PullPeerNum个节点pull数据
PullInterval //pull引擎每隔PullInterval开始一次pull同步 createBlockPuller: //创建pull.Mediator
- IngressDigFilter(大于本地高度的区块)//用来过滤digest,返回自己要同步数据的摘要
- IdExtractor: seqNumFromMsg //要同步数据的唯一标识

注: IDExtractor是个接口,区块数据用块高标识;身份数据用证书或者公钥相关数据表示

超级账本fabric原理之gossip详解的更多相关文章

  1. Go语言备忘录:反射的原理与使用详解

    目录: 预备知识 reflect.Typeof.reflect.ValueOf Value.Type 动态调用 通过反射可以修改原对象 实现类似“泛型”的功能   1.预备知识: Go的变量都是静态类 ...

  2. 基础 | batchnorm原理及代码详解

    https://blog.csdn.net/qq_25737169/article/details/79048516 https://www.cnblogs.com/bonelee/p/8528722 ...

  3. Oracle中的SQL分页查询原理和方法详解

    Oracle中的SQL分页查询原理和方法详解 分析得不错! http://blog.csdn.net/anxpp/article/details/51534006

  4. Spring学习 6- Spring MVC (Spring MVC原理及配置详解)

    百度的面试官问:Web容器,Servlet容器,SpringMVC容器的区别: 我还写了个文章,说明web容器与servlet容器的联系,参考:servlet单实例多线程模式 这个文章有web容器与s ...

  5. Go语言备忘录(2):反射的原理与使用详解

    本文内容是本人对Go语言的反射原理与使用的备忘录,记录了关键的相关知识点,以供翻查. 文中如有错误的地方请大家指出,以免误导!转摘本文也请注明出处:Go语言备忘录(2):反射的原理与使用详解,多谢! ...

  6. DeepLearning tutorial(3)MLP多层感知机原理简介+代码详解

    本文介绍多层感知机算法,特别是详细解读其代码实现,基于python theano,代码来自:Multilayer Perceptron,如果你想详细了解多层感知机算法,可以参考:UFLDL教程,或者参 ...

  7. 机器学习——KMeans聚类,KMeans原理,参数详解

    0.聚类 聚类就是对大量的未知标注的数据集,按数据的内在相似性将数据集划分为多个类别,使类别内的数据相似度较大而类别间的数据相似度较小,聚类属于无监督的学习方法. 1.内在相似性的度量 聚类是根据数据 ...

  8. Spark RDD、DataFrame原理及操作详解

    RDD是什么? RDD (resilientdistributed dataset),指的是一个只读的,可分区的分布式数据集,这个数据集的全部或部分可以缓存在内存中,在多次计算间重用. RDD内部可以 ...

  9. 非极大值抑制(NMS,Non-Maximum Suppression)的原理与代码详解

    1.NMS的原理 NMS(Non-Maximum Suppression)算法本质是搜索局部极大值,抑制非极大值元素.NMS就是需要根据score矩阵和region的坐标信息,从中找到置信度比较高的b ...

随机推荐

  1. ProgressBar三种style

    一.普通的ProgressBar显示如图 <ProgressBar        android:id="@+id/pbNormal"        android:layo ...

  2. Tips_关闭按钮的简单实现 && Felx实现水平垂直居中

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. java课程之团队开发冲刺阶段1.5

    一.总结昨天进度 1.昨天由于时间较少,没有太多的时间来进行学习Sqlite 二.遇到的困难 1.由于最终的程序需要调用本地的数据库,所以我们需要在安装程序的时候就需要直接附带安装一个本地的数据库到手 ...

  4. 推荐自学JAVA开发的三本书

    ---------------------------------------------------------------------------------------------------- ...

  5. oracle登录管理员创建数据库和表空间

    登录管理员最高权限账号 cmd输入sqlplus 回车,或者直接打开sqlplus 用户名:sys 密码:sys as sysdba 1.首先,创建(新)用户: create user usernam ...

  6. 查询结果集转换成HTML存储过程

    工作中经常需要用SQLServer发送报警或者业务报表邮件,每次现拼串也不是办法,故写了一个TableResult to HTML的存储过程 USE master; GO -- Description ...

  7. NeuChar 平台使用及开发教程(六):成为开发者

    在上一篇<NeuChar 平台使用及开发教程(五):使用 NeuChar 的关键字回复服务>中,我们已经学习了如何命中关键字来反馈特定格式内容的信息,这是由微信开发者/运营者自己来维护的信 ...

  8. [Swift]LeetCode231. 2的幂 | Power of Two

    Given an integer, write a function to determine if it is a power of two. Credits:Special thanks to @ ...

  9. [Swift]LeetCode435. 无重叠区间 | Non-overlapping Intervals

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  10. [Swift]LeetCode719. 找出第 k 小的距离对 | Find K-th Smallest Pair Distance

    Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pai ...