升级Tendermint

项目中用Tendermint做共识,发展到了一定阶段,想着要升级下Tendermint,虽然现在也能用,但是最好跟着官方的步伐, 跟之前Android升级一个道理。

之前我们使用的是0.15的版本,目前最新的稳定release是0.28,直接把我们使用的tendermint换成最新的,然后解决编译问题。

费尽的解决一大堆编译问题,有一个涉及到app的改动不太好改,就直接倒回到0.23版本没有改动到这个地方的。

0.23较0.15的一些大改动:

1 把go-crypto和abci以及tmlibs三个git合并到tendermint git内,分别为crypto、abci和libs目录

2 abci改动的不算大,主要是PubKey增加了一个type字段(默认用的是ed25519,我们改成了secp256k1),所有对应的地方都要改

然后再把我们自己的改动patch打上去

其他的是内部的改动,先介绍下P2P

 

Tendermint P2P

新版config.toml改动比较大,能配置的config都配到这里了。关于p2p以前只有一个seeds选项,现在加了一个persistent_peers选项,看下官方解释

#### Seed

A seed node is a node who relays the addresses of other peers which they know
of. These nodes constantly crawl the network to try to get more peers. The
addresses which the seed node relays get saved into a local address book. Once
these are in the address book, you will connect to those addresses directly.
Basically the seed nodes job is just to relay everyones addresses. You won't
connect to seed nodes once you have received enough addresses, so typically you
only need them on the first start. The seed node will immediately disconnect
from you after sending you some addresses.

#### Persistent Peer

Persistent peers are people you want to be constantly connected with. If you
disconnect you will try to connect directly back to them as opposed to using
another address from the address book. On restarts you will always try to
connect to these peers regardless of the size of your address book.

All peers relay peers they know of by default. This is called the peer exchange
protocol (PeX). With PeX, peers will be gossipping about known peers and forming
a network, storing peer addresses in the addrbook. Because of this, you don't
have to use a seed node if you have a live persistent peer.

Seed

这个是种子节点的意思,要配合seed_mode使用,如果节点的seed_mode为true,代表这个节点是种子节点,其他节点连上它一定时间后就会断开(默认30s),节点通过种子节点获取到其他节点,连上就可以工作。

这个也解释了节点怎么入网的问题。普通节点要连入网络,需要seeds填写官方公布的节点信息,然后就会被种子节点带入网络。

Persistent Peer

字面意思:持久的节点,正如字面所示,这个是长连接的节点,自己会一直试图跟persistent节点保持连接,断掉也会再重连。

 

怎么填写

如果是共识节点,那么彼此需要填写对方到persistent_peers,保持大家一直长连接。

如果是普通节点,那么只需要填写对方的$ID@$IP:$PORT到seeds即可;或者填写官方的节点信息,自然会被带入网络

 

节点ID

新版本还加了一个节点id信息,这个id是节点的公钥。

以前节点是IP:PORT的形式,现在需要ID@IP:PORT,要连接对方节点,需要先知道对方的节点ID。

以前的节点格式:

192.168.8.111:26657

现在的节点格式:

e80e67561bbaf7f53cf1c2c44988c348683e1cac@192.168.8.111:26657

初始化的时候在数据目录的config目录会生成一个node_key.json文件,这个里面默认是节点的私钥,可以根据私钥拿到公钥,就是ID。

比较奇怪的是为什么不默认把ID写在node_key.json里面,自己还得另外算一下,不方便使用。我自己打了个patch把ID生成在node_key.json中,node_key.json内容:

{"priv_key":
   {
   "type":"tendermint/PrivKeyEd25519",
"value":"GrkhDmZu/POY4hBlIcREcoZEuDCJHUSA+SQiG+l1sq/h2biA9vnMGRn5v6dQciBK6o1UcUUQVCAzR+Svp0BhVA=="
   },
   "id":"e80e67561bbaf7f53cf1c2c44988c348683e1cac"
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值