Gamma State Component

The Gamma (γ) state component is a critical part of the Safrole consensus protocol that manages validator-related state. It consists of four main subcomponents:

GammaK (γₖ)

Tracks the current validator set, storing validator public keys, VRF keys, and weights.

GammaA (γₐ)

Accumulates tickets during an epoch, maintaining an ordered list of valid ticket submissions.

GammaZ (γᵧ)

Stores the ring root for the current epoch, used for signature verification.

GammaS (γₛ)

Manages slot sealers, either using the highest scoring tickets or fallback validator keys.

API Reference

class jam.consensus.safrole.gamma.GammaK(initial: Sequence[T] = [], codec: Codec[T] | None = None)[source]

Bases: Array[ValidatorData]

Validator set

static decode_from(buffer: bytes | bytearray | memoryview, offset: int = 0) Tuple[Any, int]

Decode from buffer. Must be implemented by subclasses or added via decorator.

Parameters:
  • buffer – Buffer to decode from

  • offset – Starting position in buffer

Returns:

  • The decoded value

  • Number of bytes read

Return type:

Tuple containing

class jam.consensus.safrole.gamma.GammaA(initial: Sequence[T] = [], codec: Codec[T] | None = None)[source]

Bases: Vector[TicketBody]

Ticket accumulator: set of highest scoring ticket ids to be used for the next epoch

static decode_from(buffer: bytes | bytearray | memoryview, offset: int = 0) Tuple[Vector[T], int]

Decode from buffer. Must be implemented by subclasses or added via decorator.

Parameters:
  • buffer – Buffer to decode from

  • offset – Starting position in buffer

Returns:

  • The decoded value

  • Number of bytes read

Return type:

Tuple containing

class jam.consensus.safrole.gamma.GammaSTickets(initial: Sequence[T] = [], codec: Codec[T] | None = None)[source]

Bases: Array[TicketBody]

Current epoch’s slot sealers: set of highest scoring ticket ids for this epoch

static decode_from(buffer: bytes | bytearray | memoryview, offset: int = 0) Tuple[Any, int]

Decode from buffer. Must be implemented by subclasses or added via decorator.

Parameters:
  • buffer – Buffer to decode from

  • offset – Starting position in buffer

Returns:

  • The decoded value

  • Number of bytes read

Return type:

Tuple containing

class jam.consensus.safrole.gamma.GammaSFallback(initial: Sequence[T] = [], codec: Codec[T] | None = None)[source]

Bases: Array[ByteArray32]

Fallback set of slot sealers: set of public keys of the slot sealers for this epoch

static decode_from(buffer: bytes | bytearray | memoryview, offset: int = 0) Tuple[Any, int]

Decode from buffer. Must be implemented by subclasses or added via decorator.

Parameters:
  • buffer – Buffer to decode from

  • offset – Starting position in buffer

Returns:

  • The decoded value

  • Number of bytes read

Return type:

Tuple containing

class jam.consensus.safrole.gamma.GammaS(initial: Dict[str, Codable[T]] | Codable[T])[source]

Bases: Choice

Either the current epoch’s slot sealers or the fallback set of slot sealers

tickets: GammaSTickets
keys: GammaSFallback
static decode_from(buffer: bytes | bytearray | memoryview, offset: int = 0) Tuple[Choice, int]

Decode choice from buffer.

Parameters:
  • types – List of possible types for this choice

  • buffer – Source buffer

  • offset – Starting offset

Returns:

Tuple of (decoded value, bytes read)

Raises:
class jam.consensus.safrole.gamma.Gamma(k: GammaK, z: ByteArray144, s: GammaS, a: GammaA)[source]

Bases: Codable

Gamma state

k: GammaK
z: ByteArray144
s: GammaS
a: GammaA
__init__(k: GammaK, z: ByteArray144, s: GammaS, a: GammaA) None

Initialize the Codable.

Parameters:
  • codec – Optional codec to use for encoding/decoding

  • enc_sequence – Optional function that returns sequence of fields to encode

static decode_from(buffer: bytes | bytearray | memoryview, offset: int = 0) Tuple[T, int]

Decode from buffer. Must be implemented by subclasses or added via decorator.

Parameters:
  • buffer – Buffer to decode from

  • offset – Starting position in buffer

Returns:

  • The decoded value

  • Number of bytes read

Return type:

Tuple containing

encode_into(buffer: bytearray, offset: int = 0) int

Encode into provided buffer.

encode_size() int

Calculate number of bytes needed to encode.