Skip to content

Commit

Permalink
fix default value when voting on eth1data
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Jan 9, 2020
1 parent ac33b3d commit 3a67380
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions specs/validator/0_beacon-chain-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,20 @@ def is_candidate_block(block: Eth1Block, period_start: uint64) -> bool:
```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.
# `eth1_chain` abstractly represents all blocks in the eth1 chain sorted by descending block height
votes_to_consider = [get_eth1_data(block) for block in eth1_chain if
is_candidate_block(block, period_start)]

# Valid votes already cast during this period
valid_votes = [vote for vote in state.eth1_data_votes if vote in votes_to_consider]

# Default vote to use if no valid votes already cast in this period
default_vote = votes_to_consider[0] if any(votes_to_consider) else state.eth1_data

return max(
valid_votes,
key=lambda v: (valid_votes.count(v), -valid_votes.index(v)), # Tiebreak by smallest distance
default=get_eth1_data(ETH1_FOLLOW_DISTANCE),
default=default_vote
)
```

Expand Down

0 comments on commit 3a67380

Please sign in to comment.