Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
share
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄刚
share
Commits
87ebcca6
Commit
87ebcca6
authored
Nov 02, 2018
by
黄刚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加共识模块文档
parent
ece86020
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
0 deletions
+74
-0
Consensus_ctx.png
resources/Consensus_ctx.png
+0
-0
共识模块.md
共识模块.md
+74
-0
No files found.
resources/Consensus_ctx.png
0 → 100644
View file @
87ebcca6
12.7 KB
共识模块.md
0 → 100644
View file @
87ebcca6
# 共识模块
# 共识模块
## 1.模块介绍
共识模块是实现区块链共识机制的模块,共识机制是区块链技术的重要组件。区块链共识机制的目标是使所有的诚实节点保存一致的区块链视图,同时满足两个性质:
-
**一致性**
:所有诚实节点保存的区块链的前缀部分完全相同。
-
**有效性**
:由某诚实节点发布的信息终将被其他所有诚实节点记录在自己的区块链中。
通俗来说,共识机制在区块链网络内起到决定谁负责生成新区块以及维护区块链统一的作用。
目前区块链的共识机制大致可以分为PoW(Proof of Work 工作量证明)、PoS(Proof of Stack 权益证明)、DPoS(Delegated Proof of Stake 委托权益证明)以及分布式一致性算法几类。
## 2.逻辑架构及上下文
*共识模块上下文*
目前chain33系统中的共识模块是可插拔的,支持平行链共识,PBFT,Raft,Tendermint,Ticket几种共识算法。共识模块在整个chain33系统中所处的地位如下图:

共识模块是连接交易与区块的桥梁,作用主要体现在推动区块的产生。所有由共识模块发出的事件都是实现这一目标。
*注:EventBlockChainQuery事件除外,在该模块中此事件只与Tendermint共识的动态增加,删除Validator节点功能有关。*
为实现这一目标分成如下几步:
1.
同步区块高度:通过向Blockchain模块发送EventIsSync事件,得到当前区块高度是否已经与主链高度一致,如果一致,则可以参与新高度区块的共识过程;否则,继续等待同步到最新高度。
1.
获取交易:通过向Mempool模块发送EventTxList事件触发,获取需要打包进区块的交易。
2.
交易共识:对这些将要打包的交易进行验证,并确定哪个节点负责生成新区块。
3.
产生新区块:通过向Blockchain模块发送EventAddBlockDetail事件触发。
4.
删除错误交易:通过向Mempool模块发送EventDelTxList事件触发。
*注:EventGetBlocks用于向Blockchain模块获取指定高度范围的区块,EventGetLastBlock事件用于向Blockchain模块获取最新的区块。*
共识模块与chain33系统的耦合体现在两个接口:
-
Module:
```
/// Module be used for module interface
type Module interface {
SetQueueClient(client Client)
Close()
}
```
SetQueueClient主要完成如下功能:
1.
设置消息队列Client
2.
初始化本地区块
3.
订阅消息并开始消息循环
4.
开启共识过程
Close:关闭退出共识
-
Miner
```
type Miner interface {
CreateGenesisTx() []*types.Transaction
GetGenesisBlockTime() int64
CreateBlock()
CheckBlock(parent *types.Block, current *types.BlockDetail) error
ProcEvent(msg queue.Message) bool
}
```
CreateGenesisTx:创建创世区块交易
GetGenesisBlockTime:获取创世区块时间
CreateBlock:获取交易,打包区块
CheckBlock:通过父区块检查当前区块是否有效
ProcEvent:处理除BaseClient处理的事件以外的其他事件
## 3.处理逻辑
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment