headerdownload

package
v0.0.0-...-215623d Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeHashes

func DecodeHashes(encodings []string) map[common.Hash]struct{}

func DecodeTips

func DecodeTips(encodings []string) (map[common.Hash]HeaderRecord, error)

func InitPreverifiedHashes

func InitPreverifiedHashes(chain string) (map[common.Hash]struct{}, uint64)

Types

type Anchor

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

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 Announce

type Announce struct {
	Hash   common.Hash
	Number uint64
}

type CalcDifficultyFunc

type CalcDifficultyFunc func(childTimestamp uint64, parentTime uint64, parentDifficulty, parentNumber *big.Int, parentHash, parentUncleHash common.Hash) *big.Int

type ChainSegment

type ChainSegment struct {
	HeadersRaw [][]byte
	Headers    []*types.Header
}

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 (hd *HeaderDownload) HasLink(linkHash common.Hash) bool

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

type HeaderRecord struct {
	Raw    []byte
	Header *types.Header
}

HeaderRecord encapsulates two forms of the same header - raw RLP encoding (to avoid duplicated decodings and encodings), and parsed value types.Header

type HeaderRequest

type HeaderRequest struct {
	Hash    common.Hash
	Number  uint64
	Length  uint64
	Skip    uint64
	Reverse bool
}

Request for chain segment starting with hash and going to its parent, etc, with length headers in total

type HeadersByBlockHeight

type HeadersByBlockHeight []*types.Header

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 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) Len

func (lq LinkQueue) Len() int

Len (part of heap.Interface) returns the current size of the link queue

func (LinkQueue) Less

func (lq LinkQueue) Less(i, j int) bool

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

func (lq LinkQueue) Swap(i, j int)

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 Penalty

type Penalty int
const (
	NoPenalty Penalty = iota
	BadBlockPenalty
	DuplicateHeaderPenalty
	WrongChildBlockHeightPenalty
	WrongChildDifficultyPenalty
	InvalidSealPenalty
	TooFarFuturePenalty
	TooFarPastPenalty
	AbandonedAnchorPenalty
)

func (Penalty) String

func (p Penalty) String() string

type PenaltyItem

type PenaltyItem struct {
	Penalty Penalty
	PeerID  string
}

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)

func (*SeenAnnounces) Pop

func (s *SeenAnnounces) Pop(hash common.Hash) bool

func (SeenAnnounces) Seen

func (s SeenAnnounces) Seen(hash common.Hash) bool

type VerifySealFunc

type VerifySealFunc func(header *types.Header) error

Jump to

Keyboard shortcuts

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