Documentation ¶
Index ¶
- func DecodeHashes(encodings []string) map[common.Hash]struct{}
- func DecodeTips(encodings []string) (map[common.Hash]HeaderRecord, error)
- func InitPreverifiedHashes(chain string) (map[common.Hash]struct{}, uint64)
- type Anchor
- type AnchorQueue
- type Announce
- type CalcDifficultyFunc
- type ChainSegment
- type HeaderDownload
- func (hd *HeaderDownload) AnchorState() string
- func (hd *HeaderDownload) EnableRequestChaining()
- func (hd *HeaderDownload) GrabAnnounces() []Announce
- func (hd *HeaderDownload) HasLink(linkHash common.Hash) bool
- func (hd *HeaderDownload) InsertHeaders(hf func(header *types.Header, blockHeight uint64) error, logPrefix string, ...) (bool, error)
- func (hd *HeaderDownload) ProcessSegment(segment *ChainSegment, newBlock bool, peerID string) (requestMore bool)
- func (hd *HeaderDownload) Progress() uint64
- func (hd *HeaderDownload) ReadProgressFromDb(tx ethdb.RwTx) (err error)
- func (hd *HeaderDownload) RecoverFromDb(db ethdb.RoKV) error
- func (hd *HeaderDownload) RequestMoreHeaders(currentTime uint64) (*HeaderRequest, []PenaltyItem)
- func (hd *HeaderDownload) RequestSkeleton() *HeaderRequest
- func (hd *HeaderDownload) SaveExternalAnnounce(hash common.Hash)
- func (hd *HeaderDownload) SentRequest(req *HeaderRequest, currentTime, timeout uint64)
- func (hd *HeaderDownload) SetHeaderReader(headerReader consensus.ChainHeaderReader)
- func (hd *HeaderDownload) SetPreverifiedHashes(preverifiedHashes map[common.Hash]struct{}, preverifiedHeight uint64)
- func (hd *HeaderDownload) SingleHeaderAsSegment(headerRaw []byte, header *types.Header) ([]*ChainSegment, Penalty, error)
- func (hd *HeaderDownload) SplitIntoSegments(headersRaw [][]byte, msg []*types.Header) ([]*ChainSegment, Penalty, error)
- func (hd *HeaderDownload) TopSeenHeight() uint64
- type HeaderInserter
- func (hi *HeaderInserter) AnythingDone() bool
- func (hi *HeaderInserter) FeedHeader(db ethdb.StatelessRwTx, header *types.Header, blockHeight uint64) error
- func (hi *HeaderInserter) FeedHeaderFunc(db ethdb.StatelessRwTx) func(header *types.Header, blockHeight uint64) error
- func (hi *HeaderInserter) GetHighest() uint64
- func (hi *HeaderInserter) GetHighestHash() common.Hash
- func (hi *HeaderInserter) GetHighestTimestamp() uint64
- func (hi *HeaderInserter) UnwindPoint() uint64
- type HeaderRecord
- type HeaderRequest
- type HeadersByBlockHeight
- type Link
- type LinkQueue
- type PeerHandle
- type PeerPenalty
- type Penalty
- type PenaltyItem
- type SeenAnnounces
- type VerifySealFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeHashes ¶
func DecodeTips ¶
func DecodeTips(encodings []string) (map[common.Hash]HeaderRecord, error)
Types ¶
type AnchorQueue ¶
type AnchorQueue []*Anchor
func (AnchorQueue) Len ¶
func (aq AnchorQueue) Len() int
func (AnchorQueue) Less ¶
func (aq AnchorQueue) Less(i, j int) bool
func (*AnchorQueue) Pop ¶
func (aq *AnchorQueue) Pop() interface{}
func (*AnchorQueue) Push ¶
func (aq *AnchorQueue) Push(x interface{})
func (AnchorQueue) Swap ¶
func (aq AnchorQueue) Swap(i, j int)
type CalcDifficultyFunc ¶
type ChainSegment ¶
First item in ChainSegment is the anchor ChainSegment must be contigous and must not include bad headers
type HeaderDownload ¶
type HeaderDownload struct { DeliveryNotify chan struct{} // contains filtered or unexported fields }
func NewHeaderDownload ¶
func NewHeaderDownload( anchorLimit int, linkLimit int, engine consensus.Engine, ) *HeaderDownload
func (*HeaderDownload) AnchorState ¶
func (hd *HeaderDownload) AnchorState() string
func (*HeaderDownload) EnableRequestChaining ¶
func (hd *HeaderDownload) EnableRequestChaining()
func (*HeaderDownload) GrabAnnounces ¶
func (hd *HeaderDownload) GrabAnnounces() []Announce
GrabAnnounces - returns all available announces and forget them
func (*HeaderDownload) InsertHeaders ¶
func (hd *HeaderDownload) InsertHeaders(hf func(header *types.Header, blockHeight uint64) error, logPrefix string, logChannel <-chan time.Time) (bool, error)
InsertHeaders attempts to insert headers into the database, verifying them first It returns true in the first return value if the system is "in sync"
func (*HeaderDownload) ProcessSegment ¶
func (hd *HeaderDownload) ProcessSegment(segment *ChainSegment, newBlock bool, peerID string) (requestMore bool)
ProcessSegment - handling single segment. If segment were processed by extendDown or newAnchor method, then it returns `requestMore=true` it allows higher-level algo immediately request more headers without waiting all stages precessing, speeds up visibility of new blocks It remember peerID - then later - if anchors created from segments will abandoned - this peerID gonna get Penalty
func (*HeaderDownload) Progress ¶
func (hd *HeaderDownload) Progress() uint64
func (*HeaderDownload) ReadProgressFromDb ¶
func (hd *HeaderDownload) ReadProgressFromDb(tx ethdb.RwTx) (err error)
ReadProgressFromDb updates highestInDb field according to the information in the database. It is useful in the situations when transaction was aborted and highestInDb became out-of-sync
func (*HeaderDownload) RecoverFromDb ¶
func (hd *HeaderDownload) RecoverFromDb(db ethdb.RoKV) error
func (*HeaderDownload) RequestMoreHeaders ¶
func (hd *HeaderDownload) RequestMoreHeaders(currentTime uint64) (*HeaderRequest, []PenaltyItem)
func (*HeaderDownload) RequestSkeleton ¶
func (hd *HeaderDownload) RequestSkeleton() *HeaderRequest
func (*HeaderDownload) SaveExternalAnnounce ¶
func (hd *HeaderDownload) SaveExternalAnnounce(hash common.Hash)
SaveExternalAnnounce - does mark hash as seen in external announcement only such hashes will broadcast further after
func (*HeaderDownload) SentRequest ¶
func (hd *HeaderDownload) SentRequest(req *HeaderRequest, currentTime, timeout uint64)
func (*HeaderDownload) SetHeaderReader ¶
func (hd *HeaderDownload) SetHeaderReader(headerReader consensus.ChainHeaderReader)
func (*HeaderDownload) SetPreverifiedHashes ¶
func (hd *HeaderDownload) SetPreverifiedHashes(preverifiedHashes map[common.Hash]struct{}, preverifiedHeight uint64)
func (*HeaderDownload) SingleHeaderAsSegment ¶
func (hd *HeaderDownload) SingleHeaderAsSegment(headerRaw []byte, header *types.Header) ([]*ChainSegment, Penalty, error)
SingleHeaderAsSegment converts message containing 1 header into one singleton chain segment
func (*HeaderDownload) SplitIntoSegments ¶
func (hd *HeaderDownload) SplitIntoSegments(headersRaw [][]byte, msg []*types.Header) ([]*ChainSegment, Penalty, error)
SplitIntoSegments converts message containing headers into a collection of chain segments
func (*HeaderDownload) TopSeenHeight ¶
func (hd *HeaderDownload) TopSeenHeight() uint64
type HeaderInserter ¶
type HeaderInserter struct {
// contains filtered or unexported fields
}
HeaderInserter incapsulates necessary variable for inserting header records to the database, abstracting away the source of these headers The headers are "fed" by repeatedly calling the FeedHeader function.
func NewHeaderInserter ¶
func NewHeaderInserter(logPrefix string, localTd *big.Int, headerProgress uint64) *HeaderInserter
func (*HeaderInserter) AnythingDone ¶
func (hi *HeaderInserter) AnythingDone() bool
func (*HeaderInserter) FeedHeader ¶
func (hi *HeaderInserter) FeedHeader(db ethdb.StatelessRwTx, header *types.Header, blockHeight uint64) error
func (*HeaderInserter) FeedHeaderFunc ¶
func (hi *HeaderInserter) FeedHeaderFunc(db ethdb.StatelessRwTx) func(header *types.Header, blockHeight uint64) error
func (*HeaderInserter) GetHighest ¶
func (hi *HeaderInserter) GetHighest() uint64
func (*HeaderInserter) GetHighestHash ¶
func (hi *HeaderInserter) GetHighestHash() common.Hash
func (*HeaderInserter) GetHighestTimestamp ¶
func (hi *HeaderInserter) GetHighestTimestamp() uint64
func (*HeaderInserter) UnwindPoint ¶
func (hi *HeaderInserter) UnwindPoint() uint64
type HeaderRecord ¶
HeaderRecord encapsulates two forms of the same header - raw RLP encoding (to avoid duplicated decodings and encodings), and parsed value types.Header
type HeaderRequest ¶
Request for chain segment starting with hash and going to its parent, etc, with length headers in total
type HeadersByBlockHeight ¶
Implements sort.Interface so we can sort the incoming header in the message by block height
func (HeadersByBlockHeight) Len ¶
func (h HeadersByBlockHeight) Len() int
func (HeadersByBlockHeight) Less ¶
func (h HeadersByBlockHeight) Less(i, j int) bool
func (HeadersByBlockHeight) Swap ¶
func (h HeadersByBlockHeight) Swap(i, j int)
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link is a chain link that can be connect to other chain links For a given link, parent link can be found by hd.links[link.header.ParentHash], and child links by link.next (there may be more than one child in case of forks) Links encapsule block headers Links can be either persistent or not. Persistent links encapsule headers that have already been saved to the database, but these links are still present to allow potential reorgs
type LinkQueue ¶
type LinkQueue []*Link
LinkQueue is the priority queue of links. It is instantiated once for persistent links, and once for non-persistent links In other instances, it is used to limit number of links of corresponding type (persistent and non-persistent) in memory
func (LinkQueue) Less ¶
Less (part of heap.Interface) compares two links. For persisted links, those with the lower block heights get evicted first. This means that more recently persisted links are preferred. For non-persisted links, those with the highest block heights get evicted first. This is to prevent "holes" in the block heights that may cause inability to insert headers in the ascending order of their block heights.
func (*LinkQueue) Pop ¶
func (lq *LinkQueue) Pop() interface{}
Pop (part of heap.Interface) removes the first link from the queue
func (*LinkQueue) Push ¶
func (lq *LinkQueue) Push(x interface{})
Push (part of heap.Interface) places a new link onto the end of queue. Note that idx attribute is set to the correct position of the new link
func (LinkQueue) Swap ¶
Swap (part of heap.Interface) moves two links in the queue into each other's places. Note that each link has idx attribute that is getting adjusted during the swap. The idx attribute allows the removal of links from the middle of the queue (in case if links are getting invalidated due to failed verification of unavailability of parent headers)
type PeerHandle ¶
type PeerHandle int // This is int just for the PoC phase - will be replaced by more appropriate type to find a peer
type PeerPenalty ¶
type PeerPenalty struct {
// contains filtered or unexported fields
}
func (PeerPenalty) String ¶
func (pp PeerPenalty) String() string
type PenaltyItem ¶
type SeenAnnounces ¶
type SeenAnnounces struct {
// contains filtered or unexported fields
}
SeenAnnounces - external announcement hashes, after header verification if hash is in this set - will broadcast it further
func NewSeenAnnounces ¶
func NewSeenAnnounces() *SeenAnnounces
func (*SeenAnnounces) Add ¶
func (s *SeenAnnounces) Add(b common.Hash)