blockchain

package
v0.0.0-...-3bf8caa Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: Apache-2.0, MIT Imports: 39 Imported by: 0

Documentation

Overview

Package blockchain defines the life-cycle of the blockchain at the core of Ethereum, including processing of new blocks and attestations using proof of stake.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingClockSetter = errors.New("blockchain Service initialized without a startup.ClockSetter")

Functions

This section is empty.

Types

type AttestationReceiver

type AttestationReceiver interface {
	AttestationStateFetcher
	VerifyLmdFfgConsistency(ctx context.Context, att *ethpb.Attestation) error
	InForkchoice([32]byte) bool
}

AttestationReceiver interface defines the methods of chain service receive and processing new attestations.

type AttestationStateFetcher

type AttestationStateFetcher interface {
	AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.ReadOnlyBeaconState, error)
}

AttestationStateFetcher allows for retrieving a beacon state corresponding to the block root of an attestation's target checkpoint.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service represents a service that handles the internal logic of managing the full PoS beacon chain.

func NewService

func NewService(ctx context.Context, opts ...Option) (*Service, error)

NewService instantiates a new block service instance that will be registered into a running beacon node.

func (*Service) AttestationTargetState

func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.ReadOnlyBeaconState, error)

AttestationTargetState returns the pre state of attestation.

func (*Service) OnAttestation

func (s *Service) OnAttestation(ctx context.Context, a *ethpb.Attestation, disparity time.Duration) error

OnAttestation is called whenever an attestation is received, verifies the attestation is valid and saves it to the DB. As a stateless function, this does not hold nor delay attestation based on the spec descriptions. The delay is handled by the caller in `processAttestations`.

Spec pseudocode definition:

def on_attestation(store: Store, attestation: Attestation) -> None:
 """
 Run ``on_attestation`` upon receiving a new ``attestation`` from either within a block or directly on the wire.

 An ``attestation`` that is asserted as invalid may be valid at a later time,
 consider scheduling it for later processing in such case.
 """
 validate_on_attestation(store, attestation)
 store_target_checkpoint_state(store, attestation.data.target)

 # Get state at the `target` to fully validate attestation
 target_state = store.checkpoint_states[attestation.data.target]
 indexed_attestation = get_indexed_attestation(target_state, attestation)
 assert is_valid_indexed_attestation(target_state, indexed_attestation)

 # Update latest messages for attesting indices
 update_latest_messages(store, indexed_attestation.attesting_indices, attestation)

func (*Service) SaveAttestation

func (s *Service) SaveAttestation(a *ethpb.Attestation) error

func (*Service) Start

func (s *Service) Start()

Start a blockchain service's main event loop.

func (*Service) StartFromSavedState

func (s *Service) StartFromSavedState(saved state.BeaconState) error

StartFromSavedState initializes the blockchain using a previously saved finalized checkpoint.

func (*Service) Status

func (s *Service) Status() error

Status always returns nil unless there is an error condition that causes this service to be unhealthy.

func (*Service) Stop

func (s *Service) Stop() error

Stop the blockchain service's main event loop and associated goroutines.

func (*Service) UpdateHead

func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot)

UpdateHead updates the canonical head of the chain based on information from fork-choice attestations and votes. The caller of this function MUST hold a lock in forkchoice

func (*Service) VerifyLmdFfgConsistency

func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a *ethpb.Attestation) error

VerifyLmdFfgConsistency verifies that attestation's LMD and FFG votes are consistency to each other.

Jump to

Keyboard shortcuts

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