Documentation ¶
Index ¶
- Variables
- func HandleBlockBodiesMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleBlockHeadersMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleGetBlockBodiesMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleGetBlockHeadersMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleGetNodeDataMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleGetReceiptsMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleNewBlockHashesMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleNewBlockMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleNewHashBlockMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleNodeDataMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleReceiptsMsg(p *p2p.Peer, msg p2p.Msg) error
- func HandleTxMsg(p *p2p.Peer, msg p2p.Msg) error
- func TxsPoolLoop()
- type BlockChain
- type DoneEvent
- type FailedEvent
- type FakePeer
- func (p *FakePeer) Head() (common.Hash, *big.Int)
- func (p *FakePeer) RequestBodies(hashes []common.Hash) error
- func (p *FakePeer) RequestHeadersByHash(hash common.Hash, amount int, skip int, reverse bool) error
- func (p *FakePeer) RequestHeadersByNumber(number uint64, amount int, skip int, reverse bool) error
- func (p *FakePeer) RequestNodeData(hashes []common.Hash) error
- func (p *FakePeer) RequestReceipts(hashes []common.Hash) error
- type LightChain
- type LightPeer
- type Peer
- type PeerSyn
- func (ps *PeerSyn) Head() (common.Hash, *big.Int)
- func (ps *PeerSyn) RequestBodies(hashes []common.Hash) error
- func (ps *PeerSyn) RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse bool) error
- func (ps *PeerSyn) RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool) error
- func (ps *PeerSyn) RequestNodeData(hashes []common.Hash) error
- func (ps *PeerSyn) RequestReceipts(hashes []common.Hash) error
- type PublicSyncerAPI
- type Puller
- func (this *Puller) Enqueue(peer string, block *types.Block) error
- func (this *Puller) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, ...) ([][]*types.Transaction, [][]*types.Header)
- func (this *Puller) FilterHeaders(peer string, headers []*types.Header, time time.Time) []*types.Header
- func (this *Puller) Notify(peer string, hash common.Hash, number uint64, time time.Time, ...) error
- type StartEvent
- type SynCtrl
- type SyncStatusSubscription
- type Syncer
- func (this *Syncer) Cancel()
- func (this *Syncer) DeliverBodies(id string, transactions [][]*types.Transaction, uncles [][]*types.Header) (err error)
- func (this *Syncer) DeliverHeaders(id string, headers []*types.Header) (err error)
- func (this *Syncer) DeliverNodeData(id string, data [][]byte) (err error)
- func (this *Syncer) DeliverReceipts(id string, receipts [][]*types.Receipt) (err error)
- func (this *Syncer) Progress() hpbinter.SyncProgress
- func (this *Syncer) RegisterLightPeer(id string, version uint, peer LightPeer) error
- func (this *Syncer) RegisterPeer(id string, version uint, peer Peer) error
- func (this *Syncer) Start(id string, head common.Hash, td *big.Int, mode config.SyncMode) error
- func (this *Syncer) Synchronising() bool
- func (this *Syncer) UnregisterPeer(id string) error
- type SyncingResult
Constants ¶
This section is empty.
Variables ¶
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 ¶
HandleBlockBodiesMsg deal received BlockBodiesMsg
func HandleBlockHeadersMsg ¶
HandleBlockHeadersMsg deal received BlockHeadersMsg
func HandleGetBlockBodiesMsg ¶
HandleGetBlockBodiesMsg deal received GetBlockBodiesMsg
func HandleGetBlockHeadersMsg ¶
HandleGetBlockHeadersMsg deal received GetBlockHeadersMsg
func HandleGetNodeDataMsg ¶
HandleGetNodeDataMsg deal received GetNodeDataMsg
func HandleGetReceiptsMsg ¶
HandleGetReceiptsMsg deal received GetReceiptsMsg
func HandleNewBlockHashesMsg ¶
HandleNewBlockHashesMsg deal received NewBlockHashesMsg
func HandleNewBlockMsg ¶
HandleNewBlockMsg deal received NewBlockMsg
func HandleNewHashBlockMsg ¶
HandleNewBlockMsg deal received NewBlockMsg
func HandleNodeDataMsg ¶
HandleNodeDataMsg deal received NodeDataMsg
func HandleReceiptsMsg ¶
HandleReceiptsMsg deal received ReceiptsMsg
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 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 ¶
NewFakePeer creates a new mock syncer peer with the given data sources.
func (*FakePeer) Head ¶
Head implements syncer.Peer, returning the current head hash and number of the best known header.
func (*FakePeer) RequestBodies ¶
RequestBodies implements syncer.Peer, returning a batch of block bodies corresponding to the specified block hashes.
func (*FakePeer) RequestHeadersByHash ¶
RequestHeadersByHash implements syncer.Peer, returning a batch of headers defined by the origin hash and the associaed query parameters.
func (*FakePeer) RequestHeadersByNumber ¶
RequestHeadersByNumber implements syncer.Peer, returning a batch of headers defined by the origin number and the associaed query parameters.
func (*FakePeer) RequestNodeData ¶
RequestNodeData implements syncer.Peer, returning a batch of state trie nodes corresponding to the specified trie 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 ¶
//////////////////////////////////////////////////////////////////////////////////////
func (*PeerSyn) RequestHeadersByHash ¶
func (*PeerSyn) RequestHeadersByNumber ¶
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) 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.
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 ¶
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 (*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 ¶
DeliverHeaders injects a new batch of block headers received from a remote node into the syn schedule.
func (*Syncer) DeliverNodeData ¶
DeliverNodeData injects a new batch of node state data received from a remote node.
func (*Syncer) DeliverReceipts ¶
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 ¶
RegisterLightPeer injects a light client peer, wrapping it so it appears as a regular peer.
func (*Syncer) RegisterPeer ¶
RegisterPeer injects a new syn peer into the set of block source to be used for fetching hashes and blocks from.
func (*Syncer) Start ¶
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 ¶
Synchronising returns whether the syn is currently retrieving blocks.
func (*Syncer) UnregisterPeer ¶
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.