synctrl

package
v0.0.0-...-d82d076 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: MIT, GPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxHashFetch    = 512 // Amount of hashes to be fetched per retrieval request
	MaxBlockFetch   = 128 // Amount of blocks to be fetched per retrieval request
	MaxHeaderFetch  = 192 // Amount of block headers to be fetched per retrieval request
	MaxSkeletonSize = 128 // Number of header fetches to need for a skeleton assembly
	MaxBodyFetch    = 128 // Amount of block bodies to be fetched per retrieval request
	MaxReceiptFetch = 256 // Amount of transaction receipts to allow fetching per request
	MaxStateFetch   = 384 // Amount of node state values to allow fetching per request

	MaxForkAncestry = 3 * config.EpochDuration // Maximum chain reorganisation

)

Functions

func HandleBlockBodiesMsg

func HandleBlockBodiesMsg(p *p2p.Peer, msg p2p.Msg) error

HandleBlockBodiesMsg deal received BlockBodiesMsg

func HandleBlockHeadersMsg

func HandleBlockHeadersMsg(p *p2p.Peer, msg p2p.Msg) error

HandleBlockHeadersMsg deal received BlockHeadersMsg

func HandleGetBlockBodiesMsg

func HandleGetBlockBodiesMsg(p *p2p.Peer, msg p2p.Msg) error

HandleGetBlockBodiesMsg deal received GetBlockBodiesMsg

func HandleGetBlockHeadersMsg

func HandleGetBlockHeadersMsg(p *p2p.Peer, msg p2p.Msg) error

HandleGetBlockHeadersMsg deal received GetBlockHeadersMsg

func HandleGetNodeDataMsg

func HandleGetNodeDataMsg(p *p2p.Peer, msg p2p.Msg) error

HandleGetNodeDataMsg deal received GetNodeDataMsg

func HandleGetReceiptsMsg

func HandleGetReceiptsMsg(p *p2p.Peer, msg p2p.Msg) error

HandleGetReceiptsMsg deal received GetReceiptsMsg

func HandleNewBlockHashesMsg

func HandleNewBlockHashesMsg(p *p2p.Peer, msg p2p.Msg) error

HandleNewBlockHashesMsg deal received NewBlockHashesMsg

func HandleNewBlockMsg

func HandleNewBlockMsg(p *p2p.Peer, msg p2p.Msg) error

HandleNewBlockMsg deal received NewBlockMsg

func HandleNewHashBlockMsg

func HandleNewHashBlockMsg(p *p2p.Peer, msg p2p.Msg) error

HandleNewBlockMsg deal received NewBlockMsg

func HandleNodeDataMsg

func HandleNodeDataMsg(p *p2p.Peer, msg p2p.Msg) error

HandleNodeDataMsg deal received NodeDataMsg

func HandleReceiptsMsg

func HandleReceiptsMsg(p *p2p.Peer, msg p2p.Msg) error

HandleReceiptsMsg deal received ReceiptsMsg

func HandleTxMsg

func HandleTxMsg(p *p2p.Peer, msg p2p.Msg) error

HandleTxMsg deal received TxMsg

func TxsPoolLoop

func TxsPoolLoop()

Types

type BlockChain

type BlockChain interface {
	LightChain

	// HasBlockAndState verifies block and associated states' presence in the local chain.
	HasBlockAndState(common.Hash) bool

	// GetBlockByHash retrieves a block from the local chain.
	GetBlockByHash(common.Hash) *types.Block

	// CurrentBlock retrieves the head block from the local chain.
	CurrentBlock() *types.Block

	// CurrentFastBlock retrieves the head fast block from the local chain.
	CurrentFastBlock() *types.Block

	// FastSyncCommitHead directly commits the head block to a certain entity.
	FastSyncCommitHead(common.Hash) error

	// InsertChain inserts a batch of blocks into the local chain.
	InsertChain(types.Blocks) (int, error)

	// InsertReceiptChain inserts a batch of receipts into the local chain.
	InsertReceiptChain(types.Blocks, []types.Receipts) (int, error)
}

BlockChain encapsulates functions required to sync a (full or fast) blockchain.

type DoneEvent

type DoneEvent struct{}

type FailedEvent

type FailedEvent struct{ Err error }

type FakePeer

type FakePeer struct {
	// contains filtered or unexported fields
}

FakePeer is a mock syncer peer that operates on a local database instance instead of being an actual live node. It's useful for testing and to implement sync commands from an xisting local database.

func NewFakePeer

func NewFakePeer(id string, db hpbdb.Database, hc *bc.HeaderChain, sy *Syncer) *FakePeer

NewFakePeer creates a new mock syncer peer with the given data sources.

func (*FakePeer) Head

func (p *FakePeer) Head() (common.Hash, *big.Int)

Head implements syncer.Peer, returning the current head hash and number of the best known header.

func (*FakePeer) RequestBodies

func (p *FakePeer) RequestBodies(hashes []common.Hash) error

RequestBodies implements syncer.Peer, returning a batch of block bodies corresponding to the specified block hashes.

func (*FakePeer) RequestHeadersByHash

func (p *FakePeer) RequestHeadersByHash(hash common.Hash, amount int, skip int, reverse bool) error

RequestHeadersByHash implements syncer.Peer, returning a batch of headers defined by the origin hash and the associaed query parameters.

func (*FakePeer) RequestHeadersByNumber

func (p *FakePeer) RequestHeadersByNumber(number uint64, amount int, skip int, reverse bool) error

RequestHeadersByNumber implements syncer.Peer, returning a batch of headers defined by the origin number and the associaed query parameters.

func (*FakePeer) RequestNodeData

func (p *FakePeer) RequestNodeData(hashes []common.Hash) error

RequestNodeData implements syncer.Peer, returning a batch of state trie nodes corresponding to the specified trie hashes.

func (*FakePeer) RequestReceipts

func (p *FakePeer) RequestReceipts(hashes []common.Hash) error

RequestReceipts implements syncer.Peer, returning a batch of transaction receipts corresponding to the specified block hashes.

type LightChain

type LightChain interface {
	// HasHeader verifies a header's presence in the local chain.
	HasHeader(h common.Hash, number uint64) bool

	// GetHeaderByHash retrieves a header from the local chain.
	GetHeaderByHash(common.Hash) *types.Header

	// CurrentHeader retrieves the head header from the local chain.
	CurrentHeader() *types.Header

	// GetTdByHash returns the total difficulty of a local block.
	GetTdByHash(common.Hash) *big.Int

	// InsertHeaderChain inserts a batch of headers into the local chain.
	InsertHeaderChain([]*types.Header, int, config.SyncMode) (int, error)

	// Rollback removes a few recently added elements from the local chain.
	Rollback([]common.Hash)
}

LightChain encapsulates functions required to synchronise a light chain.

type LightPeer

type LightPeer interface {
	Head() (common.Hash, *big.Int)
	RequestHeadersByHash(common.Hash, int, int, bool) error
	RequestHeadersByNumber(uint64, int, int, bool) error
}

LightPeer encapsulates the methods required to synchronise with a remote light peer.

type Peer

type Peer interface {
	LightPeer
	RequestBodies([]common.Hash) error
	RequestReceipts([]common.Hash) error
	RequestNodeData([]common.Hash) error
}

Peer encapsulates the methods required to synchronise with a remote full peer.

type PeerSyn

type PeerSyn struct {
	*p2p.Peer
}

//////////////////////////////////////////////////////////////////////////////////////

func (*PeerSyn) Head

func (ps *PeerSyn) Head() (common.Hash, *big.Int)

func (*PeerSyn) RequestBodies

func (ps *PeerSyn) RequestBodies(hashes []common.Hash) error

func (*PeerSyn) RequestHeadersByHash

func (ps *PeerSyn) RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse bool) error

func (*PeerSyn) RequestHeadersByNumber

func (ps *PeerSyn) RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool) error

func (*PeerSyn) RequestNodeData

func (ps *PeerSyn) RequestNodeData(hashes []common.Hash) error

func (*PeerSyn) RequestReceipts

func (ps *PeerSyn) RequestReceipts(hashes []common.Hash) error

type PublicSyncerAPI

type PublicSyncerAPI struct {
	// contains filtered or unexported fields
}

PublicSyncerAPI provides an API which gives information about the current synchronisation status. It offers only methods that operates on data that can be available to anyone without security risks.

func NewPublicSyncerAPI

func NewPublicSyncerAPI(syncer *Syncer, m *sub.TypeMux) *PublicSyncerAPI

NewPublicSyncerAPI create a new PublicSyncerAPI. The API has an internal event loop that listens for events from the syncer through the global event mux. In case it receives one of these events it broadcasts it to all syncing subscriptions that are installed through the installSyncSubscription channel.

func (*PublicSyncerAPI) SubscribeSyncStatus

func (api *PublicSyncerAPI) SubscribeSyncStatus(status chan interface{}) *SyncStatusSubscription

SubscribeSyncStatus creates a subscription that will broadcast new synchronisation updates. The given channel must receive interface values, the result can either

func (*PublicSyncerAPI) Syncing

func (api *PublicSyncerAPI) Syncing(ctx context.Context) (*rpc.Subscription, error)

Syncing provides information when this nodes starts synchronising with the Hpb network and when it's finished.

type Puller

type Puller struct {
	// contains filtered or unexported fields
}

func NewPuller

func NewPuller(getBlock blockRetrievalFn, verifyHeader headerVerifierFn, broadcastBlock blockBroadcasterFn,
	chainHeight chainHeightFn, insertChain chainInsertFn, dropPeer peerDropFn) *Puller

func (*Puller) Enqueue

func (this *Puller) Enqueue(peer string, block *types.Block) error

Enqueue tries to fill gaps the the fetcher's future import queue.

func (*Puller) FilterBodies

func (this *Puller) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, time time.Time) ([][]*types.Transaction, [][]*types.Header)

FilterBodies extracts all the block bodies that were explicitly requested by the fetcher, returning those that should be handled differently.

func (*Puller) FilterHeaders

func (this *Puller) FilterHeaders(peer string, headers []*types.Header, time time.Time) []*types.Header

FilterHeaders extracts all the headers that were explicitly requested by the fetcher, returning those that should be handled differently.

func (*Puller) Notify

func (this *Puller) Notify(peer string, hash common.Hash, number uint64, time time.Time,
	headerFetcher headerRequesterFn, bodyFetcher bodyRequesterFn) error

Notify announces the fetcher of the potential availability of a new block in the network.

type StartEvent

type StartEvent struct{}

type SynCtrl

type SynCtrl struct {
	AcceptTxs uint32 // Flag whether we're considered synchronised (enables transaction processing)

	SubProtocols []p2p.Protocol
	// contains filtered or unexported fields
}

func InstanceSynCtrl

func InstanceSynCtrl() *SynCtrl

InstanceSynCtrl returns the singleton of SynCtrl.

func (*SynCtrl) NewBlockMux

func (this *SynCtrl) NewBlockMux() *sub.TypeMux

func (*SynCtrl) RegisterNetPeer

func (this *SynCtrl) RegisterNetPeer(peer *p2p.Peer) error

func (*SynCtrl) Start

func (this *SynCtrl) Start()

func (*SynCtrl) Stop

func (this *SynCtrl) Stop()

func (*SynCtrl) Syncer

func (this *SynCtrl) Syncer() *Syncer

func (*SynCtrl) UnregisterNetPeer

func (this *SynCtrl) UnregisterNetPeer(peer *p2p.Peer) error

type SyncStatusSubscription

type SyncStatusSubscription struct {
	// contains filtered or unexported fields
}

SyncStatusSubscription represents a syncing subscription.

func (*SyncStatusSubscription) Unsubscribe

func (s *SyncStatusSubscription) Unsubscribe()

Unsubscribe uninstalls the subscription from the SynAPI event loop. The status channel that was passed to subscribeSyncStatus isn't used anymore after this method returns.

type Syncer

type Syncer struct {
	// contains filtered or unexported fields
}

func NewSyncer

func NewSyncer(mode config.SyncMode, stateDb hpbdb.Database, mux *sub.TypeMux, lightchain LightChain,
	dropPeer peerDropFn) *Syncer

func (*Syncer) Cancel

func (this *Syncer) Cancel()

Cancel cancels all of the operations and resets the scheduler. It returns true if the cancel operation was completed.

func (*Syncer) DeliverBodies

func (this *Syncer) DeliverBodies(id string, transactions [][]*types.Transaction, uncles [][]*types.Header) (err error)

DeliverBodies injects a new batch of block bodies received from a remote node.

func (*Syncer) DeliverHeaders

func (this *Syncer) DeliverHeaders(id string, headers []*types.Header) (err error)

DeliverHeaders injects a new batch of block headers received from a remote node into the syn schedule.

func (*Syncer) DeliverNodeData

func (this *Syncer) DeliverNodeData(id string, data [][]byte) (err error)

DeliverNodeData injects a new batch of node state data received from a remote node.

func (*Syncer) DeliverReceipts

func (this *Syncer) DeliverReceipts(id string, receipts [][]*types.Receipt) (err error)

DeliverReceipts injects a new batch of receipts received from a remote node.

func (*Syncer) Progress

func (this *Syncer) Progress() hpbinter.SyncProgress

Progress retrieves the synchronisation boundaries, specifically the origin block where synchronisation started at (may have failed/suspended); the block or header sync is currently at; and the latest known block which the sync targets.

In addition, during the state sync phase of fast synchronisation the number of processed and the total number of known states are also returned. Otherwise these are zero.

func (*Syncer) RegisterLightPeer

func (this *Syncer) RegisterLightPeer(id string, version uint, peer LightPeer) error

RegisterLightPeer injects a light client peer, wrapping it so it appears as a regular peer.

func (*Syncer) RegisterPeer

func (this *Syncer) RegisterPeer(id string, version uint, peer Peer) error

RegisterPeer injects a new syn peer into the set of block source to be used for fetching hashes and blocks from.

func (*Syncer) Start

func (this *Syncer) Start(id string, head common.Hash, td *big.Int, mode config.SyncMode) error

Start tries to sync up our local block chain with a remote peer, both adding various sanity checks as well as wrapping it with various log entries.

func (*Syncer) Synchronising

func (this *Syncer) Synchronising() bool

Synchronising returns whether the syn is currently retrieving blocks.

func (*Syncer) UnregisterPeer

func (this *Syncer) UnregisterPeer(id string) error

UnregisterPeer remove a peer from the known list, preventing any action from the specified peer. An effort is also made to return any pending fetches into the queue.

type SyncingResult

type SyncingResult struct {
	Syncing bool             `json:"syncing"`
	Status  hpb.SyncProgress `json:"status"`
}

SyncingResult provides information about the current synchronisation status for this node.

Jump to

Keyboard shortcuts

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