Merge pull request #25 from ethereum/constants-readability

Rework the constants for readability
This commit is contained in:
Danny Ryan 2018-10-03 08:29:50 -05:00 committed by GitHub
commit f6c1b6c744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 52 additions and 35 deletions

View File

@ -19,43 +19,60 @@ Note that one can also consider a simpler "minimal sharding algorithm" where cro
Note: the python code at https://github.com/ethereum/beacon_chain and [an ethresear.ch post](https://ethresear.ch/t/convenience-link-to-full-casper-chain-v2-spec/2332) do not reflect all of the latest changes. If there is a discrepancy, this document is likely to reflect the more recent changes. Note: the python code at https://github.com/ethereum/beacon_chain and [an ethresear.ch post](https://ethresear.ch/t/convenience-link-to-full-casper-chain-v2-spec/2332) do not reflect all of the latest changes. If there is a discrepancy, this document is likely to reflect the more recent changes.
### Glossary ### Terminology
* **Validator**—a participant in the Ethereum 2.0 consensus system with the right to produce blocks, attestations, and other consensus objects. * **Validator** - a participant in the Casper/sharding consensus system. You can become one by depositing 32 ETH into the Casper mechanism.
* **Committee**—a statistically representative validator subset, sampled pseudo-randomly. * **Active validator set** - those validators who are currently participating, and which the Casper mechanism looks to produce and attest to blocks, crosslinks and other consensus objects.
* **Proposer**—a validator with the right to create a block at a given slot. * **Committee** - a (pseudo-) randomly sampled subset of the active validator set. When a committee is referred to collectively, as in "this committee attests to X", this is assumed to mean "some subset of that committee that contains enough validators that the protocol recognizes it as representing the committee".
* **Attester**—a validator in an attestation committee with the right to attest to a block. * **Proposer** - the validator that creates a block
* **Beacon chain**—the central proof-of-state chain of Ethereum 2.0. * **Attester** - a validator that is part of a committee that needs to sign off on a block.
* **Shard**—one of the chains on which user transactions take place and contract state is stored. * **Beacon chain** - the central PoS chain that is the base of the sharding system.
* **Crosslink**—sufficient signatures from an attestation committee attesting to a given block. * **Shard chain** - one of the chains on which user transactions take place and account data is stored.
* **Slot**—a period of `SLOT_DURATION` seconds, during which one proposer has the ability to create a block and some attesters have the ability to make attestations * **Crosslink** - a set of signatures from a committee attesting to a block in a shard chain, which can be included into the beacon chain. Crosslinks are the main means by which the beacon chain "learns about" the updated state of shard chains.
* **Dynasty transition**—a beacon chain state transaction where the validator set may change. * **Slot** - a period of `SLOT_DURATION` seconds, during which one proposer has the ability to create a block and some attesters have the ability to make attestations
* **Dynasty height**—the number of dynasty transitions that have happened in a given chain since genesis. * **Dynasty transition** - a change of the validator set
* **Cycle**—a span of slots during which all validators get exactly one chance to make an attestation. * **Dynasty** - the number of dynasty transitions that have happened in a given chain since genesis
* **Finalized**, **justified**—see the [Casper FFG paper](https://arxiv.org/abs/1710.09437). [TODO: flesh out definitions] * **Cycle** - a span of blocks during which all validators get exactly one chance to make an attestation (unless a dynasty transition happens inside of one)
* **Finalized**, **justified** - see Casper FFG finalization here: https://arxiv.org/abs/1710.09437
* **Withdrawal period** - number of slots between a validator exit and the validator balance being withdrawable
* **Genesis time** - the Unix time of the genesis beacon chain block at slot 0
### Constants ### Constants
* **SHARD_COUNT** - a constant referring to the number of shards. Currently set to 1024. | Constant | Value | Unit | Approximation |
* **DEPOSIT_SIZE** - 32 ETH, or 32 * 10\*\*18 wei | --- | --- | :---: | - |
* **MAX_VALIDATOR_COUNT** - 2<sup>22</sup> = 4194304 # Note: this means that up to ~134 million ETH can stake at the same time | `SHARD_COUNT` | 2**10 (= 1,024)| shards |
* **GENESIS_TIME** - time of beacon chain startup (slot 0) in seconds since the Unix epoch | `DEPOSIT_SIZE` | 2**5 (= 32) | ETH |
* **SLOT_DURATION** - 16 seconds | `MIN_COMMITTEE_SIZE` | 2**7 (= 128) | validators |
* **CYCLE_LENGTH** - 64 slots | `MAX_VALIDATOR_COUNT` | 2**22 ( = 4,194,304) | validators |
* **MIN_DYNASTY_LENGTH** - 256 slots | `GENESIS_TIME` | **TBD** | seconds |
* **MIN_COMMITTEE_SIZE** - 128 (rationale: see recommended minimum 111 here https://vitalik.ca/files/Ithaca201807_Sharding.pdf) | `SLOT_DURATION` | 2**4 (= 16) | seconds |
* **SQRT\_E\_DROP\_TIME** - a constant set to reflect the amount of time it will take for the quadratic leak to cut nonparticipating validators' deposits by ~39.4%. Currently set to 2**20 seconds (~12 days). | `CYCLE_LENGTH` | 2**6 (= 64) | slots | ~17 minutes |
* **BASE\_REWARD\_QUOTIENT** - 1/this is the per-slot interest rate assuming all validators are participating, assuming total deposits of 1 ETH. Currently set to `2**15 = 32768`, corresponding to ~3.88% annual interest assuming 10 million participating ETH. | `MIN_DYNASTY_LENGTH` | 2**8 (= 256) | slots | ~1.1 hours |
* **WITHDRAWAL_PERIOD** - number of slots between a validator exit and the validator slot being withdrawable. Currently set to `2**19 = 524288` slots, or `2**23` seconds ~= 97 days. | `SQRT_E_DROP_TIME` | 2**16 (= 65,536) | slots | ~12 days |
* **MAX\_VALIDATOR\_CHANGE\_QUOTIENT** - a maximum of 1/x validators can change during each dynasty. Currently set to 32. | `WITHDRAWAL_PERIOD` | 2**19 (= 524,288) | slots | ~97 days |
* **PENDING\_LOG\_IN** = 0 (status code) | `BASE_REWARD_QUOTIENT` | 2**15 (= 32,768) | — |
* **LOGGED\_IN** = 1 (status code) | `MAX_VALIDATOR_CHURN_QUOTIENT` | 2**5 (= 32) | — |
* **PENDING\_EXIT** = 2 (status code)
* **PENDING\_WITHDRAW** = 3 (status code) **Notes**
* **PENALIZED** = 128 (status code)
* **WITHDRAWN** = 4 (status code) * At most `MAX_VALIDATOR_COUNT * DEPOSIT_SIZE` (~134 million ETH) can be staked.
* **ENTRY** = 1 (flag) * The `SQRT_E_DROP_TIME` constant is the amount of time it takes for the quadratic leak to cut deposits of non-participating validators by ~39.4%.
* **EXIT** = 2 (flag) * The `BASE_REWARD_QUOTIENT` constant is the per-slot interest rate assuming all validators are participating, assuming total deposits of 1 ETH. It corresponds to ~3.88% annual interest assuming 10 million participating ETH.
* At most `1/MAX_VALIDATOR_CHURN_QUOTIENT` of the validators can change during each dynasty.
**Status codes**
| Status code | Value |
| - | :-: |
| `PENDING_LOG_IN` | `0` |
| `LOGGED_IN` | `1` |
| `PENDING_EXIT` | `2` |
| `PENDING_WITHDRAW` | `3` |
| `WITHDRAWN` | `4` |
| `PENALIZED` | `128` |
| `ENTRY` | `1` |
| `EXIT` | `2` |
### PoW chain registration contract ### PoW chain registration contract
@ -494,7 +511,7 @@ Let `time_since_finality = block.slot - last_finalized_slot`, and let `B` be the
* `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` * `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 * int_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) * `quadratic_penalty_quotient = SQRT_E_DROP_TIME**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_recalculation - CYCLE_LENGTH ... last_state_recalculation - 1`: For each slot `S` in the range `last_state_recalculation - CYCLE_LENGTH ... last_state_recalculation - 1`:
@ -557,7 +574,7 @@ def change_validators(validators):
# The maximum total wei that can deposit+withdraw # The maximum total wei that can deposit+withdraw
max_allowable_change = max( max_allowable_change = max(
DEPOSIT_SIZE * 2, DEPOSIT_SIZE * 2,
total_deposits // MAX_VALIDATOR_CHANGE_QUOTIENT total_deposits // MAX_VALIDATOR_CHURN_QUOTIENT
) )
# Go through the list start to end depositing+withdrawing as many as possible # Go through the list start to end depositing+withdrawing as many as possible
total_changed = 0 total_changed = 0