最近采用GO语言实现了一个PBFT共识算法的demo,主要用于展示算法的核心逻辑
github地址:https://github.com/w3liu/consensus/tree/master/pbft
1. 主节点定时出块(每1秒钟)
2. 共识流程:
* propose - 主节点提议
* vote - 从节点投票
* preCommit - 所有节点预提交
* commit - 提交,流程结束,进入下一个区块
3. 编译
```
make clean
make
```
4. 启动主节点
```
./pbft -c=./config/config.toml
```
5. 启动从节点
```
./pbft -c=./config/config1.toml
./pbft -c=./config/config2.toml
./pbft -c=./config/config3.toml
```
6. 输出
```
{"level":"info","ts":1600916693.3426318,"caller":"log/zap.go:20","msg":"block commit","height":1,"data":"This is a block data, height is 1."}
{"level":"info","ts":1600916703.341808,"caller":"log/zap.go:20","msg":"block commit","height":2,"data":"This is a block data, height is 2."}
{"level":"info","ts":1600916713.339083,"caller":"log/zap.go:20","msg":"block commit","height":3,"data":"This is a block data, height is 3."}
{"level":"info","ts":1600916723.3332858,"caller":"log/zap.go:20","msg":"block commit","height":4,"data":"This is a block data, height is 4."}
{"level":"info","ts":1600916733.341336,"caller":"log/zap.go:20","msg":"block commit","height":5,"data":"This is a block data, height is 5."}
...
```