sync

package
v3.2.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: GPL-3.0 Imports: 83 Imported by: 2

Documentation

Overview

Package sync TODO(3147): Add details on how sync works.

Package sync includes all chain-synchronization logic for the beacon node, including gossip-sub validators for blocks, attestations, and other p2p messages, as well as ability to process and respond to block requests by peers.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFetchedData = errors.New("invalid data returned from peer")

ErrInvalidFetchedData is thrown if stream fails to provide requested blocks.

View Source
var (
	ErrOptimisticParent = errors.New("parent of the block is optimistic")
)

Functions

func ReadChunkedBlock

func ReadChunkedBlock(stream libp2pcore.Stream, chain blockchain.ForkFetcher, p2p p2p.EncodingProvider, isFirstChunk bool) (interfaces.SignedBeaconBlock, error)

ReadChunkedBlock handles each response chunk that is sent by the peer and converts it into a beacon block.

func ReadStatusCode

func ReadStatusCode(stream network.Stream, encoding encoder.NetworkEncoding) (uint8, string, error)

ReadStatusCode response from a RPC stream.

func SendBeaconBlocksByRangeRequest

func SendBeaconBlocksByRangeRequest(
	ctx context.Context, chain blockchain.ForkFetcher, p2pProvider p2p.SenderEncoder, pid peer.ID,
	req *pb.BeaconBlocksByRangeRequest, blockProcessor BeaconBlockProcessor,
) ([]interfaces.SignedBeaconBlock, error)

SendBeaconBlocksByRangeRequest sends BeaconBlocksByRange and returns fetched blocks, if any.

func SendBeaconBlocksByRootRequest

func SendBeaconBlocksByRootRequest(
	ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID,
	req *p2ptypes.BeaconBlockByRootsReq, blockProcessor BeaconBlockProcessor,
) ([]interfaces.SignedBeaconBlock, error)

SendBeaconBlocksByRootRequest sends BeaconBlocksByRoot and returns fetched blocks, if any.

func SetRPCStreamDeadlines

func SetRPCStreamDeadlines(stream network.Stream)

SetRPCStreamDeadlines sets read and write deadlines for libp2p-based connection streams.

func SetStreamReadDeadline

func SetStreamReadDeadline(stream network.Stream, duration time.Duration)

SetStreamReadDeadline for reading from libp2p connection streams, deciding when to close a connection based on a particular duration.

NOTE: libp2p uses the system clock time for determining the deadline so we use time.Now() instead of the synchronized roughtime.Now(). If the system time is corrupted (i.e. time does not advance), the node will experience issues being able to properly close streams, leading to unexpected failures and possible memory leaks.

func SetStreamWriteDeadline

func SetStreamWriteDeadline(stream network.Stream, duration time.Duration)

SetStreamWriteDeadline for writing to libp2p connection streams, deciding when to close a connection based on a particular duration.

NOTE: libp2p uses the system clock time for determining the deadline so we use time.Now() instead of the synchronized roughtime.Now(). If the system time is corrupted (i.e. time does not advance), the node will experience issues being able to properly close streams, leading to unexpected failures and possible memory leaks.

func WriteBlockChunk

WriteBlockChunk writes block chunk object to stream. response_chunk ::= <result> | <context-bytes> | <encoding-dependent-header> | <encoded-payload>

Types

type BeaconBlockProcessor

type BeaconBlockProcessor func(block interfaces.SignedBeaconBlock) error

BeaconBlockProcessor defines a block processing function, which allows to start utilizing blocks even before all blocks are ready.

type Checker

type Checker interface {
	Initialized() bool
	Syncing() bool
	Synced() bool
	Status() error
	Resync() error
}

Checker defines a struct which can verify whether a node is currently synchronizing a chain with the rest of peers in the network.

type Option

type Option func(s *Service) error

func WithAttestationNotifier

func WithAttestationNotifier(notifier operation.Notifier) Option

func WithAttestationPool

func WithAttestationPool(attPool attestations.Pool) Option

func WithBlockNotifier

func WithBlockNotifier(blockNotifier blockfeed.Notifier) Option

func WithBlsToExecPool added in v3.2.0

func WithBlsToExecPool(blsToExecPool blstoexec.PoolManager) Option

func WithChainService

func WithChainService(chain blockchainService) Option

func WithDatabase

func WithDatabase(db db.NoHeadAccessDatabase) Option

func WithExecutionPayloadReconstructor

func WithExecutionPayloadReconstructor(r execution.ExecutionPayloadReconstructor) Option

func WithExitPool

func WithExitPool(exitPool voluntaryexits.PoolManager) Option

func WithInitialSync

func WithInitialSync(initialSync Checker) Option

func WithOperationNotifier

func WithOperationNotifier(operationNotifier operation.Notifier) Option

func WithP2P

func WithP2P(p2p p2p.P2P) Option

func WithSlasherAttestationsFeed

func WithSlasherAttestationsFeed(slasherAttestationsFeed *event.Feed) Option

func WithSlasherBlockHeadersFeed

func WithSlasherBlockHeadersFeed(slasherBlockHeadersFeed *event.Feed) Option

func WithSlashingPool

func WithSlashingPool(slashingPool slashings.PoolManager) Option

func WithStateGen

func WithStateGen(stateGen *stategen.State) Option

func WithStateNotifier

func WithStateNotifier(stateNotifier statefeed.Notifier) Option

func WithSyncCommsPool

func WithSyncCommsPool(syncCommsPool synccommittee.Pool) Option

type Service

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

Service is responsible for handling all run time p2p related operations as the main entry point for network messages.

func NewService

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

NewService initializes new regular sync service.

func (*Service) Start

func (s *Service) Start()

Start the regular sync service.

func (*Service) Status

func (s *Service) Status() error

Status of the currently running regular sync service.

func (*Service) Stop

func (s *Service) Stop() error

Stop the regular sync service.

Directories

Path Synopsis
Package initialsync includes all initial block download and processing logic for the beacon node, using a round robin strategy and a finite-state-machine to handle edge-cases in a beacon node's sync status.
Package initialsync includes all initial block download and processing logic for the beacon node, using a round robin strategy and a finite-state-machine to handle edge-cases in a beacon node's sync status.
testing
Package testing includes useful mocks for testing initial sync status in unit tests.
Package testing includes useful mocks for testing initial sync status in unit tests.

Jump to

Keyboard shortcuts

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