[integer-sqrt] use abstract def of integer_sqrt

This commit is contained in:
Danny Ryan 2018-09-30 11:50:44 -05:00
parent ec1eee4133
commit 4cb9790ea8
1 changed files with 5 additions and 9 deletions

View File

@ -298,19 +298,15 @@ def get_block_hash(active_state, curblock, slot):
`get_block_hash(*, *, h)` should always return the block in the chain at slot `h`, and `get_shards_and_committees_for_slot(*, h)` should not change unless the dynasty changes. `get_block_hash(*, *, h)` should always return the block in the chain at slot `h`, and `get_shards_and_committees_for_slot(*, h)` should not change unless the dynasty changes.
Finally, we define `integer_sqrt` for use in reward/penalty calculations: Finally, we abstractly define `integer_sqrt` for use in reward/penalty calculations:
```python ```python
def integer_sqrt(n): def integer_sqrt(n):
# Utilizes "Newton's Method" return max(n in Z: n**2 <= x)
x = n
y = (x + 1) // 2
while y < x:
x = y
y = (x + n // x) // 2
return x
``` ```
We leave `integer_sqrt` implementation details to each particular language/framework.
### On startup ### On startup
* Let `x = get_new_shuffling(bytes([0] * 32), validators, 1, 0)` and set `crystallized_state.shard_and_committee_for_slots` to `x + x` * Let `x = get_new_shuffling(bytes([0] * 32), validators, 1, 0)` and set `crystallized_state.shard_and_committee_for_slots` to `x + x`