Documentation ¶
Index ¶
- Constants
- type BlockCache
- type BlockInfo
- type BlockSyncMgr
- func (this *BlockSyncMgr) OnAddNode(nodeId p2pComm.PeerId)
- func (this *BlockSyncMgr) OnBlockReceive(fromID p2pComm.PeerId, blockSize uint32, block *types.Block, ...)
- func (this *BlockSyncMgr) OnDelNode(nodeId p2pComm.PeerId)
- func (this *BlockSyncMgr) OnHeaderReceive(fromID p2pComm.PeerId, headers []*types.Header)
- func (this *BlockSyncMgr) Start()
- func (this *BlockSyncMgr) Stop()
- type NodeWeight
- type NodeWeights
- type SyncFlightInfo
- func (this *SyncFlightInfo) GetFailedTimes(nodeId p2pComm.PeerId) int
- func (this *SyncFlightInfo) GetNodeId() p2pComm.PeerId
- func (this *SyncFlightInfo) GetStartTime() int64
- func (this *SyncFlightInfo) GetTotalFailedTimes() int
- func (this *SyncFlightInfo) MarkFailedNode()
- func (this *SyncFlightInfo) ResetStartTime()
- func (this *SyncFlightInfo) SetNodeId(nodeId p2pComm.PeerId)
Constants ¶
const ( SYNC_MAX_HEADER_FORWARD_SIZE = 5000 //keep CurrentHeaderHeight - CurrentBlockHeight <= SYNC_MAX_HEADER_FORWARD_SIZE SYNC_MAX_FLIGHT_HEADER_SIZE = 1 //Number of headers on flight SYNC_MAX_FLIGHT_BLOCK_SIZE = 50 //Number of blocks on flight SYNC_MAX_BLOCK_CACHE_SIZE = 500 //Cache size of block wait to commit to ledger SYNC_HEADER_REQUEST_TIMEOUT = 2 * time.Second //s, Request header timeout time. If header haven't receive after SYNC_HEADER_REQUEST_TIMEOUT second, retry SYNC_BLOCK_REQUEST_TIMEOUT = 2 * time.Second //s, Request block timeout time. If block haven't received after SYNC_BLOCK_REQUEST_TIMEOUT second, retry SYNC_NEXT_BLOCK_TIMES = 3 //Request times of next height block SYNC_NEXT_BLOCKS_HEIGHT = 2 //for current block height plus next SYNC_NODE_RECORD_SPEED_CNT = 3 //Record speed count for accuracy SYNC_NODE_RECORD_TIME_CNT = 3 //Record request time for accuracy SYNC_NODE_SPEED_INIT = 100 * 1024 //Init a big speed (100MB/s) for every node in first round SYNC_MAX_ERROR_RESP_TIMES = 5 //Max error headers/blocks response times, if reaches, delete it SYNC_MAX_HEIGHT_OFFSET = 5 //Offset of the max height and current height )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockCache ¶
type BlockCache struct {
// contains filtered or unexported fields
}
func NewBlockCache ¶
func NewBlockCache() *BlockCache
type BlockInfo ¶
type BlockInfo struct {
// contains filtered or unexported fields
}
BlockInfo is used for saving block information in cache
type BlockSyncMgr ¶
type BlockSyncMgr struct {
// contains filtered or unexported fields
}
BlockSyncMgr is the manager class to deal with block sync
func NewBlockSyncMgr ¶
func NewBlockSyncMgr(server p2p.P2P, ld *ledger.Ledger) *BlockSyncMgr
NewBlockSyncMgr return a BlockSyncMgr instance
func (*BlockSyncMgr) OnAddNode ¶
func (this *BlockSyncMgr) OnAddNode(nodeId p2pComm.PeerId)
OnAddPeer to node list when a new node added
func (*BlockSyncMgr) OnBlockReceive ¶
func (this *BlockSyncMgr) OnBlockReceive(fromID p2pComm.PeerId, blockSize uint32, block *types.Block, ccMsg *types.CrossChainMsg, merkleRoot common.Uint256)
OnBlockReceive receive block from net
func (*BlockSyncMgr) OnDelNode ¶
func (this *BlockSyncMgr) OnDelNode(nodeId p2pComm.PeerId)
OnDelNode remove from node list. When the node disconnect
func (*BlockSyncMgr) OnHeaderReceive ¶
func (this *BlockSyncMgr) OnHeaderReceive(fromID p2pComm.PeerId, headers []*types.Header)
OnHeaderReceive receive header from net
type NodeWeight ¶
type NodeWeight struct {
// contains filtered or unexported fields
}
NodeWeight record some params of node, using for sort
func NewNodeWeight ¶
func NewNodeWeight(id p2pComm.PeerId) *NodeWeight
NewNodeWeight new a nodeweight
func (*NodeWeight) AddErrorRespCnt ¶
func (this *NodeWeight) AddErrorRespCnt()
AddErrorRespCnt incre receive error header/block count
func (*NodeWeight) AddTimeoutCnt ¶
func (this *NodeWeight) AddTimeoutCnt()
AddTimeoutCnt incre timeout count
func (*NodeWeight) AppendNewReqtime ¶
func (this *NodeWeight) AppendNewReqtime()
AppendNewReqTime append new request time
func (*NodeWeight) AppendNewSpeed ¶
func (this *NodeWeight) AppendNewSpeed(s float32)
addNewSpeed apend the new speed to tail, remove the oldest one
func (*NodeWeight) GetErrorRespCnt ¶
func (this *NodeWeight) GetErrorRespCnt() int64
GetErrorRespCnt get the error response count
func (*NodeWeight) Weight ¶
func (this *NodeWeight) Weight() float32
Weight calculate node's weight for sort. Highest weight node will be accessed first for next request.
type NodeWeights ¶
type NodeWeights []*NodeWeight
NodeWeights implement sorting
func (NodeWeights) Len ¶
func (nws NodeWeights) Len() int
func (NodeWeights) Less ¶
func (nws NodeWeights) Less(i, j int) bool
func (NodeWeights) Swap ¶
func (nws NodeWeights) Swap(i, j int)
type SyncFlightInfo ¶
type SyncFlightInfo struct { Height uint32 //BlockHeight of HeaderHeight // contains filtered or unexported fields }
SyncFlightInfo record the info of fight object(header or block)
func NewSyncFlightInfo ¶
func NewSyncFlightInfo(height uint32, nodeId p2pComm.PeerId) *SyncFlightInfo
NewSyncFlightInfo return a new SyncFlightInfo instance
func (*SyncFlightInfo) GetFailedTimes ¶
func (this *SyncFlightInfo) GetFailedTimes(nodeId p2pComm.PeerId) int
GetFailedTimes return failed times of a node
func (*SyncFlightInfo) GetNodeId ¶
func (this *SyncFlightInfo) GetNodeId() p2pComm.PeerId
GetNodeId return current node id for sending msg
func (*SyncFlightInfo) GetStartTime ¶
func (this *SyncFlightInfo) GetStartTime() int64
GetStartTime return the start time of request
func (*SyncFlightInfo) GetTotalFailedTimes ¶
func (this *SyncFlightInfo) GetTotalFailedTimes() int
GetTotalFailedTimes return the total failed times of request
func (*SyncFlightInfo) MarkFailedNode ¶
func (this *SyncFlightInfo) MarkFailedNode()
MarkFailedNode mark node failed, after request timeout
func (*SyncFlightInfo) SetNodeId ¶
func (this *SyncFlightInfo) SetNodeId(nodeId p2pComm.PeerId)
SetNodeId set a new node id