Documentation ¶
Index ¶
- Constants
- func RegisterBlockchainMessages(cdc *amino.Codec)
- 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) 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.ID
- func (pool *BlockPool) RemovePeer(peerID p2p.ID)
- func (pool *BlockPool) SetPeerRange(peerID p2p.ID, base int64, height int64)
- type BlockRequest
- type BlockchainMessage
- type BlockchainReactor
- func (bcR *BlockchainReactor) AddPeer(peer p2p.Peer)
- func (bcR *BlockchainReactor) BroadcastStatusRequest() error
- func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor
- func (bcR *BlockchainReactor) OnStart() error
- func (bcR *BlockchainReactor) OnStop()
- func (bcR *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
- func (bcR *BlockchainReactor) RemovePeer(peer p2p.Peer, reason interface{})
- func (bcR *BlockchainReactor) SetLogger(l log.Logger)
Constants ¶
const ( // BlockchainChannel is a channel for blocks and status updates (`BlockStore` height) BlockchainChannel = byte(0x40) )
Variables ¶
This section is empty.
Functions ¶
func RegisterBlockchainMessages ¶
RegisterBlockchainMessages registers the fast sync messages for amino encoding.
Types ¶
type BlockPool ¶
type BlockPool struct { service.BaseService // contains filtered or unexported fields }
BlockPool 保持追踪快速同步的peer,区块请求和区块回复
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. TODO: ensure that blocks come in order for each peer.
func (*BlockPool) IsCaughtUp ¶
IsCaughtUp 检查node是否已经追赶上了,如果是则返回true TODO: relax conditions, prevent abuse.
func (*BlockPool) MaxPeerHeight ¶
MaxPeerHeight 返回所有peer中报告的最高高度
func (*BlockPool) OnStart ¶
OnStart implements service.Service by spawning requesters routine and recording pool's start time.
func (*BlockPool) PeekTwoBlocks ¶
PeekTwoBlocks 返回池中height和height+1的两个区块, 使用第二个块来验证第一个块
func (*BlockPool) PopRequest ¶
func (pool *BlockPool) PopRequest()
PopRequest 弹出高度为height的区块,它必须被高度为Height+1的区块验证过才能弹出。
func (*BlockPool) RedoRequest ¶
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 ¶
RemovePeer 从池中删除给定peerID的peer。 如果没有给定peerID的peer,则方法为无操作。
type BlockRequest ¶
BlockRequest stores a block request identified by the block Height and the PeerID responsible for delivering the block
type BlockchainMessage ¶
type BlockchainMessage interface {
ValidateBasic() error
}
BlockchainMessage is a generic message for this reactor.
type BlockchainReactor ¶
type BlockchainReactor struct { p2p.BaseReactor // contains filtered or unexported fields }
BlockchainReactor 处理长期追赶同步
func NewBlockchainReactor ¶
func NewBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore, fastSync bool) *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, src p2p.Peer, msgBytes []byte)
Receive implements Reactor by handling 4 types of messages (look below).
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.