Merge pull request #1410 from wemeetagain/patch-3

sync protocol: clarify committee type
This commit is contained in:
Danny Ryan 2019-10-28 15:26:31 +08:00 committed by GitHub
commit 913a231a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -39,8 +39,8 @@ We define the following Python custom types for type hinting and readability:
| - | - | | - | - |
| `BEACON_CHAIN_ROOT_IN_SHARD_BLOCK_HEADER_DEPTH` | `4` | | `BEACON_CHAIN_ROOT_IN_SHARD_BLOCK_HEADER_DEPTH` | `4` |
| `BEACON_CHAIN_ROOT_IN_SHARD_BLOCK_HEADER_INDEX` | **TBD** | | `BEACON_CHAIN_ROOT_IN_SHARD_BLOCK_HEADER_INDEX` | **TBD** |
| `PERSISTENT_COMMITTEE_ROOT_IN_BEACON_STATE_DEPTH` | `5` | | `PERIOD_COMMITTEE_ROOT_IN_BEACON_STATE_DEPTH` | `5` |
| `PERSISTENT_COMMITTEE_ROOT_IN_BEACON_STATE_INDEX` | **TBD** | | `PERIOD_COMMITTEE_ROOT_IN_BEACON_STATE_INDEX` | **TBD** |
## Containers ## Containers
@ -56,9 +56,9 @@ class LightClientUpdate(container):
# Updated beacon header (and authenticating branch) # Updated beacon header (and authenticating branch)
header: BeaconBlockHeader header: BeaconBlockHeader
header_branch: Vector[Hash, BEACON_CHAIN_ROOT_IN_SHARD_BLOCK_HEADER_DEPTH] header_branch: Vector[Hash, BEACON_CHAIN_ROOT_IN_SHARD_BLOCK_HEADER_DEPTH]
# Updated persistent committee (and authenticating branch) # Updated period committee (and authenticating branch)
committee: CompactCommittee committee: CompactCommittee
committee_branch: Vector[Hash, PERSISTENT_COMMITTEE_ROOT_IN_BEACON_STATE_DEPTH + log_2(SHARD_COUNT)] committee_branch: Vector[Hash, PERIOD_COMMITTEE_ROOT_IN_BEACON_STATE_DEPTH + log_2(SHARD_COUNT)]
``` ```
## Helpers ## Helpers
@ -70,7 +70,7 @@ class LightClientUpdate(container):
class LightClientMemory(object): class LightClientMemory(object):
shard: Shard # Randomly initialized and retained forever shard: Shard # Randomly initialized and retained forever
header: BeaconBlockHeader # Beacon header which is not expected to revert header: BeaconBlockHeader # Beacon header which is not expected to revert
# Persistent committees corresponding to the beacon header # period committees corresponding to the beacon header
previous_committee: CompactCommittee previous_committee: CompactCommittee
current_committee: CompactCommittee current_committee: CompactCommittee
next_committee: CompactCommittee next_committee: CompactCommittee
@ -137,13 +137,13 @@ def update_memory(memory: LightClientMemory, update: LightClientUpdate) -> None:
domain = compute_domain(DOMAIN_SHARD_ATTESTER, update.fork_version) domain = compute_domain(DOMAIN_SHARD_ATTESTER, update.fork_version)
assert bls_verify(pubkey, update.shard_block_root, update.signature, domain) assert bls_verify(pubkey, update.shard_block_root, update.signature, domain)
# Update persistent committees if entering a new period # Update period committees if entering a new period
if next_period == current_period + 1: if next_period == current_period + 1:
assert is_valid_merkle_branch( assert is_valid_merkle_branch(
leaf=hash_tree_root(update.committee), leaf=hash_tree_root(update.committee),
branch=update.committee_branch, branch=update.committee_branch,
depth=PERSISTENT_COMMITTEE_ROOT_IN_BEACON_STATE_DEPTH + log_2(SHARD_COUNT), depth=PERIOD_COMMITTEE_ROOT_IN_BEACON_STATE_DEPTH + log_2(SHARD_COUNT),
index=PERSISTENT_COMMITTEE_ROOT_IN_BEACON_STATE_INDEX << log_2(SHARD_COUNT) + memory.shard, index=PERIOD_COMMITTEE_ROOT_IN_BEACON_STATE_INDEX << log_2(SHARD_COUNT) + memory.shard,
root=hash_tree_root(update.header), root=hash_tree_root(update.header),
) )
memory.previous_committee = memory.current_committee memory.previous_committee = memory.current_committee