Skip to content

feat: electra get_attesting_indices changes + helper functions from predicates/misc. #1419

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

Merged
merged 19 commits into from
Apr 10, 2025

Conversation

LeanSerra
Copy link
Contributor

Motivation

Implement the changes for Electra for sections predicates, misc

This PR does not fix any spec-test but does not break any either to check this

make spec-test

should return same amount of tests as #1417

Description
Predicates

  • Modified is_eligible_for_activation_queue link
  • New is_compounding_withdrawal_credential link
  • New has_compounding_withdrawal_credential link
  • New has_execution_withdrawal_credential link
  • Modified is_fully_withdrawable_validator link
  • Modified is_partially_withdrawable_validator link

Misc

  • New get_committee_indices link

Beacon state accessors

  • Modified get_attesting_indices link

@LeanSerra LeanSerra added elixir Pull requests that update Elixir code electra labels Apr 7, 2025
@LeanSerra LeanSerra self-assigned this Apr 7, 2025
@LeanSerra LeanSerra marked this pull request as ready for review April 8, 2025 14:36
@LeanSerra LeanSerra requested a review from a team as a code owner April 8, 2025 14:36
@LeanSerra LeanSerra changed the title feat: electra helper functions predicate/misc feat: electra get_attesting_indices_changes changes + helper functions from predicates/misc. Apr 8, 2025
@LeanSerra LeanSerra changed the title feat: electra get_attesting_indices_changes changes + helper functions from predicates/misc. feat: electra get_attesting_indices changes + helper functions from predicates/misc. Apr 8, 2025
Base automatically changed from electra_slashing to electra-support April 8, 2025 14:56
Copy link
Collaborator

@rodrigo-o rodrigo-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a comment that could cause issues in the future (in the get_attesting_indices) and another one to show how comprehension could match closer the spec if needed.

Comment on lines 595 to 609
committee_bits
|> get_committee_indices()
|> Enum.reduce({MapSet.new(), 0}, fn index, {old_set, offset} ->
with {:ok, committee} <- get_beacon_committee(state, data.slot, index) do
committee
|> Stream.with_index()
|> Stream.filter(fn {_value, index} ->
participated?(aggregation_bits, offset + index)
end)
|> Stream.map(fn {value, _index} -> value end)
|> MapSet.new()
|> then(&{MapSet.union(&1, old_set), offset + length(committee)})
end
end)
|> then(fn {map, _offset} -> {:ok, map} end)
Copy link
Collaborator

@rodrigo-o rodrigo-o Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may have an issue here, before when the get_beacon_committee/3 returned an error we just bubbled it up, now if this happens the reduce will fail because it will try to parse an {:error, error} as the {old_set, offset} tuple. We could go with a reduce_while, instead (BTW made some changes for readability):

  committee_bits
  |> get_committee_indices()
  |> Enum.reduce_while({MapSet.new(), 0}, fn committee_index, {attesters, offset} ->
    case get_beacon_committee(state, data.slot, committee_index) do
      {:ok, committee} ->
        # Process this committee's attesters
        committee_attesters = 
          committee
          |> Stream.with_index(offset)
          |> Stream.filter(fn {_validator, pos} -> participated?(aggregation_bits, pos) end)
          |> Stream.map(fn {validator, _} -> validator end)
          |> MapSet.new()
        
        {:cont, {MapSet.union(attesters, committee_attesters), offset + length(committee)}}
      
      error -> 
        # Depending on the specs we might just want to skip this error with something like: `{attesters, offset}`
        {:halt, error}
    end
  end)
  |> case do
    {:error, error} -> {:error, error}
    {attesters, _offset} -> {:ok, attesters}
  end

Also, I'm not 100% sure about the usefulness of Streams here, but given that it was already implemented that way I wouldn't change it to Enum for now.

Copy link
Contributor Author

@LeanSerra LeanSerra Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops I didn't know with behaved that way. I implemented the changes here. I also tried both {:halt, error} and {:cont, {attesters, offset} and the amount of tests passing is the same so for now I think we can leave it as {:halt, error}.

@LeanSerra LeanSerra merged commit 71dee9d into electra-support Apr 10, 2025
1 check passed
@LeanSerra LeanSerra deleted the electra_predicates branch April 10, 2025 12:41
rodrigo-o pushed a commit that referenced this pull request Apr 25, 2025
rodrigo-o pushed a commit that referenced this pull request Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electra elixir Pull requests that update Elixir code
Projects
Development

Successfully merging this pull request may close these issues.

2 participants