关于最长链准则的两个考量 by cifer

View this thread on steempeak.com
· @cifer ·
$11.56
关于最长链准则的两个考量
假设有 a, b, c 三个见证人轮流出块, 他们在出块的过程中可能会碰到如下的一些窘境.

首先是最简单的情况:

 ![](https://cdn.steemitimages.com/DQmaPYAsjRMQPd5WLpQhKQR4NAcTPannBnFPD8t9ZTaB8L8/image.png)

a, b, c 第一轮出块很完美, 第二轮开始 a 基于 c 出块, 依然正常. 但是 b 可能恰好 c 和 a 的块他都没收到, 也可能是它自己确实是坏人, 总之这第二轮它的块指向了自己在第一轮出的块. 接下来 c 出块时 (假设 c 正常收到了所有消息), 他看到的就是图上这番景象. 那么它出块应当基于 a 区块还是 b 区块呢? 根据最长链准则, 显然它应当基于 a 区块出.

这里我们讨论一个细节, 就是 c 怎么判断它看到的 a 和 b 谁的高度比较高. 分别从 a, b 往前推到头来计数肯定是很慢的, 所以在我们的实现中高度信息也会写到区块中. 那么问题又来了, 如果高度写到区块里, 那 b 在第二轮出块的时候把自己的块高度写的比较大不就行了吗? 当然是不行的, 在我们的实现中, 见证人收到每个块是都会验证前一个块在不在, 以及验证前一个块的高度是不是只比收到的块小 1, 如果不是的话, 块会被拒绝.

上面说的是最基本的情况, 下面是一个相对复杂一点的情况, 就是当轮到某个节点出块时, 它发现当前有两个块高度一样, 它不知道自己的块应该指向这两个块中的哪个.

这个情况的产生可能是由于 c 没有收到 b 的区块, 于是在 c 出块时 c 看到的只有 a 区块, 于是就继续在 a 后面出, 而 a 是成功收到了 b 和 c 的区块的. 于是再到 a 出块时, a 就会看到 b, c 高度都是 2, 并且都指向自己第一次出的块.

 ![](https://cdn.steemitimages.com/DQmUTH4xaGnyiXQsEYMUy8dnf3fdrjdnYVZpUD5vwA5gucU/image.png)

这个窘境怎么解呢? 我们规定, 但出现两个长度相同的链时, 见证人应当基于较早 (可以比较两个块的时间戳, 或者比较两个块出块人在见证人列表中的先后次序) 接收到的块出块. 这里显然 b 是较早接收到的块, 于是 a 这次出块应当基于 b 区块出.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 54 others
properties (23)
post_id63,807,692
authorcifer
permlink5wmzpt
categorycn-programming
json_metadata{"app":"steemit\/0.1","format":"markdown","tags":["cn-programming","cn-reader","cn","bitshares","dpos"],"image":["https:\/\/cdn.steemitimages.com\/DQmaPYAsjRMQPd5WLpQhKQR4NAcTPannBnFPD8t9ZTaB8L8\/image.png"]}
created2018-10-07 11:27:33
last_update2018-10-07 11:27:33
depth0
children4
net_rshares7,548,040,969,807
last_payout2018-10-14 11:27:33
cashout_time1969-12-31 23:59:59
total_payout_value8.747 SBD
curator_payout_value2.808 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,004
author_reputation7,963,630,681,040
root_title关于最长链准则的两个考量
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (118)
@britcoins ·
$0.03
hmmm ... any link to an english version perhaps?
:_)
👍  , , , ,
properties (23)
post_id63,872,610
authorbritcoins
permlinkre-cifer-5wmzpt-20181008t123827980z
categorycn-programming
json_metadata{"app":"steemit\/0.1","tags":["cn-programming"]}
created2018-10-08 12:38:33
last_update2018-10-08 12:38:33
depth1
children2
net_rshares22,208,573,593
last_payout2018-10-15 12:38:33
cashout_time1969-12-31 23:59:59
total_payout_value0.024 SBD
curator_payout_value0.006 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length52
author_reputation3,090,295,432,513
root_title关于最长链准则的两个考量
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars0
author_curate_reward""
vote details (5)
@cifer · (edited)
$0.04
oh sorry.. not good at english. i am trying hard
👍  , ,
properties (23)
post_id63,888,934
authorcifer
permlinkre-britcoins-re-cifer-5wmzpt-20181008t175412580z
categorycn-programming
json_metadata{"tags":["cn-programming"],"app":"steemit\/0.1"}
created2018-10-08 17:54:15
last_update2018-10-08 17:54:39
depth2
children1
net_rshares25,841,230,482
last_payout2018-10-15 17:54:15
cashout_time1969-12-31 23:59:59
total_payout_value0.028 SBD
curator_payout_value0.007 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length48
author_reputation7,963,630,681,040
root_title关于最长链准则的两个考量
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (3)
@britcoins · (edited)
because you use the tag #bitshares, I wonder why ... :) 
you can try @bangzi, he translates EN-CN
properties (22)
post_id64,128,409
authorbritcoins
permlinkre-cifer-re-britcoins-re-cifer-5wmzpt-20181012t162049477z
categorycn-programming
json_metadata{"tags":["cn-programming","bitshares"],"app":"steemit\/0.1","users":["bangzi"]}
created2018-10-12 16:20:48
last_update2018-10-12 16:21:09
depth3
children0
net_rshares0
last_payout2018-10-19 16:20:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length97
author_reputation3,090,295,432,513
root_title关于最长链准则的两个考量
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars0
@imransoory · (edited)
tremendous work. keep it up ♥
properties (22)
post_id64,152,718
authorimransoory
permlinkre-cifer-5wmzpt-20181013t030703581z
categorycn-programming
json_metadata{"app":"steemit\/0.1","tags":["cn-programming"]}
created2018-10-13 03:07:06
last_update2018-10-13 03:07:45
depth1
children0
net_rshares0
last_payout2018-10-20 03:07:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length29
author_reputation50,634,257,333,295
root_title关于最长链准则的两个考量
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000