Documentation ¶
Index ¶
- Constants
- Variables
- func CompareBlockByHash(a *types.Block, b *types.Block) int
- func CompareSyncPeerConfigByblockHashes(a *SyncPeerConfig, b *SyncPeerConfig) int
- func GetHowManyMaxConsensus(blocks []*types.Block) (int, int)
- func GetSyncingPort(nodePort string) string
- type StateSync
- func (ss *StateSync) AddLastMileBlock(block *types.Block)
- func (ss *StateSync) AddNewBlock(peerHash []byte, block *types.Block)
- func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer, isBeacon bool) error
- func (ss *StateSync) GetActivePeerNumber() int
- func (ss *StateSync) GetConsensusHashes(startHash []byte, size uint32) bool
- func (ss *StateSync) IsOutOfSync(bc *core.BlockChain) bool
- func (ss *StateSync) IsSameBlockchainHeight(bc *core.BlockChain) (uint64, bool)
- func (ss *StateSync) ProcessStateSync(startHash []byte, size uint32, bc *core.BlockChain, worker *worker.Worker)
- func (ss *StateSync) RegisterNodeInfo() int
- func (ss *StateSync) SyncLoop(bc *core.BlockChain, worker *worker.Worker, isBeacon bool, ...)
- type SyncBlockTask
- type SyncConfig
- func (sc *SyncConfig) AddPeer(peer *SyncPeerConfig)
- func (sc *SyncConfig) CloseConnections()
- func (sc *SyncConfig) FindPeerByHash(peerHash []byte) *SyncPeerConfig
- func (sc *SyncConfig) ForEachPeer(f func(peer *SyncPeerConfig) (brk bool))
- func (sc *SyncConfig) GetBlockHashesConsensusAndCleanUp() bool
- func (sc *SyncConfig) InitForTesting(client *downloader.Client, blockHashes [][]byte)
- type SyncPeerConfig
Constants ¶
const ( SleepTimeAfterNonConsensusBlockHashes = time.Second * 30 TimesToFail = 5 // Downloadblocks service retry limit RegistrationNumber = 3 SyncingPortDifference = 3000 BatchSize uint32 = 1000 //maximum size for one query of block hashes SyncLoopFrequency = 1 // unit in second LastMileBlocksSize = 10 )
Constants for syncing.
Variables ¶
var ( ErrRegistrationFail = errors.New("[SYNC]: registration failed") ErrGetBlock = errors.New("[SYNC]: get block failed") ErrGetBlockHash = errors.New("[SYNC]: get blockhash failed") )
Errors ...
Functions ¶
func CompareBlockByHash ¶
CompareBlockByHash compares two block by hash, it will be used in sort the blocks
func CompareSyncPeerConfigByblockHashes ¶
func CompareSyncPeerConfigByblockHashes(a *SyncPeerConfig, b *SyncPeerConfig) int
CompareSyncPeerConfigByblockHashes compares two SyncPeerConfig by blockHashes.
func GetHowManyMaxConsensus ¶
GetHowManyMaxConsensus will get the most common blocks and the first such blockID
func GetSyncingPort ¶
GetSyncingPort returns the syncing port.
Types ¶
type StateSync ¶
type StateSync struct {
// contains filtered or unexported fields
}
StateSync is the struct that implements StateSyncInterface.
func CreateStateSync ¶
CreateStateSync returns the implementation of StateSyncInterface interface.
func (*StateSync) AddLastMileBlock ¶
AddLastMileBlock add the lastest a few block into queue for syncing only keep the latest blocks with size capped by LastMileBlocksSize
func (*StateSync) AddNewBlock ¶
AddNewBlock will add newly received block into state syncing queue
func (*StateSync) CreateSyncConfig ¶
CreateSyncConfig creates SyncConfig for StateSync object.
func (*StateSync) GetActivePeerNumber ¶
GetActivePeerNumber returns the number of active peers
func (*StateSync) GetConsensusHashes ¶
GetConsensusHashes gets all hashes needed to download.
func (*StateSync) IsOutOfSync ¶
func (ss *StateSync) IsOutOfSync(bc *core.BlockChain) bool
IsOutOfSync checks whether the node is out of sync from other peers
func (*StateSync) IsSameBlockchainHeight ¶
func (ss *StateSync) IsSameBlockchainHeight(bc *core.BlockChain) (uint64, bool)
IsSameBlockchainHeight checks whether the node is out of sync from other peers
func (*StateSync) ProcessStateSync ¶
func (ss *StateSync) ProcessStateSync(startHash []byte, size uint32, bc *core.BlockChain, worker *worker.Worker)
ProcessStateSync processes state sync from the blocks received but not yet processed so far TODO: return error
func (*StateSync) RegisterNodeInfo ¶
RegisterNodeInfo will register node to peers to accept future new block broadcasting return number of successful registration
type SyncBlockTask ¶
type SyncBlockTask struct {
// contains filtered or unexported fields
}
SyncBlockTask is the task struct to sync a specific block.
type SyncConfig ¶
type SyncConfig struct {
// contains filtered or unexported fields
}
SyncConfig contains an array of SyncPeerConfig.
func (*SyncConfig) AddPeer ¶
func (sc *SyncConfig) AddPeer(peer *SyncPeerConfig)
AddPeer adds the given sync peer.
func (*SyncConfig) CloseConnections ¶
func (sc *SyncConfig) CloseConnections()
CloseConnections close grpc connections for state sync clients
func (*SyncConfig) FindPeerByHash ¶
func (sc *SyncConfig) FindPeerByHash(peerHash []byte) *SyncPeerConfig
FindPeerByHash returns the peer with the given hash, or nil if not found.
func (*SyncConfig) ForEachPeer ¶
func (sc *SyncConfig) ForEachPeer(f func(peer *SyncPeerConfig) (brk bool))
ForEachPeer calls the given function with each peer. It breaks the iteration iff the function returns true.
func (*SyncConfig) GetBlockHashesConsensusAndCleanUp ¶
func (sc *SyncConfig) GetBlockHashesConsensusAndCleanUp() bool
GetBlockHashesConsensusAndCleanUp chesk if all consensus hashes are equal.
func (*SyncConfig) InitForTesting ¶
func (sc *SyncConfig) InitForTesting(client *downloader.Client, blockHashes [][]byte)
InitForTesting used for testing.
type SyncPeerConfig ¶
type SyncPeerConfig struct {
// contains filtered or unexported fields
}
SyncPeerConfig is peer config to sync.
func CreateTestSyncPeerConfig ¶
func CreateTestSyncPeerConfig(client *downloader.Client, blockHashes [][]byte) *SyncPeerConfig
CreateTestSyncPeerConfig used for testing.
func (*SyncPeerConfig) GetBlocks ¶
func (peerConfig *SyncPeerConfig) GetBlocks(hashes [][]byte) ([][]byte, error)
GetBlocks gets blocks by calling grpc request to the corresponding peer.
func (*SyncPeerConfig) GetClient ¶
func (peerConfig *SyncPeerConfig) GetClient() *downloader.Client
GetClient returns client pointer of downloader.Client