Documentation ¶
Index ¶
- Constants
- func ValidateMsg(pb proto.Message) error
- type BlockPool
- func (pool *BlockPool) AddBlock(peerID p2p.ID, block *types.Block, blockSize int)
- func (pool *BlockPool) GetStatus() (height int64, numPending int32, lenRequesters int)
- func (pool *BlockPool) Height() int64
- func (pool *BlockPool) IsCaughtUp() bool
- func (pool *BlockPool) MaxPeerHeight() int64
- func (pool *BlockPool) OnStart() error
- func (pool *BlockPool) PeekTwoBlocks() (first *types.Block, second *types.Block)
- func (pool *BlockPool) PopRequest()
- func (pool *BlockPool) RedoRequest(height int64) p2p.IDdeprecated
- func (pool *BlockPool) RedoRequestFrom(height int64, peerID p2p.ID)
- func (pool *BlockPool) RemovePeer(peerID p2p.ID)
- func (pool *BlockPool) RemovePeerAndRedoAllPeerRequests(height int64) p2p.ID
- func (pool *BlockPool) SetPeerRange(peerID p2p.ID, base int64, height int64)
- type BlockRequest
- type Reactor
- func (bcR *Reactor) AddPeer(peer p2p.Peer)
- func (bcR *Reactor) BroadcastStatusRequest()
- func (bcR *Reactor) GetChannels() []*p2p.ChannelDescriptor
- func (bcR *Reactor) OnStart() error
- func (bcR *Reactor) OnStop()
- func (bcR *Reactor) ReceiveEnvelope(e p2p.Envelope)
- func (bcR *Reactor) RemovePeer(peer p2p.Peer, reason interface{})
- func (bcR *Reactor) SetLogger(l log.Logger)
- func (bcR *Reactor) SwitchToBlockSync(state sm.State) error
Constants ¶
const ( // NOTE: keep up to date with bcproto.BlockResponse BlockResponseMessagePrefixSize = 4 BlockResponseMessageFieldKeySize = 1 MaxMsgSize = types.MaxBlockSizeBytes + BlockResponseMessagePrefixSize + BlockResponseMessageFieldKeySize )
const ( // BlocksyncChannel is a channel for blocks and status updates (`BlockStore` height) BlocksyncChannel = byte(0x40) )
Variables ¶
This section is empty.
Functions ¶
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 ¶
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) GetStatus ¶
GetStatus returns pool's height, numPending requests and the number of requesters.
func (*BlockPool) IsCaughtUp ¶
IsCaughtUp returns true if this node is caught up, false - otherwise. TODO: relax conditions, prevent abuse.
func (*BlockPool) MaxPeerHeight ¶
MaxPeerHeight returns the highest reported height.
func (*BlockPool) OnStart ¶
OnStart implements service.Service by spawning requesters routine and recording pool's start time.
func (*BlockPool) PeekTwoBlocks ¶
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 removes the requester at pool.height and increments pool.height.
func (*BlockPool) RedoRequest
deprecated
func (*BlockPool) RedoRequestFrom ¶
RedoRequestFrom retries the request at the given height. It does not remove the peer.
func (*BlockPool) RemovePeer ¶
RemovePeer removes the peer with peerID from the pool. If there's no peer with peerID, function is a no-op.
func (*BlockPool) RemovePeerAndRedoAllPeerRequests ¶
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.
type BlockRequest ¶
BlockRequest stores a block request identified by the block Height and the PeerID responsible for delivering the block
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) *Reactor
NewReactor returns new reactor instance.
func NewReactorWithOfflineStateSync ¶
func NewReactorWithOfflineStateSync(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore, blockSync bool, offlineStateSyncHeight int64) *Reactor
func (*Reactor) BroadcastStatusRequest ¶
func (bcR *Reactor) BroadcastStatusRequest()
BroadcastStatusRequest broadcasts `BlockStore` base and height.
func (*Reactor) GetChannels ¶
func (bcR *Reactor) GetChannels() []*p2p.ChannelDescriptor
GetChannels implements Reactor
func (*Reactor) ReceiveEnvelope ¶
Receive implements Reactor by handling 4 types of messages (look below).
func (*Reactor) RemovePeer ¶
RemovePeer implements Reactor by removing peer from the pool.