From 17fd4c766935116b40d8fca505b5b93cd7c281d2 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 17 Oct 2018 19:00:45 -0700 Subject: [PATCH 1/8] add code representation of utility function described in text for style consistency --- specs/beacon-chain.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index c22b71a24..3e81bc8b2 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -550,7 +550,19 @@ The `CrystallizedState()` and `ActiveState()` constructors should initialize all ### Routine for adding a validator -This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. These logs should be processed in the order in which they are emitted by the PoW chain. Define `min_empty_validator(validators)` as a function that returns the lowest validator index `i` such that `validators[i].status == WITHDRAWN`, otherwise `None`. +This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. These logs should be processed in the order in which they are emitted by the PoW chain. + +First, a helper function: + +```python +def min_empty_validator(validators: List[ValidatorRecord]): + for i, v in enumerate(validators): + if v.status == WITHDRAWN: + return i + return None +``` + +Now, to add a validator: ```python def add_validator(validators: List[ValidatorRecord], From bfe4caa379883be7a9064b61da5294b54597e176 Mon Sep 17 00:00:00 2001 From: Yutaro Mori Date: Sat, 20 Oct 2018 17:07:45 +0900 Subject: [PATCH 2/8] minor typo --- specs/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 3e81bc8b2..1495419e3 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -682,7 +682,7 @@ For every `(shard, shard_block_hash)` tuple: * Let `total_balance_attesting_to_h` be the total balance of validators that attested to the shard block with hash `shard_block_hash`. * Let `total_committee_balance` be the total balance in the committee of validators that could have attested to the shard block with hash `shard_block_hash`. -* If `3 * total_balance_attesting_to_h >= 2 * total_committee_balance` and `recently_changed is False`, set `crosslinks[shard] = CrosslinkRecord(recently_changed=True, slot=block.last_state_recalculation_slot + CYCLE_LENGTH, hash=shard_block_hash)`. +* If `3 * total_balance_attesting_to_h >= 2 * total_committee_balance` and `recently_changed is False`, set `crosslinks[shard] = CrosslinkRecord(recently_changed=True, slot=last_state_recalculation_slot + CYCLE_LENGTH, hash=shard_block_hash)`. #### Balance recalculations related to FFG rewards From 40d0076b27411dfe71fe0548db6f433a1e11ae1e Mon Sep 17 00:00:00 2001 From: terence tsao Date: Mon, 22 Oct 2018 13:11:54 -0700 Subject: [PATCH 3/8] clean up possible rework/additions --- specs/beacon-chain.md | 1 - 1 file changed, 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 1495419e3..9cbc7aa51 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -837,7 +837,6 @@ Note: This spec is ~60% complete. * [ ] Reduce the slot duration to 8 seconds * [ ] Allow for the delayed inclusion of aggregated signatures * [ ] Use a separate networking-optimised serialisation format for networking -* [ ] Harden RANDAO against orphaned reveals * [ ] Introduce a RANDAO slashing condition for early leakage * [ ] Use a separate hash function for the proof of possession * [ ] Rework the `ShardAndCommittee` data structures From 203eeba2b6ef48fb2f5225fa3fffa7265028418b Mon Sep 17 00:00:00 2001 From: terence tsao Date: Wed, 24 Oct 2018 09:04:40 -0700 Subject: [PATCH 4/8] update change_validator --- specs/beacon-chain.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 9cbc7aa51..82a04a423 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -503,7 +503,8 @@ def on_startup(initial_validator_entries: List[Any]) -> Tuple[CrystallizedState, withdrawal_shard=withdrawal_shard, withdrawal_address=withdrawal_address, randao_commitment=randao_commitment, - current_slot=0 + current_slot=0, + status=ACTIVE, ) # Setup crystallized state x = get_new_shuffling(bytes([0] * 32), validators, 0) @@ -550,7 +551,7 @@ The `CrystallizedState()` and `ActiveState()` constructors should initialize all ### Routine for adding a validator -This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. These logs should be processed in the order in which they are emitted by the PoW chain. +This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. The status of the validators will be PENDING_ACTIVE. These logs should be processed in the order in which they are emitted by the PoW chain. First, a helper function: @@ -571,6 +572,7 @@ def add_validator(validators: List[ValidatorRecord], withdrawal_shard: int, withdrawal_address: Address, randao_commitment: Hash32, + status: uint8, current_slot: int) -> int: # if following assert fails, validator induction failed # move on to next validator registration log @@ -584,7 +586,7 @@ def add_validator(validators: List[ValidatorRecord], randao_commitment=randao_commitment, randao_last_change=current_slot, balance=DEPOSIT_SIZE * GWEI_PER_ETH, # in Gwei - status=PENDING_ACTIVATION, + status=status, exit_slot=0 ) index = min_empty_validator(validators) From 9064cfaddbb481a6756608cffdf45f89442385d0 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Wed, 24 Oct 2018 10:14:24 -0700 Subject: [PATCH 5/8] use int for type hints --- specs/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 82a04a423..855b6b651 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -572,7 +572,7 @@ def add_validator(validators: List[ValidatorRecord], withdrawal_shard: int, withdrawal_address: Address, randao_commitment: Hash32, - status: uint8, + status: int, current_slot: int) -> int: # if following assert fails, validator induction failed # move on to next validator registration log From e3931f1e725c3fca342ad2cad5fa6e49fc75dfad Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 25 Oct 2018 09:43:47 +0200 Subject: [PATCH 6/8] minor type/clarification in adding validator --- specs/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 855b6b651..6de5b40f2 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -551,7 +551,7 @@ The `CrystallizedState()` and `ActiveState()` constructors should initialize all ### Routine for adding a validator -This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. The status of the validators will be PENDING_ACTIVE. These logs should be processed in the order in which they are emitted by the PoW chain. +This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. The status of the validators added after genesis is `PENDING_ACTIVATION`. These logs should be processed in the order in which they are emitted by the PoW chain. First, a helper function: From ff81a3032fa5422e2f47393b8cc3f0e8638e019f Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 25 Oct 2018 15:51:24 +0200 Subject: [PATCH 7/8] fix small error in comment --- specs/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 6de5b40f2..6c967a8e4 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -146,7 +146,7 @@ An `AttestationSignedData` has the following fields: 'slot': 'uint64', # Shard number 'shard': 'uint16', - # 31 parent hashes + # CYCLE_LENGTH parent hashes 'parent_hashes': ['hash32'], # Shard block hash 'shard_block_hash': 'hash32', From 0064043e141efa39471a011c49aa3614a753012e Mon Sep 17 00:00:00 2001 From: mratsim Date: Sat, 27 Oct 2018 13:36:10 +0200 Subject: [PATCH 8/8] Mention that lists are of elements of homegeneous type --- specs/simple-serialize.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index be58a68dd..f508e8298 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -186,6 +186,8 @@ return byte_length + value #### List/Vectors +Lists are a collection of elements of the same homogeneous type. + | Check to perform | Code | |:--------------------------------------------|:----------------------------| | Length of serialized list fits into 4 bytes | ``len(serialized) < 2**32`` | @@ -327,7 +329,7 @@ return rawbytes[bytes_start:bytes_end], new_index #### List/Vectors -Deserialize each object in the list. +Deserialize each element in the list. 1. Get the length of the serialized list. 2. Loop through deserializing each item in the list until you reach the entire length of the list.