blocksync

package
v100.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NOTE: keep up to date with bcproto.BlockResponse.
	BlockResponseMessagePrefixSize   = 4
	BlockResponseMessageFieldKeySize = 1
	MaxMsgSize                       = types.MaxBlockSizeBytes +
		BlockResponseMessagePrefixSize +
		BlockResponseMessageFieldKeySize
)
View Source
const (
	// BlocksyncChannel is a channel for blocks and status updates (`BlockStore` height).
	BlocksyncChannel = byte(0x40)
)
View Source
const (
	// MetricsSubsystem is a subsystem shared by all metrics exposed by this
	// package.
	MetricsSubsystem = "blocksync"
)

Variables

View Source
var ErrNilMessage = errors.New("message cannot be nil")

ErrNilMessage is returned when provided message is empty.

Functions

func ValidateMsg

func ValidateMsg(pb proto.Message) error

ValidateMsg validates a message.

Types

type BlockPool

type BlockPool struct {
	service.BaseService
	// contains filtered or unexported fields
}

BlockPool keeps track of the block sync peers, block requests and block responses.

func NewBlockPool

func NewBlockPool(start int64, requestsCh chan<- BlockRequest, errorsCh chan<- peerError) *BlockPool

NewBlockPool returns a new BlockPool with the height equal to start. Block requests and errors will be sent to requestsCh and errorsCh accordingly.

func (*BlockPool) AddBlock

func (pool *BlockPool) AddBlock(peerID p2p.ID, block *types.Block, extCommit *types.ExtendedCommit, blockSize int) error

AddBlock validates that the block comes from the peer it was expected from and calls the requester to store it.

This requires an extended commit at the same height as the supplied block - the block contains the last commit, but we need the latest commit in case we need to switch over from block sync to consensus at this height. If the height of the extended commit and the height of the block do not match, we do not add the block and return an error. TODO: ensure that blocks come in order for each peer.

func (*BlockPool) Height

func (pool *BlockPool) Height() int64

Height returns the pool's height.

func (*BlockPool) IsCaughtUp

func (pool *BlockPool) IsCaughtUp() (isCaughtUp bool, height, maxPeerHeight int64)

IsCaughtUp returns true if this node is caught up, false - otherwise. TODO: relax conditions, prevent abuse.

func (*BlockPool) MaxPeerHeight

func (pool *BlockPool) MaxPeerHeight() int64

MaxPeerHeight returns the highest reported height.

func (*BlockPool) OnStart

func (pool *BlockPool) OnStart() error

OnStart implements service.Service by spawning requesters routine and recording pool's start time.

func (*BlockPool) PeekTwoBlocks

func (pool *BlockPool) PeekTwoBlocks() (first, second *types.Block, firstExtCommit *types.ExtendedCommit)

PeekTwoBlocks returns blocks at pool.height and pool.height+1. We need to see the second block's Commit to validate the first block. So we peek two blocks at a time. We return an extended commit, containing vote extensions and their associated signatures, as this is critical to consensus in ABCI++ as we switch from block sync to consensus mode.

The caller will verify the commit.

func (*BlockPool) PopRequest

func (pool *BlockPool) PopRequest()

PopRequest removes the requester at pool.height and increments pool.height.

func (*BlockPool) RedoRequest deprecated

func (pool *BlockPool) RedoRequest(height int64) p2p.ID

Deprecated: use RemovePeerAndRedoAllPeerRequests instead.

func (*BlockPool) RedoRequestFrom

func (pool *BlockPool) RedoRequestFrom(height int64, peerID p2p.ID)

RedoRequestFrom retries the request at the given height. It does not remove the peer.

func (*BlockPool) RemovePeer

func (pool *BlockPool) RemovePeer(peerID p2p.ID)

RemovePeer removes the peer with peerID from the pool. If there's no peer with peerID, function is a no-op.

func (*BlockPool) RemovePeerAndRedoAllPeerRequests

func (pool *BlockPool) RemovePeerAndRedoAllPeerRequests(height int64) p2p.ID

RemovePeerAndRedoAllPeerRequests retries the request at the given height and all the requests made to the same peer. The peer is removed from the pool. Returns the ID of the removed peer.

func (*BlockPool) SetPeerRange

func (pool *BlockPool) SetPeerRange(peerID p2p.ID, base int64, height int64)

SetPeerRange sets the peer's alleged blockchain base and height.

type BlockRequest

type BlockRequest struct {
	Height int64
	PeerID p2p.ID
}

BlockRequest stores a block request identified by the block Height and the PeerID responsible for delivering the block.

type ErrInvalidBase

type ErrInvalidBase struct {
	Base   int64
	Reason string
}

ErrInvalidBase is returned when peer informs of a status with invalid base.

func (ErrInvalidBase) Error

func (e ErrInvalidBase) Error() string

type ErrInvalidHeight

type ErrInvalidHeight struct {
	Height int64
	Reason string
}

ErrInvalidBase is returned when peer informs of a status with invalid height.

func (ErrInvalidHeight) Error

func (e ErrInvalidHeight) Error() string

type ErrReactorValidation

type ErrReactorValidation struct {
	Err error
}

func (ErrReactorValidation) Error

func (e ErrReactorValidation) Error() string

func (ErrReactorValidation) Unwrap

func (e ErrReactorValidation) Unwrap() error

type ErrUnknownMessageType

type ErrUnknownMessageType struct {
	Msg proto.Message
}

func (ErrUnknownMessageType) Error

func (e ErrUnknownMessageType) Error() string

type Metrics

type Metrics struct {
	// Whether or not a node is block syncing. 1 if yes, 0 if no.
	Syncing metrics.Gauge
	// Number of transactions in the latest block.
	NumTxs metrics.Gauge
	// Total number of transactions.
	TotalTxs metrics.Gauge
	// Size of the latest block.
	BlockSizeBytes metrics.Gauge
	// The height of the latest block.
	LatestBlockHeight metrics.Gauge
}

Metrics contains metrics exposed by this package.

func NopMetrics

func NopMetrics() *Metrics

func PrometheusMetrics

func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics

type Reactor

type Reactor struct {
	p2p.BaseReactor
	// contains filtered or unexported fields
}

Reactor handles long-term catchup syncing.

func NewReactor

func NewReactor(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore,
	blockSync bool, metrics *Metrics, offlineStateSyncHeight int64,
) *Reactor

NewReactor returns new reactor instance.

func (*Reactor) AddPeer

func (bcR *Reactor) AddPeer(peer p2p.Peer)

AddPeer implements Reactor by sending our state to peer.

func (*Reactor) BroadcastStatusRequest

func (bcR *Reactor) BroadcastStatusRequest()

BroadcastStatusRequest broadcasts `BlockStore` base and height.

func (*Reactor) GetChannels

func (*Reactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels implements Reactor.

func (*Reactor) OnStart

func (bcR *Reactor) OnStart() error

OnStart implements service.Service.

func (*Reactor) OnStop

func (bcR *Reactor) OnStop()

OnStop implements service.Service.

func (*Reactor) Receive

func (bcR *Reactor) Receive(e p2p.Envelope)

Receive implements Reactor by handling 4 types of messages (look below).

func (*Reactor) RemovePeer

func (bcR *Reactor) RemovePeer(peer p2p.Peer, _ any)

RemovePeer implements Reactor by removing peer from the pool.

func (*Reactor) SetLogger

func (bcR *Reactor) SetLogger(l log.Logger)

SetLogger implements service.Service by setting the logger on reactor and pool.

func (*Reactor) SwitchToBlockSync

func (bcR *Reactor) SwitchToBlockSync(state sm.State) error

SwitchToBlockSync is called by the state sync reactor when switching to block sync.

Jump to

Keyboard shortcuts

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