v0

package
v0.35.9 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockSyncChannel is a channel for blocks and status updates
	BlockSyncChannel = p2p.ChannelID(0x40)
)

Variables

View Source
var (

	// ChannelShims contains a map of ChannelDescriptorShim objects, where each
	// object wraps a reference to a legacy p2p ChannelDescriptor and the corresponding
	// p2p proto.Message the new p2p Channel is responsible for handling.
	//
	//
	// TODO: Remove once p2p refactor is complete.
	// ref: https://github.com/tendermint/tendermint/issues/5670
	ChannelShims = map[p2p.ChannelID]*p2p.ChannelDescriptorShim{
		BlockSyncChannel: {
			MsgType: new(bcproto.Message),
			Descriptor: &p2p.ChannelDescriptor{
				ID:                  byte(BlockSyncChannel),
				Priority:            5,
				SendQueueCapacity:   1000,
				RecvBufferCapacity:  1024,
				RecvMessageCapacity: blocksync.MaxMsgSize,
				MaxSendBytes:        100,
			},
		},
	}
)

Functions

This section is empty.

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 types.NodeID, block *types.Block, blockSize int)

AddBlock validates that the block comes from the peer it was expected from and calls the requester to store it. TODO: ensure that blocks come in order for each peer.

func (*BlockPool) GetStatus

func (pool *BlockPool) GetStatus() (height int64, numPending int32, lenRequesters int)

GetStatus returns pool's height, numPending requests and the number of requesters.

func (*BlockPool) IsCaughtUp

func (pool *BlockPool) IsCaughtUp() bool

IsCaughtUp returns true if this node is caught up, false - otherwise.

func (*BlockPool) LastAdvance

func (pool *BlockPool) LastAdvance() time.Time

LastAdvance returns the time when the last block was processed (or start time if no blocks were processed).

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 *types.Block, second *types.Block)

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. The caller will verify the commit.

func (*BlockPool) PopRequest

func (pool *BlockPool) PopRequest()

PopRequest pops the first block at pool.height. It must have been validated by 'second'.Commit from PeekTwoBlocks().

func (*BlockPool) RedoRequest

func (pool *BlockPool) RedoRequest(height int64) types.NodeID

RedoRequest invalidates the block at pool.height, Remove the peer and redo request from others. Returns the ID of the removed peer.

func (*BlockPool) RemovePeer

func (pool *BlockPool) RemovePeer(peerID types.NodeID)

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

func (*BlockPool) SetPeerRange

func (pool *BlockPool) SetPeerRange(peerID types.NodeID, base int64, height int64)

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

type BlockRequest

type BlockRequest struct {
	Height int64
	PeerID types.NodeID
}

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

type Reactor

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

Reactor handles long-term catchup syncing.

func NewReactor

func NewReactor(
	logger log.Logger,
	state sm.State,
	blockExec *sm.BlockExecutor,
	store *store.BlockStore,
	consReactor consensusReactor,
	blockSyncCh *p2p.Channel,
	peerUpdates *p2p.PeerUpdates,
	blockSync bool,
	metrics *consensus.Metrics,
) (*Reactor, error)

NewReactor returns new reactor instance.

func (*Reactor) GetMaxPeerBlockHeight

func (r *Reactor) GetMaxPeerBlockHeight() int64

func (*Reactor) GetRemainingSyncTime

func (r *Reactor) GetRemainingSyncTime() time.Duration

func (*Reactor) GetTotalSyncedTime

func (r *Reactor) GetTotalSyncedTime() time.Duration

func (*Reactor) OnStart

func (r *Reactor) OnStart() error

OnStart starts separate go routines for each p2p Channel and listens for envelopes on each. In addition, it also listens for peer updates and handles messages on that p2p channel accordingly. The caller must be sure to execute OnStop to ensure the outbound p2p Channels are closed.

If blockSync is enabled, we also start the pool and the pool processing goroutine. If the pool fails to start, an error is returned.

func (*Reactor) OnStop

func (r *Reactor) OnStop()

OnStop stops the reactor by signaling to all spawned goroutines to exit and blocking until they all exit.

func (*Reactor) SwitchToBlockSync

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

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

Jump to

Keyboard shortcuts

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