[integer-sqrt] add integer_sqrt helper function and use in rewards calculations
This commit is contained in:
parent
5cfa735482
commit
82ec8dfdc2
|
@ -282,7 +282,7 @@ Here's a diagram of what's going on:
|
|||
|
||||
![](http://vitalik.ca/files/ShuffleAndAssign.png?1)
|
||||
|
||||
We also define:
|
||||
We also define two functions retrieving data from the state:
|
||||
|
||||
```python
|
||||
def get_shards_and_committees_for_slot(crystallized_state, slot):
|
||||
|
@ -298,6 +298,18 @@ 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.
|
||||
|
||||
Finally, we define `integer_sqrt` for use in reward/penalty calculations:
|
||||
|
||||
```python
|
||||
def integer_sqrt(n):
|
||||
x = n
|
||||
y = (x + 1) // 2
|
||||
while y < x:
|
||||
x = y
|
||||
y = (x + n // x) // 2
|
||||
return x
|
||||
```
|
||||
|
||||
### 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`
|
||||
|
@ -375,7 +387,7 @@ For all (`shard_id`, `shard_block_hash`) tuples, compute the total deposit size
|
|||
Let `time_since_finality = block.slot_number - last_finalized_slot`, and let `B` be the balance of any given validator whose balance we are adjusting, not including any balance changes from this round of state recalculation. Let:
|
||||
|
||||
* `total_deposits = sum([v.balance for i, v in enumerate(validators) if i in get_active_validator_indices(validators, current_dynasty)])` and `total_deposits_in_ETH = total_deposits // 10**18`
|
||||
* `reward_quotient = BASE_REWARD_QUOTIENT * int(sqrt(total_deposits_in_ETH))` (1/this is the per-slot max interest rate)
|
||||
* `reward_quotient = BASE_REWARD_QUOTIENT * integer_sqrt(total_deposits_in_ETH)` (1/this is the per-slot max interest rate)
|
||||
* `quadratic_penalty_quotient = (SQRT_E_DROP_TIME / SLOT_DURATION)**2` (after D slots, ~D<sup>2</sup>/2 divided by this is the portion lost by offline validators)
|
||||
|
||||
For each slot `S` in the range `last_state_recalc - CYCLE_LENGTH ... last_state_recalc - 1`:
|
||||
|
|
Loading…
Reference in New Issue