Part 3: Annotated Specification

Helper Functions

Participation flags

These two simple utilities were added in the Altair upgrade.

add_flag

def add_flag(flags: ParticipationFlags, flag_index: int) -> ParticipationFlags:
    """
    Return a new ``ParticipationFlags`` adding ``flag_index`` to ``flags``.
    """
    flag = ParticipationFlags(2**flag_index)
    return flags | flag

This is simple and self-explanatory. The 2**flag_index is a bit Pythony. In a C-like language it would use a bit-shift:

1 << flag_index
Used by process_attestation(), translate_participation()
See also ParticipationFlags

has_flag

def has_flag(flags: ParticipationFlags, flag_index: int) -> bool:
    """
    Return whether ``flags`` has ``flag_index`` set.
    """
    flag = ParticipationFlags(2**flag_index)
    return flags & flag == flag

Move along now, nothing to see here.

Used by get_unslashed_participating_indices(), process_attestation()
See also ParticipationFlags

Created by Ben Edgington. Licensed under CC BY-SA 4.0. Published 2022-05-12 12:26 UTC. Commit 0cc9f0b.