transition

package
v0.0.1-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2024 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Overview

Package transition implements the whole state transition function which consists of per slot, per-epoch transitions. It also bootstraps the genesis beacon state for slot 0.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteStateTransition

func ExecuteStateTransition(
	ctx context.Context,
	state state.BeaconState,
	signed interfaces.ReadOnlySignedBeaconBlock,
) (state.BeaconState, error)

ExecuteStateTransition defines the procedure for a state transition function.

Note: This method differs from the spec pseudocode as it uses a batch signature verification. See: ExecuteStateTransitionNoVerifyAnySig

Spec pseudocode definition:

def state_transition(state: BeaconState, signed_block: ReadOnlySignedBeaconBlock, validate_result: bool=True) -> None:
  block = signed_block.message
  # Process slots (including those with no blocks) since block
  process_slots(state, block.slot)
  # Verify signature
  if validate_result:
      assert verify_block_signature(state, signed_block)
  # Process block
  process_block(state, block)
  # Verify state root
  if validate_result:
      assert block.state_root == hash_tree_root(state)

func ProcessEpochPrecompute

func ProcessEpochPrecompute(ctx context.Context, state state.BeaconState) (state.BeaconState, error)

ProcessEpochPrecompute describes the per epoch operations that are performed on the beacon state. It's optimized by pre computing validator attested info and epoch total/attested balances upfront.

func ProcessSlot

func ProcessSlot(ctx context.Context, state state.BeaconState) (state.BeaconState, error)

ProcessSlot happens every slot and focuses on the slot counter and block roots record updates. It happens regardless if there's an incoming block or not. Spec pseudocode definition:

def process_slot(state: BeaconState) -> None:
  # Cache state root
  previous_state_root = hash_tree_root(state)
  state.state_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_state_root
  # Cache latest block header state root
  if state.latest_block_header.state_root == Bytes32():
      state.latest_block_header.state_root = previous_state_root
  # Cache block root
  previous_block_root = hash_tree_root(state.latest_block_header)
  state.block_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_block_root

func ProcessSlots

func ProcessSlots(ctx context.Context, state state.BeaconState, slot primitives.Slot) (state.BeaconState, error)

ProcessSlots process through skip slots and apply epoch transition when it's needed

Spec pseudocode definition:

def process_slots(state: BeaconState, slot: Slot) -> None:
  assert state.slot < slot
  while state.slot < slot:
      process_slot(state)
      # Process epoch on the start slot of the next epoch
      if (state.slot + 1) % SLOTS_PER_EPOCH == 0:
          process_epoch(state)
      state.slot = Slot(state.slot + 1)

func ProcessSlotsIfPossible

func ProcessSlotsIfPossible(ctx context.Context, state state.BeaconState, targetSlot primitives.Slot) (state.BeaconState, error)

ProcessSlotsIfPossible executes ProcessSlots on the input state when target slot is above the state's slot. Otherwise, it returns the input state unchanged.

func ProcessSlotsUsingNextSlotCache

func ProcessSlotsUsingNextSlotCache(
	ctx context.Context,
	parentState state.BeaconState,
	parentRoot []byte,
	slot primitives.Slot) (state.BeaconState, error)

ProcessSlotsUsingNextSlotCache processes slots by using next slot cache for higher efficiency.

func VerifyOperationLengths

VerifyOperationLengths verifies that block operation lengths are valid.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL