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
- func InvalidAncestorRoots(e error) [][32]byte
- func InvalidBlockRoot(e error) [32]byte
- func IsInvalidBlock(e error) bool
- type AttestationReceiver
- type AttestationStateFetcher
- type BlockReceiver
- type CanonicalFetcher
- type ChainInfoFetcher
- type FinalizationFetcher
- type ForkFetcher
- type ForkchoiceFetcher
- type GenesisFetcher
- type HeadDomainFetcher
- type HeadFetcher
- type HeadSyncCommitteeFetcher
- type OptimisticModeFetcher
- type Option
- func WithAttestationPool(p attestations.Pool) Option
- func WithAttestationService(srv *attestations.Service) Option
- func WithBLSToExecPool(p blstoexec.PoolManager) Option
- func WithChainStartFetcher(f execution.ChainStartFetcher) Option
- func WithDatabase(beaconDB db.HeadAccessDatabase) Option
- func WithDepositCache(c *depositcache.DepositCache) Option
- func WithExecutionEngineCaller(c execution.EngineCaller) Option
- func WithExitPool(p voluntaryexits.PoolManager) Option
- func WithFinalizedStateAtStartUp(st state.BeaconState) Option
- func WithForkChoiceStore(f forkchoice.ForkChoicer) Option
- func WithMaxGoroutines(x int) Option
- func WithP2PBroadcaster(p p2p.Broadcaster) Option
- func WithProposerIdsCache(c *cache.ProposerPayloadIDsCache) Option
- func WithSlasherAttestationsFeed(f *event.Feed) Option
- func WithSlashingPool(p slashings.PoolManager) Option
- func WithStateGen(g *stategen.State) Option
- func WithStateNotifier(n statefeed.Notifier) Option
- func WithWeakSubjectivityCheckpoint(c *ethpb.Checkpoint) Option
- type Service
- func (s *Service) Ancestor(ctx context.Context, root []byte, slot primitives.Slot) ([]byte, error)
- func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.BeaconState, error)
- func (s *Service) CachedHeadRoot() [32]byte
- func (s *Service) ChainHeads() ([][32]byte, []primitives.Slot)
- func (s *Service) CurrentFork() *ethpb.Fork
- func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint
- func (s *Service) CurrentSlot() primitives.Slot
- func (s *Service) FinalizedBlockHash() [32]byte
- func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint
- func (s *Service) ForkChoiceDump(ctx context.Context) (*ethpbv1.ForkChoiceDump, error)
- func (s *Service) GenesisTime() time.Time
- func (s *Service) GenesisValidatorsRoot() [32]byte
- func (s *Service) GetProposerHead() [32]byte
- func (s *Service) HasBlock(ctx context.Context, root [32]byte) bool
- func (s *Service) HeadBlock(ctx context.Context) (interfaces.ReadOnlySignedBeaconBlock, error)
- func (s *Service) HeadETH1Data() *ethpb.Eth1Data
- func (s *Service) HeadGenesisValidatorsRoot() [32]byte
- func (s *Service) HeadPublicKeyToValidatorIndex(pubKey [fieldparams.BLSPubkeyLength]byte) (primitives.ValidatorIndex, bool)
- func (s *Service) HeadRoot(ctx context.Context) ([]byte, error)
- func (s *Service) HeadSlot() primitives.Slot
- func (s *Service) HeadState(ctx context.Context) (state.BeaconState, error)
- func (s *Service) HeadStateReadOnly(ctx context.Context) (state.ReadOnlyBeaconState, error)
- func (s *Service) HeadSyncCommitteeDomain(ctx context.Context, slot primitives.Slot) ([]byte, error)
- func (s *Service) HeadSyncCommitteeIndices(ctx context.Context, index primitives.ValidatorIndex, slot primitives.Slot) ([]primitives.CommitteeIndex, error)
- func (s *Service) HeadSyncCommitteePubKeys(ctx context.Context, slot primitives.Slot, ...) ([][]byte, error)
- func (s *Service) HeadSyncContributionProofDomain(ctx context.Context, slot primitives.Slot) ([]byte, error)
- func (s *Service) HeadSyncSelectionProofDomain(ctx context.Context, slot primitives.Slot) ([]byte, error)
- func (s *Service) HeadValidatorIndexToPublicKey(_ context.Context, index primitives.ValidatorIndex) ([fieldparams.BLSPubkeyLength]byte, error)
- func (s *Service) HeadValidatorsIndices(ctx context.Context, epoch primitives.Epoch) ([]primitives.ValidatorIndex, error)
- func (s *Service) HighestReceivedBlockSlot() primitives.Slot
- func (s *Service) InForkchoice(root [32]byte) bool
- func (s *Service) InsertNode(ctx context.Context, st state.BeaconState, root [32]byte) error
- func (s *Service) InsertSlashingsToForkChoiceStore(ctx context.Context, slashings []*ethpb.AttesterSlashing)
- func (s *Service) IsCanonical(ctx context.Context, blockRoot [32]byte) (bool, error)
- func (s *Service) IsFinalized(ctx context.Context, root [32]byte) bool
- func (s *Service) IsOptimistic(ctx context.Context) (bool, error)
- func (s *Service) IsOptimisticForRoot(ctx context.Context, root [32]byte) (bool, error)
- func (s *Service) NewSlot(ctx context.Context, slot primitives.Slot) error
- func (s *Service) OnAttestation(ctx context.Context, a *ethpb.Attestation, disparity time.Duration) error
- func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint
- func (s *Service) ProposerBoost() [32]byte
- func (s *Service) ReceiveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing)
- func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, ...) error
- func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []interfaces.ReadOnlySignedBeaconBlock, ...) error
- func (s *Service) ReceivedBlocksLastEpoch() (uint64, error)
- func (s *Service) SetForkChoiceGenesisTime(timestamp uint64)
- func (s *Service) SetGenesisTime(t time.Time)
- 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) UnrealizedJustifiedPayloadBlockHash() ([32]byte, error)
- func (s *Service) UpdateAndSaveHeadWithBalances(ctx context.Context) error
- func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot)
- func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a *ethpb.Attestation) error
- type SlashingReceiver
- type TimeFetcher
- type WeakSubjectivityVerifier
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPayload is returned when the payload is invalid ErrInvalidPayload = invalidBlock{/* contains filtered or unexported fields */} // ErrInvalidBlockHashPayloadStatus is returned when the payload has invalid block hash. ErrInvalidBlockHashPayloadStatus = invalidBlock{/* contains filtered or unexported fields */} // ErrUndefinedExecutionEngineError is returned when the execution engine returns an error that is not defined ErrUndefinedExecutionEngineError = errors.New("received an undefined execution engine error") // errNotDescendantOfFinalized is returned when a block is not a descendant of the finalized checkpoint ErrNotDescendantOfFinalized = invalidBlock{/* contains filtered or unexported fields */} )
var (
LateBlockAttemptedReorgCount = promauto.NewCounter(prometheus.CounterOpts{
Name: "beacon_late_block_attempted_reorgs",
Help: "Count the number of times a proposer served by this beacon has attempted a late block reorg",
})
)
Functions ¶
func InvalidAncestorRoots ¶
InvalidAncestorRoots returns a list of invalid roots up to last valid root.
func InvalidBlockRoot ¶
InvalidBlockRoot returns the invalid block root. If the error doesn't have an invalid blockroot. [32]byte{} is returned.
func IsInvalidBlock ¶
IsInvalidBlock returns true if the error has `invalidBlock`.
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.BeaconState, error)
}
AttestationStateFetcher allows for retrieving a beacon state corresponding to the block root of an attestation's target checkpoint.
type BlockReceiver ¶
type BlockReceiver interface { ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte) error ReceiveBlockBatch(ctx context.Context, blocks []interfaces.ReadOnlySignedBeaconBlock, blkRoots [][32]byte) error HasBlock(ctx context.Context, root [32]byte) bool }
BlockReceiver interface defines the methods of chain service for receiving and processing new blocks.
type CanonicalFetcher ¶
type CanonicalFetcher interface {
IsCanonical(ctx context.Context, blockRoot [32]byte) (bool, error)
}
CanonicalFetcher retrieves the current chain's canonical information.
type ChainInfoFetcher ¶
type ChainInfoFetcher interface { HeadFetcher FinalizationFetcher CanonicalFetcher ForkFetcher HeadDomainFetcher ForkchoiceFetcher }
ChainInfoFetcher defines a common interface for methods in blockchain service which directly retrieve chain info related data.
type FinalizationFetcher ¶
type FinalizationFetcher interface { FinalizedCheckpt() *ethpb.Checkpoint CurrentJustifiedCheckpt() *ethpb.Checkpoint PreviousJustifiedCheckpt() *ethpb.Checkpoint UnrealizedJustifiedPayloadBlockHash() ([32]byte, error) FinalizedBlockHash() [32]byte InForkchoice([32]byte) bool IsFinalized(ctx context.Context, blockRoot [32]byte) bool }
FinalizationFetcher defines a common interface for methods in blockchain service which directly retrieve finalization and justification related data.
type ForkFetcher ¶
type ForkFetcher interface { CurrentFork() *ethpb.Fork GenesisFetcher TimeFetcher }
ForkFetcher retrieves the current fork information of the Ethereum beacon chain.
type ForkchoiceFetcher ¶
type ForkchoiceFetcher interface { Ancestor(context.Context, []byte, primitives.Slot) ([]byte, error) CachedHeadRoot() [32]byte GetProposerHead() [32]byte SetForkChoiceGenesisTime(uint64) UpdateHead(context.Context, primitives.Slot) HighestReceivedBlockSlot() primitives.Slot ReceivedBlocksLastEpoch() (uint64, error) InsertNode(context.Context, state.BeaconState, [32]byte) error ForkChoiceDump(context.Context) (*ethpbv1.ForkChoiceDump, error) NewSlot(context.Context, primitives.Slot) error ProposerBoost() [32]byte }
ForkchoiceFetcher defines a common interface for methods that access directly forkchoice information. These typically require a lock and external callers are requested to call methods within this blockchain package that takes care of locking forkchoice
type GenesisFetcher ¶
type GenesisFetcher interface {
GenesisValidatorsRoot() [32]byte
}
GenesisFetcher retrieves the Ethereum consensus data related to its genesis.
type HeadDomainFetcher ¶
type HeadDomainFetcher interface { HeadSyncCommitteeDomain(ctx context.Context, slot primitives.Slot) ([]byte, error) HeadSyncSelectionProofDomain(ctx context.Context, slot primitives.Slot) ([]byte, error) HeadSyncContributionProofDomain(ctx context.Context, slot primitives.Slot) ([]byte, error) }
HeadDomainFetcher is the interface that wraps the head sync domain related functions. The head sync committee domain functions return callers domain data with respect to slot and head state.
type HeadFetcher ¶
type HeadFetcher interface { HeadSlot() primitives.Slot HeadRoot(ctx context.Context) ([]byte, error) HeadBlock(ctx context.Context) (interfaces.ReadOnlySignedBeaconBlock, error) HeadState(ctx context.Context) (state.BeaconState, error) HeadStateReadOnly(ctx context.Context) (state.ReadOnlyBeaconState, error) HeadValidatorsIndices(ctx context.Context, epoch primitives.Epoch) ([]primitives.ValidatorIndex, error) HeadGenesisValidatorsRoot() [32]byte HeadETH1Data() *ethpb.Eth1Data HeadPublicKeyToValidatorIndex(pubKey [fieldparams.BLSPubkeyLength]byte) (primitives.ValidatorIndex, bool) HeadValidatorIndexToPublicKey(ctx context.Context, index primitives.ValidatorIndex) ([fieldparams.BLSPubkeyLength]byte, error) ChainHeads() ([][32]byte, []primitives.Slot) HeadSyncCommitteeFetcher HeadDomainFetcher }
HeadFetcher defines a common interface for methods in blockchain service which directly retrieve head related data.
type HeadSyncCommitteeFetcher ¶
type HeadSyncCommitteeFetcher interface { HeadSyncCommitteeIndices(ctx context.Context, index primitives.ValidatorIndex, slot primitives.Slot) ([]primitives.CommitteeIndex, error) HeadSyncCommitteePubKeys(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) ([][]byte, error) }
HeadSyncCommitteeFetcher is the interface that wraps the head sync committee related functions. The head sync committee functions return callers sync committee indices and public keys with respect to current head state.
type OptimisticModeFetcher ¶
type OptimisticModeFetcher interface { IsOptimistic(ctx context.Context) (bool, error) IsOptimisticForRoot(ctx context.Context, root [32]byte) (bool, error) }
OptimisticModeFetcher retrieves information about optimistic status of the node.
type Option ¶
func WithAttestationPool ¶
func WithAttestationPool(p attestations.Pool) Option
WithAttestationPool for attestation lifecycle after chain inclusion.
func WithAttestationService ¶
func WithAttestationService(srv *attestations.Service) Option
WithAttestationService for dealing with attestation lifecycles.
func WithBLSToExecPool ¶
func WithBLSToExecPool(p blstoexec.PoolManager) Option
WithBLSToExecPool to keep track of BLS to Execution address changes.
func WithChainStartFetcher ¶
func WithChainStartFetcher(f execution.ChainStartFetcher) Option
WithChainStartFetcher to retrieve information about genesis.
func WithDatabase ¶
func WithDatabase(beaconDB db.HeadAccessDatabase) Option
WithDatabase for head access.
func WithDepositCache ¶
func WithDepositCache(c *depositcache.DepositCache) Option
WithDepositCache for deposit lifecycle after chain inclusion.
func WithExecutionEngineCaller ¶
func WithExecutionEngineCaller(c execution.EngineCaller) Option
WithExecutionEngineCaller to call execution engine.
func WithExitPool ¶
func WithExitPool(p voluntaryexits.PoolManager) Option
WithExitPool for exits lifecycle after chain inclusion.
func WithFinalizedStateAtStartUp ¶
func WithFinalizedStateAtStartUp(st state.BeaconState) Option
WithFinalizedStateAtStartUp to store finalized state at start up.
func WithForkChoiceStore ¶
func WithForkChoiceStore(f forkchoice.ForkChoicer) Option
WithForkChoiceStore to update an optimized fork-choice representation.
func WithMaxGoroutines ¶
WithMaxGoroutines to control resource use of the blockchain service.
func WithP2PBroadcaster ¶
func WithP2PBroadcaster(p p2p.Broadcaster) Option
WithP2PBroadcaster to broadcast messages after appropriate processing.
func WithProposerIdsCache ¶
func WithProposerIdsCache(c *cache.ProposerPayloadIDsCache) Option
WithProposerIdsCache for proposer id cache.
func WithSlasherAttestationsFeed ¶
WithSlasherAttestationsFeed to forward attestations into slasher if enabled.
func WithSlashingPool ¶
func WithSlashingPool(p slashings.PoolManager) Option
WithSlashingPool for slashings lifecycle after chain inclusion.
func WithStateGen ¶
WithStateGen for managing state regeneration and replay.
func WithStateNotifier ¶
WithStateNotifier to notify an event feed of state processing.
func WithWeakSubjectivityCheckpoint ¶
func WithWeakSubjectivityCheckpoint(c *ethpb.Checkpoint) Option
WithWeakSubjectivityCheckpoint for checkpoint sync.
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) Ancestor ¶
Ancestor returns the block root of an ancestry block from the input block root.
Spec pseudocode definition:
def get_ancestor(store: Store, root: Root, slot: Slot) -> Root: block = store.blocks[root] if block.slot > slot: return get_ancestor(store, block.parent_root, slot) elif block.slot == slot: return root else: # root is older than queried slot, thus a skip slot. Return most recent root prior to slot return root
func (*Service) AttestationTargetState ¶
func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.BeaconState, error)
AttestationTargetState returns the pre state of attestation.
func (*Service) CachedHeadRoot ¶ added in v4.0.1
CachedHeadRoot returns the corresponding value from Forkchoice
func (*Service) ChainHeads ¶
func (s *Service) ChainHeads() ([][32]byte, []primitives.Slot)
ChainHeads returns all possible chain heads (leaves of fork choice tree). Heads roots and heads slots are returned.
func (*Service) CurrentFork ¶
CurrentFork retrieves the latest fork information of the beacon chain.
func (*Service) CurrentJustifiedCheckpt ¶
func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint
CurrentJustifiedCheckpt returns the current justified checkpoint from chain store.
func (*Service) CurrentSlot ¶
func (s *Service) CurrentSlot() primitives.Slot
CurrentSlot returns the current slot based on time.
func (*Service) FinalizedBlockHash ¶ added in v4.0.2
FinalizedBlockHash returns finalized payload block hash from forkchoice.
func (*Service) FinalizedCheckpt ¶
func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint
FinalizedCheckpt returns the latest finalized checkpoint from chain store.
func (*Service) ForkChoiceDump ¶ added in v4.0.1
ForkChoiceDump returns the corresponding value from forkchoice
func (*Service) GenesisTime ¶
GenesisTime returns the genesis time of beacon chain.
func (*Service) GenesisValidatorsRoot ¶
GenesisValidatorsRoot returns the genesis validators root of the chain.
func (*Service) GetProposerHead ¶ added in v4.0.1
GetProposerHead returns the corresponding value from forkchoice
func (*Service) HasBlock ¶
HasBlock returns true if the block of the input root exists in initial sync blocks cache or DB.
func (*Service) HeadBlock ¶
func (s *Service) HeadBlock(ctx context.Context) (interfaces.ReadOnlySignedBeaconBlock, error)
HeadBlock returns the head block of the chain. If the head is nil from service struct, it will attempt to get the head block from DB.
func (*Service) HeadETH1Data ¶
HeadETH1Data returns the eth1data of the current head state.
func (*Service) HeadGenesisValidatorsRoot ¶
HeadGenesisValidatorsRoot returns genesis validators root of the head state.
func (*Service) HeadPublicKeyToValidatorIndex ¶
func (s *Service) HeadPublicKeyToValidatorIndex(pubKey [fieldparams.BLSPubkeyLength]byte) (primitives.ValidatorIndex, bool)
HeadPublicKeyToValidatorIndex returns the validator index of the `pubkey` in current head state.
func (*Service) HeadSlot ¶
func (s *Service) HeadSlot() primitives.Slot
HeadSlot returns the slot of the head of the chain.
func (*Service) HeadState ¶
HeadState returns the head state of the chain. If the head is nil from service struct, it will attempt to get the head state from DB.
func (*Service) HeadStateReadOnly ¶
HeadStateReadOnly returns the read only head state of the chain. If the head is nil from service struct, it will attempt to get the head state from DB. Any callers of this method MUST only use the state instance to read fields from the state. Any type assertions back to the concrete type and subsequent use of it could lead to corruption of the state.
func (*Service) HeadSyncCommitteeDomain ¶
func (s *Service) HeadSyncCommitteeDomain(ctx context.Context, slot primitives.Slot) ([]byte, error)
HeadSyncCommitteeDomain returns the head sync committee domain using current head state advanced up to `slot`.
func (*Service) HeadSyncCommitteeIndices ¶
func (s *Service) HeadSyncCommitteeIndices(ctx context.Context, index primitives.ValidatorIndex, slot primitives.Slot) ([]primitives.CommitteeIndex, error)
HeadSyncCommitteeIndices returns the sync committee index position using the head state. Input `slot` is taken in consideration where validator's duty for `slot - 1` is used for block inclusion in `slot`. That means when a validator is at epoch boundary across EPOCHS_PER_SYNC_COMMITTEE_PERIOD then the valiator will be considered using next period sync committee.
Spec definition: Being assigned to a sync committee for a given slot means that the validator produces and broadcasts signatures for slot - 1 for inclusion in slot. This means that when assigned to an epoch sync committee signatures must be produced and broadcast for slots on range [compute_start_slot_at_epoch(epoch) - 1, compute_start_slot_at_epoch(epoch) + SLOTS_PER_EPOCH - 1) rather than for the range [compute_start_slot_at_epoch(epoch), compute_start_slot_at_epoch(epoch) + SLOTS_PER_EPOCH)
func (*Service) HeadSyncCommitteePubKeys ¶
func (s *Service) HeadSyncCommitteePubKeys(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) ([][]byte, error)
HeadSyncCommitteePubKeys returns the head sync committee public keys with respect to `slot` and subcommittee index `committeeIndex`. Head state advanced up to `slot` is used for calculation.
func (*Service) HeadSyncContributionProofDomain ¶
func (s *Service) HeadSyncContributionProofDomain(ctx context.Context, slot primitives.Slot) ([]byte, error)
HeadSyncContributionProofDomain returns the head sync committee domain using current head state advanced up to `slot`.
func (*Service) HeadSyncSelectionProofDomain ¶
func (s *Service) HeadSyncSelectionProofDomain(ctx context.Context, slot primitives.Slot) ([]byte, error)
HeadSyncSelectionProofDomain returns the head sync committee domain using current head state advanced up to `slot`.
func (*Service) HeadValidatorIndexToPublicKey ¶
func (s *Service) HeadValidatorIndexToPublicKey(_ context.Context, index primitives.ValidatorIndex) ([fieldparams.BLSPubkeyLength]byte, error)
HeadValidatorIndexToPublicKey returns the pubkey of the validator `index` in current head state.
func (*Service) HeadValidatorsIndices ¶
func (s *Service) HeadValidatorsIndices(ctx context.Context, epoch primitives.Epoch) ([]primitives.ValidatorIndex, error)
HeadValidatorsIndices returns a list of active validator indices from the head view of a given epoch.
func (*Service) HighestReceivedBlockSlot ¶ added in v4.0.1
func (s *Service) HighestReceivedBlockSlot() primitives.Slot
HighestReceivedBlockSlot returns the corresponding value from forkchoice
func (*Service) InForkchoice ¶
InForkchoice returns true if the given root is found in forkchoice This in particular means that the blockroot is a descendant of the finalized checkpoint
func (*Service) InsertNode ¶ added in v4.0.1
InsertNode is a wrapper for node insertion which is self locked
func (*Service) InsertSlashingsToForkChoiceStore ¶
func (s *Service) InsertSlashingsToForkChoiceStore(ctx context.Context, slashings []*ethpb.AttesterSlashing)
InsertSlashingsToForkChoiceStore inserts attester slashing indices to fork choice store. To call this function, it's caller's responsibility to ensure the slashing object is valid. This function requires a write lock on forkchoice.
func (*Service) IsCanonical ¶
IsCanonical returns true if the input block root is part of the canonical chain.
func (*Service) IsFinalized ¶
IsFinalized returns true if the input root is finalized. It first checks latest finalized root then checks finalized root index in DB.
func (*Service) IsOptimistic ¶
IsOptimistic returns true if the current head is optimistic.
func (*Service) IsOptimisticForRoot ¶
IsOptimisticForRoot takes the root as argument instead of the current head and returns true if it is optimistic.
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) PreviousJustifiedCheckpt ¶
func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint
PreviousJustifiedCheckpt returns the current justified checkpoint from chain store.
func (*Service) ProposerBoost ¶ added in v4.0.1
ProposerBoost wraps the corresponding method from forkchoice
func (*Service) ReceiveAttesterSlashing ¶
func (s *Service) ReceiveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing)
ReceiveAttesterSlashing receives an attester slashing and inserts it to forkchoice
func (*Service) ReceiveBlock ¶
func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte) error
ReceiveBlock is a function that defines the operations (minus pubsub) that are performed on a received block. The operations consist of:
- Validate block, apply state transition and update checkpoints
- Apply fork choice to the processed block
- Save latest head info
func (*Service) ReceiveBlockBatch ¶
func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []interfaces.ReadOnlySignedBeaconBlock, blkRoots [][32]byte) error
ReceiveBlockBatch processes the whole block batch at once, assuming the block batch is linear ,transitioning the state, performing batch verification of all collected signatures and then performing the appropriate actions for a block post-transition.
func (*Service) ReceivedBlocksLastEpoch ¶ added in v4.0.1
ReceivedBlocksLastEpoch returns the corresponding value from forkchoice
func (*Service) SetForkChoiceGenesisTime ¶ added in v4.0.1
SetForkChoiceGenesisTime sets the genesis time in Forkchoice
func (*Service) SetGenesisTime ¶
SetGenesisTime sets the genesis time of beacon chain.
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) UnrealizedJustifiedPayloadBlockHash ¶ added in v4.0.2
UnrealizedJustifiedPayloadBlockHash returns unrealized justified payload block hash from forkchoice.
func (*Service) UpdateAndSaveHeadWithBalances ¶
UpdateAndSaveHeadWithBalances updates the beacon state head after getting justified balanced from cache. This function is only used in spec-tests, it does save the head after updating it.
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.
type SlashingReceiver ¶
type SlashingReceiver interface {
ReceiveAttesterSlashing(ctx context.Context, slashings *ethpb.AttesterSlashing)
}
SlashingReceiver interface defines the methods of chain service for receiving validated slashing over the wire.
type TimeFetcher ¶
type TimeFetcher interface { GenesisTime() time.Time CurrentSlot() primitives.Slot }
TimeFetcher retrieves the Ethereum consensus data that's related to time.
type WeakSubjectivityVerifier ¶
type WeakSubjectivityVerifier struct {
// contains filtered or unexported fields
}
func NewWeakSubjectivityVerifier ¶
func NewWeakSubjectivityVerifier(wsc *ethpb.Checkpoint, db weakSubjectivityDB) (*WeakSubjectivityVerifier, error)
NewWeakSubjectivityVerifier validates a checkpoint, and if valid, uses it to initialize a weak subjectivity verifier.
func (*WeakSubjectivityVerifier) VerifyWeakSubjectivity ¶
func (v *WeakSubjectivityVerifier) VerifyWeakSubjectivity(ctx context.Context, finalizedEpoch primitives.Epoch) error
VerifyWeakSubjectivity verifies the weak subjectivity root in the service struct. Reference design: https://github.com/ethereum/consensus-specs/blob/master/specs/phase0/weak-subjectivity.md#weak-subjectivity-sync-procedure
Source Files ¶
- chain_info.go
- chain_info_forkchoice.go
- error.go
- execution_engine.go
- forkchoice_update_execution.go
- head.go
- head_sync_committee_info.go
- init_sync_process_block.go
- log.go
- merge_ascii_art.go
- metrics.go
- options.go
- pow_block.go
- process_attestation.go
- process_attestation_helpers.go
- process_block.go
- process_block_helpers.go
- receive_attestation.go
- receive_block.go
- service.go
- weak_subjectivity_checks.go