-
Notifications
You must be signed in to change notification settings - Fork 970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_eth1_data
uses timestamp instead of block height
#1553
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
- [Constructing the `BeaconBlockBody`](#constructing-the-beaconblockbody) | ||
- [Randao reveal](#randao-reveal) | ||
- [Eth1 Data](#eth1-data) | ||
- [`Eth1Block`](#eth1block) | ||
- [`get_eth1_data`](#get_eth1_data) | ||
- [Proposer slashings](#proposer-slashings) | ||
- [Attester slashings](#attester-slashings) | ||
- [Attestations](#attestations) | ||
|
@@ -85,6 +87,7 @@ All terminology, constants, functions, and protocol mechanics defined in the [Ph | |
| `TARGET_AGGREGATORS_PER_COMMITTEE` | `2**4` (= 16) | validators | | | ||
| `RANDOM_SUBNETS_PER_VALIDATOR` | `2**0` (= 1) | subnets | | | ||
| `EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION` | `2**8` (= 256) | epochs | ~27 hours | | ||
| `SECONDS_PER_ETH1_BLOCK` | `14` | seconds | | | ||
|
||
## Becoming a validator | ||
|
||
|
@@ -239,28 +242,50 @@ def get_epoch_signature(state: BeaconState, block: BeaconBlock, privkey: int) -> | |
|
||
##### Eth1 Data | ||
|
||
The `block.body.eth1_data` field is for block proposers to vote on recent Eth1 data. This recent data contains an Eth1 block hash as well as the associated deposit root (as calculated by the `get_deposit_root()` method of the deposit contract) and deposit count after execution of the corresponding Eth1 block. If over half of the block proposers in the current Eth1 voting period vote for the same `eth1_data` then `state.eth1_data` updates at the end of the voting period. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`. | ||
The `block.body.eth1_data` field is for block proposers to vote on recent Eth1 data. This recent data contains an Eth1 block hash as well as the associated deposit root (as calculated by the `get_deposit_root()` method of the deposit contract) and deposit count after execution of the corresponding Eth1 block. If over half of the block proposers in the current Eth1 voting period vote for the same `eth1_data` then `state.eth1_data` updates immediately allowing new deposits to be processed. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`. | ||
|
||
Let `get_eth1_data(distance: uint64) -> Eth1Data` be the (subjective) function that returns the Eth1 data at distance `distance` relative to the Eth1 head at the start of the current Eth1 voting period. Let `previous_eth1_distance` be the distance relative to the Eth1 block corresponding to `eth1_data.block_hash` found in the state at the _start_ of the current Eth1 voting period. Note that `eth1_data` can be updated in the middle of a voting period and thus the starting `eth1_data.block_hash` must be stored separately. | ||
###### `Eth1Block` | ||
|
||
An honest block proposer sets `block.body.eth1_data = get_eth1_vote(state, previous_eth1_distance)` where: | ||
Let `Eth1Block` be an abstract object representing Eth1 blocks with the `timestamp` field available. | ||
|
||
```python | ||
def get_eth1_vote(state: BeaconState, previous_eth1_distance: uint64) -> Eth1Data: | ||
new_eth1_data = [get_eth1_data(distance) for distance in range(ETH1_FOLLOW_DISTANCE, 2 * ETH1_FOLLOW_DISTANCE)] | ||
all_eth1_data = [get_eth1_data(distance) for distance in range(ETH1_FOLLOW_DISTANCE, previous_eth1_distance)] | ||
class Eth1Block(Container): | ||
timestamp: uint64 | ||
# All other eth1 block fields | ||
``` | ||
|
||
###### `get_eth1_data` | ||
|
||
Let `get_eth1_data(block: Eth1Block) -> Eth1Data` be the function that returns the Eth1 data for a given Eth1 block. | ||
|
||
An honest block proposer sets `block.body.eth1_data = get_eth1_vote(state)` where: | ||
|
||
```python | ||
def voting_period_start_time(state: BeaconState) -> uint64: | ||
eth1_voting_period_start_slot = state.slot % SLOTS_PER_ETH1_VOTING_PERIOD | ||
return state.genesis_time + eth1_voting_period_start_slot * SECONDS_PER_SLOT | ||
``` | ||
|
||
```python | ||
def is_candidate_block(block: Eth1Block, period_start: uint64) -> bool: | ||
return ( | ||
block.timestamp <= period_start - SECONDS_PER_ETH1_BLOCK * ETH1_FOLLOW_DISTANCE | ||
and block.timestamp >= period_start - SECONDS_PER_ETH1_BLOCK * ETH1_FOLLOW_DISTANCE * 2 | ||
Comment on lines
+272
to
+273
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the simplicity, but aside from a deep re-org, but just leaving a note here that a very slow (deprecation) or dead (with a remaining tail of deposits) eth1 will also be an extra-protocol thing for eth2. |
||
) | ||
``` | ||
|
||
period_tail = state.slot % SLOTS_PER_ETH1_VOTING_PERIOD >= integer_squareroot(SLOTS_PER_ETH1_VOTING_PERIOD) | ||
if period_tail: | ||
votes_to_consider = all_eth1_data | ||
else: | ||
votes_to_consider = new_eth1_data | ||
```python | ||
def get_eth1_vote(state: BeaconState, eth1_chain: Sequence[Eth1Block]) -> Eth1Data: | ||
period_start = voting_period_start_time(state) | ||
# `eth1_chain` abstractly represents all blocks in the eth1 chain. | ||
votes_to_consider = [get_eth1_data(block) for block in eth1_chain if | ||
is_candidate_block(block, period_start)] | ||
|
||
valid_votes = [vote for vote in state.eth1_data_votes if vote in votes_to_consider] | ||
|
||
return max( | ||
valid_votes, | ||
key=lambda v: (valid_votes.count(v), -all_eth1_data.index(v)), # Tiebreak by smallest distance | ||
key=lambda v: (valid_votes.count(v), -valid_votes.index(v)), # Tiebreak by smallest distance | ||
default=get_eth1_data(ETH1_FOLLOW_DISTANCE), | ||
) | ||
``` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the slot/epoch conversions, helper functions for time - slot conversion would be useful too. But leaving this as-is, we can change it when there are more cases.