v0

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockchainChannel is a channel for blocks and status updates (`BlockStore` height)
	BlockchainChannel = byte(0x40)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockPool

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

BlockPool keeps track of the fast 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, 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. 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 *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) p2p.ID

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 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) 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 BlockchainReactor

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

BlockchainReactor handles long-term catchup syncing.

func NewBlockchainReactor

func NewBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore,
	fastSync bool, async bool, recvBufSize int) *BlockchainReactor

NewBlockchainReactor returns new reactor instance.

func (*BlockchainReactor) AddPeer

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

AddPeer implements Reactor by sending our state to peer.

func (*BlockchainReactor) BroadcastStatusRequest

func (bcR *BlockchainReactor) BroadcastStatusRequest() error

BroadcastStatusRequest broadcasts `BlockStore` base and height.

func (*BlockchainReactor) GetChannels

func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels implements Reactor

func (*BlockchainReactor) OnStart

func (bcR *BlockchainReactor) OnStart() error

OnStart implements service.Service.

func (*BlockchainReactor) OnStop

func (bcR *BlockchainReactor) OnStop()

OnStop implements service.Service.

func (*BlockchainReactor) Receive

func (bcR *BlockchainReactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte)

func (*BlockchainReactor) ReceiveEnvelope added in v1.1.1

func (bcR *BlockchainReactor) ReceiveEnvelope(e p2p.Envelope)

func (*BlockchainReactor) RemovePeer

func (bcR *BlockchainReactor) RemovePeer(peer p2p.Peer, reason interface{})

RemovePeer implements Reactor by removing peer from the pool.

func (*BlockchainReactor) SetLogger

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

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

func (*BlockchainReactor) SwitchToFastSync

func (bcR *BlockchainReactor) SwitchToFastSync(state sm.State) error

SwitchToFastSync 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