headerdownload

package
v0.0.0-...-140c642 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const AnchorSerLen = 32 + 8 + 8 /* maxTipHeight */

Variables

This section is empty.

Functions

func DecodeTips

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

func InitHardCodedTips

func InitHardCodedTips(network string) map[common.Hash]HeaderRecord

func ReadFilesAndBuffer

func ReadFilesAndBuffer(files []string, headerBuf *HeaderBuffer, hf func(header *types.Header, blockHeight uint64) error) error

Types

type Anchor

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

func (*Anchor) Less

func (a *Anchor) Less(bi llrb.Item) bool

For placing anchors into the sorting tree

type AnchorTipItem

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

AnchorTipItem is element of the priority queue of tips belonging to an anchor This queue is prioritised by block heights, lowest block height being first out

type AnchorTipQueue

type AnchorTipQueue []AnchorTipItem

func (AnchorTipQueue) Len

func (atq AnchorTipQueue) Len() int

func (AnchorTipQueue) Less

func (atq AnchorTipQueue) Less(i, j int) bool

func (*AnchorTipQueue) Pop

func (atq *AnchorTipQueue) Pop() interface{}

func (*AnchorTipQueue) Push

func (atq *AnchorTipQueue) Push(x interface{})

func (AnchorTipQueue) Swap

func (atq AnchorTipQueue) Swap(i, j int)

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 HeaderBuffer

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

func (*HeaderBuffer) AddHeader

func (hb *HeaderBuffer) AddHeader(headerRaw []byte, height uint64)

func (*HeaderBuffer) Clear

func (hb *HeaderBuffer) Clear()

func (*HeaderBuffer) Flush

func (hb *HeaderBuffer) Flush(w io.Writer) error

func (*HeaderBuffer) IsEmpty

func (hb *HeaderBuffer) IsEmpty() bool

func (*HeaderBuffer) Len

func (hb *HeaderBuffer) Len() int

func (*HeaderBuffer) Less

func (hb *HeaderBuffer) Less(i, j int) bool

func (*HeaderBuffer) Read

func (hb *HeaderBuffer) Read(p []byte) (int, error)

func (*HeaderBuffer) Swap

func (hb *HeaderBuffer) Swap(i, j int)

type HeaderDownload

type HeaderDownload struct {
	RequestQueueTimer *time.Timer
	// contains filtered or unexported fields
}

func NewHeaderDownload

func NewHeaderDownload(
	initialHash common.Hash,
	filesDir string,
	bufferLimit, tipLimit, initPowDepth int,
	calcDifficultyFunc CalcDifficultyFunc,
	verifySealFunc VerifySealFunc,
	newAnchorFutureLimit, newAnchorPastLimit uint64,
) *HeaderDownload

func (*HeaderDownload) AddHeaderToBuffer

func (hd *HeaderDownload) AddHeaderToBuffer(headerRaw []byte, blockHeight uint64)

func (*HeaderDownload) AddSegmentToBuffer

func (hd *HeaderDownload) AddSegmentToBuffer(segment *ChainSegment, start, end int)

AddSegmentToBuffer adds another segment to the buffer and return true if the buffer is now full

func (*HeaderDownload) AnchorState

func (hd *HeaderDownload) AnchorState() string

func (*HeaderDownload) Connect

func (hd *HeaderDownload) Connect(segment *ChainSegment, start, end int, currentTime uint64) error

Connect connects some working trees using anchors of some, and a tip of another

func (*HeaderDownload) ExtendDown

func (hd *HeaderDownload) ExtendDown(segment *ChainSegment, start, end int, hardCoded bool, currentTime uint64) error

ExtendDown extends some working trees down from the anchor, using given chain segment it creates a new anchor and collects all the tips from the attached anchors to it

func (*HeaderDownload) ExtendUp

func (hd *HeaderDownload) ExtendUp(segment *ChainSegment, start, end int, currentTime uint64) error

ExtendUp extends a working tree up from the tip, using given chain segment

func (*HeaderDownload) FindAnchors

func (hd *HeaderDownload) FindAnchors(segment *ChainSegment) (found bool, start int, anchorParent common.Hash, invalidAnchors []int)

FindAnchors attempts to find anchors to which given chain segment can be attached to

func (*HeaderDownload) FindTip

func (hd *HeaderDownload) FindTip(segment *ChainSegment, start int) (found bool, end int, penalty Penalty)

FindTip attempts to find tip of a tree that given chain segment can be attached to the given chain segment may be found invalid relative to a working tree, in this case penalty for peer is returned

func (*HeaderDownload) FlushBuffer

func (hd *HeaderDownload) FlushBuffer() error

func (*HeaderDownload) HasTip

func (hd *HeaderDownload) HasTip(tipHash common.Hash) bool

func (*HeaderDownload) InvalidateAnchors

func (hd *HeaderDownload) InvalidateAnchors(anchorParent common.Hash, invalidAnchors []int) (tombstones []common.Hash, err error)

InvalidateAnchors removes trees with given anchor hashes (belonging to the given anchor parent)

func (*HeaderDownload) NewAnchor

func (hd *HeaderDownload) NewAnchor(segment *ChainSegment, start, end int, currentTime uint64) error

func (*HeaderDownload) PrepareStageData

func (hd *HeaderDownload) PrepareStageData() (files []string, buffer *HeaderBuffer)

func (*HeaderDownload) Progress

func (hd *HeaderDownload) Progress() (files int, buffer int, headersAdded int)

func (*HeaderDownload) Ready

func (hd *HeaderDownload) Ready() (bool, uint64)

func (*HeaderDownload) RecoverFromDb

func (hd *HeaderDownload) RecoverFromDb(db ethdb.Database, currentTime uint64) error

func (*HeaderDownload) RecoverFromFiles

func (hd *HeaderDownload) RecoverFromFiles(currentTime uint64, hardTips map[common.Hash]HeaderRecord) error

func (*HeaderDownload) RequestMoreHeaders

func (hd *HeaderDownload) RequestMoreHeaders(currentTime, timeout uint64) ([]*HeaderRequest, *time.Timer)

func (*HeaderDownload) SetHardCodedTips

func (hd *HeaderDownload) SetHardCodedTips(hardTips map[common.Hash]HeaderRecord)

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

func (hd *HeaderDownload) StageReadyChannel() chan struct{}

func (*HeaderDownload) VerifySeals

func (hd *HeaderDownload) VerifySeals(segment *ChainSegment, anchorFound, tipFound bool, start, end int, currentTime uint64) (hardCoded bool, err error)

VerifySeals verifies Proof Of Work for the part of the given chain segment It reports first verification error, or returns the powDepth that the anchor of this chain segment should have, if created

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, tx, batch ethdb.DbWithPendingMutations, localTd *big.Int, headerProgress uint64) *HeaderInserter

func (*HeaderInserter) FeedHeader

func (hi *HeaderInserter) FeedHeader(header *types.Header, blockHeight uint64) error

func (*HeaderInserter) GetHighest

func (hi *HeaderInserter) GetHighest() 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 int
}

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 Heap

type Heap []HeapElem

func (Heap) Len

func (h Heap) Len() int

func (Heap) Less

func (h Heap) Less(i, j int) bool

func (*Heap) Pop

func (h *Heap) Pop() interface{}

func (*Heap) Push

func (h *Heap) Push(x interface{})

func (Heap) Swap

func (h Heap) Swap(i, j int)

type HeapElem

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

Heap element for merging together header files

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
)

func (Penalty) String

func (p Penalty) String() string

type RequestQueue

type RequestQueue []RequestQueueItem

func (RequestQueue) Len

func (rq RequestQueue) Len() int

func (RequestQueue) Less

func (rq RequestQueue) Less(i, j int) bool

func (*RequestQueue) Pop

func (rq *RequestQueue) Pop() interface{}

func (*RequestQueue) Push

func (rq *RequestQueue) Push(x interface{})

func (RequestQueue) Swap

func (rq RequestQueue) Swap(i, j int)

type RequestQueueItem

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

type Tip

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

type TipQueueItem

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

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