Documentation
¶
Index ¶
Constants ¶
View Source
const (
SyncPeerClientLoggerName = "sync-peer-client"
)
View Source
const (
WriteBlockSource = "syncer"
)
Variables ¶
View Source
var ( ErrLoadLocalGenesisFailed = errors.New("failed to read local genesis") ErrMismatchGenesis = errors.New("genesis does not match") ErrCommonAncestorNotFound = errors.New("header is nil") ErrForkNotFound = errors.New("fork not found") ErrPopTimeout = errors.New("timeout") ErrConnectionClosed = errors.New("connection closed") ErrTooManyHeaders = errors.New("unexpected more than 1 result") ErrDecodeDifficulty = errors.New("failed to decode difficulty") ErrInvalidTypeAssertion = errors.New("invalid type assertion") ErrBlockVerifyFailed = errors.New("block verifying failed") )
Functions ¶
func NewMockBlockchain ¶
Types ¶
type Blockchain ¶ added in v1.2.1
type Blockchain interface { // SubscribeEvents subscribes new blockchain event SubscribeEvents() blockchain.Subscription Header() *types.Header // deprecated methods. Those are old version protocols, keep it only for backward compatible CurrentTD() *big.Int GetTD(hash types.Hash) (*big.Int, bool) GetReceiptsByHash(types.Hash) ([]*types.Receipt, error) GetBodyByHash(types.Hash) (*types.Body, bool) GetHeaderByHash(types.Hash) (*types.Header, bool) GetHeaderByNumber(n uint64) (*types.Header, bool) CalculateGasLimit(number uint64) (uint64, error) // advance chain methods WriteBlock(block *types.Block, source string) error VerifyFinalizedBlock(block *types.Block) error // GetBlockByNumber returns block by number GetBlockByNumber(uint64, bool) (*types.Block, bool) }
Blockchain is the interface required by the syncer to connect to the blockchain
type NoForkPeer ¶ added in v1.2.1
func (*NoForkPeer) IsBetter ¶ added in v1.2.1
func (p *NoForkPeer) IsBetter(t *NoForkPeer) bool
type PeerMap ¶ added in v1.2.1
func NewPeerMap ¶ added in v1.2.1
func NewPeerMap(peers []*NoForkPeer) *PeerMap
func (*PeerMap) BestPeer ¶ added in v1.2.1
func (m *PeerMap) BestPeer(skipMap *map[peer.ID]int64) *NoForkPeer
BestPeer returns the top of heap
func (*PeerMap) Put ¶ added in v1.2.1
func (m *PeerMap) Put(peers ...*NoForkPeer)
type Progression ¶ added in v1.2.1
type Progression interface { // StartProgression starts progression StartProgression(syncingPeer string, startingBlock uint64, subscription blockchain.Subscription) // UpdateHighestProgression updates highest block number UpdateHighestProgression(highestBlock uint64) // GetProgression returns Progression GetProgression() *progress.Progression // StopProgression finishes progression StopProgression() }
type Status ¶
type Status struct { Difficulty *big.Int // Current difficulty Hash types.Hash // Latest block hash Number uint64 // Latest block number }
Status defines the up to date information regarding the peer
func HeaderToStatus ¶
HeaderToStatus converts given header to Status
type SyncPeerClient ¶ added in v1.2.1
type SyncPeerClient interface { // Start processes for SyncPeerClient Start() error // Close terminates running processes for SyncPeerClient Close() // GetPeerStatus fetches peer status GetPeerStatus(id peer.ID) (*NoForkPeer, error) // GetConnectedPeerStatuses fetches the statuses of all connecting peers GetConnectedPeerStatuses() []*NoForkPeer // GetBlocks returns a stream of blocks from given height to peer's latest GetBlocks(ctx context.Context, peerID peer.ID, from uint64, to uint64) ([]*types.Block, error) // GetPeerStatusUpdateCh returns a channel of peer's status update GetPeerStatusUpdateCh() <-chan *NoForkPeer // GetPeerConnectionUpdateEventCh returns peer's connection change event GetPeerConnectionUpdateEventCh() <-chan *event.PeerEvent // DisablePublishingPeerStatus disables publishing status in syncer topic DisablePublishingPeerStatus() // EnablePublishingPeerStatus enables publishing status in syncer topic EnablePublishingPeerStatus() // broadcast block to all its connected peers Broadcast(block *types.Block) error }
func NewSyncPeerClient ¶ added in v1.2.1
func NewSyncPeerClient( logger hclog.Logger, network network.Network, blockchain Blockchain, ) SyncPeerClient
type SyncPeerService ¶ added in v1.2.1
type SyncPeerService interface { // Start starts server Start() // Close terminates running processes for SyncPeerService Close() error // SetSyncer sets referent syncer SetSyncer(syncer *noForkSyncer) }
func NewSyncPeerService ¶ added in v1.2.1
func NewSyncPeerService( network network.Network, blockchain Blockchain, ) SyncPeerService
type Syncer ¶
type Syncer interface { // Start starts syncer processes Start() error // Close terminates syncer process Close() error // GetSyncProgression returns sync progression GetSyncProgression() *progress.Progression // HasSyncPeer returns whether syncer has the peer syncer can sync with HasSyncPeer() bool // IsSyncing returns whether syncer is syncing IsSyncing() bool // Sync starts routine to sync blocks Sync(func(*types.Block) bool) error }
Syncer is a sync protocol for block downloading
Source Files
¶
Click to show internal directories.
Click to hide internal directories.