Skip to content
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

period_tail in get_eth1_vote #1463

Closed
wants to merge 1 commit into from
Closed

Conversation

paulhauner
Copy link
Contributor

@paulhauner paulhauner commented Nov 4, 2019

The change I have suggested targets get_eth1_vote() and is the result of the following 3 (potentially incorrect) observations:

  1. slot seems a misleading variable name for indexing state.eth1_data_votes.
  2. slot % SLOTS_PER_ETH1_VOTING_PERIOD when len(state.eth1_data_votes) <= SLOTS_PER_ETH1_VOTING_PERIOD is a no-op.
  3. I assume the period_tail is designed to validate earlier eth1_data_votes if they are in all_eth1_data (but not in new_eth1_data). However, when period_tail = slot >= integer_squareroot(...), only later eth1_data_votes are tested against all_eth1_data.

@paulhauner
Copy link
Contributor Author

It's probably worth considering this alongside #1464

@djrtwo
Copy link
Contributor

djrtwo commented Nov 5, 2019

  1. agreed
  2. agreed
  3. You have this flipped. Essentially, for earlier in the period, we just want people to attempt to vote on new data, so in the beginning of the period, only pile on your vote to votes that are for newer data. But once we've entered the tail of the period, we just want consensus so we consider all votes

The previous method was making the assumption that there was one eth1 vote per slot. I am considering that maybe it should just be the following to remove this assumption (uses state.slot instead of counting the votes in state for figuring out if in period tail)

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)]

    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

    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
        default=get_eth1_data(ETH1_FOLLOW_DISTANCE),
    )

@djrtwo djrtwo added the scope:v-guide Validator guide label Nov 7, 2019
@djrtwo
Copy link
Contributor

djrtwo commented Nov 7, 2019

closing in favor of #1468

@djrtwo djrtwo closed this Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:v-guide Validator guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants