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 ¶
- Variables
- type AttestationReceiver
- type AttestationStateFetcher
- type Service
- func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.ReadOnlyBeaconState, error)
- func (s *Service) OnAttestation(ctx context.Context, a *ethpb.Attestation, disparity time.Duration) error
- func (s *Service) SaveAttestation(a *ethpb.Attestation) error
- func (s *Service) Start()
- func (s *Service) StartFromSavedState(saved state.BeaconState) error
- func (s *Service) Status() error
- func (s *Service) Stop() error
- func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot)
- func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a *ethpb.Attestation) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) StartFromSavedState ¶
func (s *Service) StartFromSavedState(saved state.BeaconState) error
StartFromSavedState initializes the blockchain using a previously saved finalized checkpoint.
func (*Service) Status ¶
Status always returns nil unless there is an error condition that causes this service to be unhealthy.
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 ¶
VerifyLmdFfgConsistency verifies that attestation's LMD and FFG votes are consistency to each other.