Nervos Fans

Casper+Sharding链 规范 V2.1(二)

2018-09-04  本文已影响0人  526ba0512193

每晚八点,我们在社区分享知识,等你。

NervosFans 微信公号:Nervosfans

入群请加乐乐微信:sensus113 美果大冰微信:xj73226

备注入群,谢谢!


辅助函数

先来定义一些辅助算法。首先,选择活跃验证人的函数:

然后是置乱该列表的函数:

以下为将列表分成N份的函数:

合并上述函数,就是辅助函数了:

用图片表示下原理:

还要定义:

get_block_hash(*, *, h)应总在时隙h返回链内区块,且除非代变更,否则get_indices_for_slot(*, h)不应改变。

启动阶段

1. 令x = get_new_shuffling(bytes([0] * 32), validators, 1, 0),设置crystallized_state.indices_for_slotsx + x

2. 设置crystallized_state.dynasty = 1

3. 设置crystallized_state.crosslink_records 为[CrosslinkRecord(dynasty=0, hash= bytes([0] * 32)) for i in range(SHARD_COUNT)]

4. 设置total_depositssum([x.balance for x in validators]) 

5. 设置recent_block_hashes为[bytes([0] * 32) for _ in  range(CYCLE_LENGTH * 2)]

根据实际情况,活跃和结晶状态中的其他值可设置为零或空数组。

单块处理(Per-block processing

首先,设置recent_block_hashes为以下的输出:

get_block_hash的输出不变,除了不再为current_slot - 1抛出,但会为current_slot - CYCLE_LENGTH * 2 – 1抛出。

一个区块可以有0或更多AttestationRecord对象,其中每个AttestationRecord对象都有以下字段:

每个证明[未完]:

1. 验证slot < block.slot_number以及slot >=max(block.slot_number - CYCLE_LENGTH, 0)

2. 验证给定justified_slot和justified_block_hash是否在链中并且等于或早于结晶状态中的last_justified_slot

3. 为范围内的i计算parent_hashes = [get_block_hash(active_state, block, slot - CYCLE_LENGTH + i) for i in range(CYCLE_LENGTH - len(oblique_parent_hashes))] + oblique_parent_hashes

4. 令attestation_indicesget_indices_for_slot(crystallized_state, slot)[x],选择x使得attestation_indices.shard_id等于提供的shard_id值,以查找创建此证明记录的验证人集。

5. 验证len(attester_bitfield) == ceil_div8(len(attestation_indices)),其中ceil_div8 = (x + 7) // 8。验证len(attestation_indices)....及更高位(若存在,譬如len(attestation_indices)不是8的倍数),是否为都为零

6. 通过在attestation_indices中添加所有证明者的公钥导出组公钥,在attester_bitfield中的相应位(第i位为(attester_bitfield[i // 8] >> (7 - (i %8))) % 2))等于1

7. 验证aggregate_sig对使用生成的组pubkey和hash(slot.to_bytes(8, 'big') + parent_hashes + shard_id + shard_block_hash)作为消息进行了验证。

扩展active_state中的AttestationRecord对象列表,按照其进入区块的顺序对新的添加项进行排序。

验证get_indices_for_slot(crystallized_state, slot)[0]中的第slot % len(get_indices_for_slot(crystallized_state, slot)[0])个证明人至少是一个AttestationRecord对象的一部分;该证明人可视为该区块的提议人。

状态重算

slot - last_state_recalc >= CYCLE_LENGTH重复:

对于全部时隙,last_state_recalc - CYCLE_LENGTH ... last_state_recalc – 1中的 s

1. 确定至少证实该块一次的总验证人集

2. 确定这些验证人的总余额。该数值乘以2等于或大于所有有效验证人的总余额乘以2时,设置last_justified_slot = max(last_justified_slot, s)和justified_streak + = 1。不然,设置 justified_streak = 0

3. justified_streak>= CYCLE_LENGTH + 1时,设置last_finalized_slot = max(last_finalized_slot, s - CYCLE_LENGTH - 1)

4. 删除所有时间早于时隙last_state_recalc的证明记录

另外:

1. 设置last_state_recalc + = CYCLE_LENGTH

2. 设置indices_for_slots[:CYCLE_LENGTH] = indices_for_slots[CYCLE_LENGTH:]

对于所有(shard_id, shard_block_hash)元组,计算出该分片中证实该区块哈希的验证人总押金大小。该值(总押金)乘以3等于或大于委员会中所有验证人的总余额乘以2,且当前代超过 crosslink_records[shard_id].dynasty时,设置 crosslink_records[shard_id] = CrosslinkRecord(dynasty=current_dynasty, hash=shard_block_hash)

待完成:

FFG参与奖励

委员会参与奖励

代迁移

待完成。


注:本规范目前的完成进度约70%,未完成的主要章节包括:

1. 验证人登录/退出逻辑

2. 分片链格式的逻辑,由谁提出分片区块等(初始发布中,需要时,交联可以是数据块的Merkle根;point is分片链的作用可视为一种协调选择哪个数据块提作交联的设计。)

3. 从主链引入排队验证人的逻辑

4. 签署或证明非规范链区块的处罚(参见https://ethresear.ch/t/attestation-committee-based-full-pos-chains/2259

5. 惩罚(Slashing)条件

6. 押金提现到分片的逻辑

7. 每个验证人的监护证明

8. 完整奖励与处罚

9. 版本化和升级

Slashing条件可能包含:

Casper FFGslot equivocation/时隙疑议

Casper FFGsurround/环境

Beacon chain proposal equivocation/信标链提议疑议

Shard chain proposal equivocation/分片链提议疑议

Proof of custody secret leak/监护证明秘密泄露

Proof of custody wrong custody bit/监护证明错误监护位

Proof of custody no secret reveal/监护证明秘密揭露

RANDAO leak/RANDAO泄露


https://notes.ethereum.org/SCIg8AH5SA-O4C1G1LYZHQ

上一篇下一篇

猜你喜欢

热点阅读