syncer

package
v0.0.0-...-3672da2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncPeerClientLoggerName = "sync-peer-client"
)

Variables

View Source
var (
	ErrBlockNotFound = errors.New("block not found")
)

Functions

This section is empty.

Types

type Blockchain

type Blockchain interface {
	// SubscribeEvents subscribes new blockchain event
	SubscribeEvents() blockchain.Subscription
	// Header returns get latest header
	Header() *types.Header
	// GetBlockByNumber returns block by number
	GetBlockByNumber(uint64, bool) (*types.Block, bool)
	// VerifyFinalizedBlock verifies finalized block
	VerifyFinalizedBlock(*types.Block) error
	// WriteBlock writes a given block to chain
	WriteBlock(*types.Block, string) error
}

type Network

type Network interface {
	// AddrInfo returns Network Info
	AddrInfo() *peer.AddrInfo
	// RegisterProtocol registers gRPC service
	RegisterProtocol(string, network.Protocol)
	// Peers returns current connected peers
	Peers() []*network.PeerConnInfo
	// SubscribeCh returns a channel of peer event
	SubscribeCh() (<-chan *event.PeerEvent, error)
	// GetPeerDistance returns the distance between the node and given peer
	GetPeerDistance(peer.ID) *big.Int
	// NewProtoConnection opens up a new stream on the set protocol to the peer,
	// and returns a reference to the connection
	NewProtoConnection(protocol string, peerID peer.ID) (*rawGrpc.ClientConn, error)
	// NewTopic Creates New Topic for gossip
	NewTopic(protoID string, obj proto.Message) (*network.Topic, error)
	// IsConnected returns the node is connecting to the peer associated with the given ID
	IsConnected(peerID peer.ID) bool
	// SaveProtocolStream saves stream
	SaveProtocolStream(protocol string, stream *rawGrpc.ClientConn, peerID peer.ID)
	// CloseProtocolStream closes stream
	CloseProtocolStream(protocol string, peerID peer.ID) error
}

type NoForkPeer

type NoForkPeer struct {
	// identifier
	ID peer.ID
	// peer's latest block number
	Number uint64
	// peer's distance
	Distance *big.Int
}

func (*NoForkPeer) IsBetter

func (p *NoForkPeer) IsBetter(t *NoForkPeer) bool

type PeerMap

type PeerMap struct {
	sync.Map
}

func NewPeerMap

func NewPeerMap(peers []*NoForkPeer) *PeerMap

func (*PeerMap) BestPeer

func (m *PeerMap) BestPeer(skipMap map[peer.ID]bool) *NoForkPeer

BestPeer returns the top of heap

func (*PeerMap) Put

func (m *PeerMap) Put(peers ...*NoForkPeer)

func (*PeerMap) Remove

func (m *PeerMap) Remove(peerID peer.ID)

Remove removes a peer from heap if it exists

type Progression

type Progression interface {
	// StartProgression starts progression
	StartProgression(startingBlock uint64, subscription blockchain.Subscription)
	// UpdateHighestProgression updates highest block number
	UpdateHighestProgression(highestBlock uint64)
	// GetProgression returns Progression
	GetProgression() *progress.Progression
	// StopProgression finishes progression
	StopProgression()
}

type SyncPeerClient

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(peer.ID, uint64, time.Duration) (<-chan *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
	// CloseStream close a stream
	CloseStream(peerID peer.ID) error
	// DisablePublishingPeerStatus disables publishing status in syncer topic
	DisablePublishingPeerStatus()
	// EnablePublishingPeerStatus enables publishing status in syncer topic
	EnablePublishingPeerStatus()
}

func NewSyncPeerClient

func NewSyncPeerClient(
	logger hclog.Logger,
	network Network,
	blockchain Blockchain,
) SyncPeerClient

type SyncPeerService

type SyncPeerService interface {
	// Start starts server
	Start()
	// Close terminates running processes for SyncPeerService
	Close() error
}

func NewSyncPeerService

func NewSyncPeerService(
	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
	// Sync starts routine to sync blocks
	Sync(func(*types.Block) bool) error
}

func NewSyncer

func NewSyncer(
	logger hclog.Logger,
	network Network,
	blockchain Blockchain,
	blockTimeout time.Duration,
) Syncer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL