fix default value when voting on eth1data
This commit is contained in:
parent
ac33b3d088
commit
b8d4ce4c39
|
@ -283,16 +283,20 @@ def is_candidate_block(block: Eth1Block, period_start: uint64) -> bool:
|
||||||
```python
|
```python
|
||||||
def get_eth1_vote(state: BeaconState, eth1_chain: Sequence[Eth1Block]) -> Eth1Data:
|
def get_eth1_vote(state: BeaconState, eth1_chain: Sequence[Eth1Block]) -> Eth1Data:
|
||||||
period_start = voting_period_start_time(state)
|
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 ascending block height
|
||||||
votes_to_consider = [get_eth1_data(block) for block in eth1_chain if
|
votes_to_consider = [get_eth1_data(block) for block in eth1_chain if
|
||||||
is_candidate_block(block, period_start)]
|
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]
|
valid_votes = [vote for vote in state.eth1_data_votes if vote in votes_to_consider]
|
||||||
|
|
||||||
|
# Default vote on latest eth1 block data in the period range unless eth1 chain is not live
|
||||||
|
default_vote = votes_to_consider[-1] if any(votes_to_consider) else state.eth1_data
|
||||||
|
|
||||||
return max(
|
return max(
|
||||||
valid_votes,
|
valid_votes,
|
||||||
key=lambda v: (valid_votes.count(v), -valid_votes.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),
|
default=default_vote
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue