Update 0_beacon-chain.md

This commit is contained in:
Justin 2019-03-12 10:02:52 +00:00 committed by GitHub
parent bf6bdbb021
commit a7544864d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 16 deletions

View File

@ -203,10 +203,10 @@ Code snippets appearing in `this style` are to be interpreted as Python code.
| Name | Value | Unit | | Name | Value | Unit |
| - | - | :-: | | - | - | :-: |
| `MIN_DEPOSIT_AMOUNT` | `10**9` (= 1,000,000,000) | Gwei | | `MIN_DEPOSIT_AMOUNT` | `2**0 * 10**9` (= 1,000,000,000) | Gwei |
| `MAX_DEPOSIT_AMOUNT` | `2**5 * 10**9` (= 32,000,000,000) | Gwei | | `MAX_DEPOSIT_AMOUNT` | `2**5 * 10**9` (= 32,000,000,000) | Gwei |
| `EJECTION_BALANCE` | `2**4 * 10**9` (= 16,000,000,000) | Gwei | | `EJECTION_BALANCE` | `2**4 * 10**9` (= 16,000,000,000) | Gwei |
| `HIGH_BALANCE_INCREMENT` | `10**9` (= 1,000,000,000) | Gwei | | `HIGH_BALANCE_INCREMENT` | `2**0 * 10**9` (= 1,000,000,000) | Gwei |
### Initial values ### Initial values
@ -440,7 +440,7 @@ The types are defined topologically to aid in facilitating an executable version
# Was the validator slashed # Was the validator slashed
'slashed': 'bool', 'slashed': 'bool',
# Rounded balance # Rounded balance
'high_balance': 'uint32' 'high_balance': 'uint64'
} }
``` ```
@ -756,25 +756,17 @@ def get_active_validator_indices(validators: List[Validator], epoch: Epoch) -> L
```python ```python
def get_balance(state: BeaconState, index: int) -> int: def get_balance(state: BeaconState, index: int) -> int:
return ( return state.validator_registry[index].high_balance + state.low_balances[index]
state.validator_registry[index].high_balance * HIGH_BALANCE_INCREMENT +
state.low_balances[index]
)
``` ```
#### `set_balance` #### `set_balance`
````python ````python
def set_balance(state: BeaconState, index: int, new_balance: int) -> None: def set_balance(state: BeaconState, index: int, balance: int) -> None:
validator = state.validator_registry[index] validator = state.validator_registry[index]
HALF_INCREMENT = HIGH_BALANCE_INCREMENT // 2 HALF_INCREMENT = HIGH_BALANCE_INCREMENT // 2
if ( if validator.high_balance > balance or validator.high_balance + 3 * HALF_INCREMENT < balance:
validator.high_balance * HIGH_BALANCE_INCREMENT > new_balance or validator.high_balance = balance - balance % HIGH_BALANCE_INCREMENT
validator.high_balance * HIGH_BALANCE_INCREMENT + HALF_INCREMENT * 3 < new_balance state.low_balances[index] = balance - validator.high_balance
):
validator.high_balance = new_balance // HIGH_BALANCE_INCREMENT
state.low_balances[index] = (
new_balance - validator.high_balance * HIGH_BALANCE_INCREMENT
)
```` ````
#### `increase_balance` #### `increase_balance`