headerdownload

package
v0.0.0-...-92d349b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Idle = iota
	Syncing
	Synced // if we found a canonical hash during backward sync, in this case our sync process is done
)
View Source
const POSPandaBanner = `` /* 1576-byte string literal not displayed */

Variables

This section is empty.

Functions

func DecodeTips

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

Types

type Anchor

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

Anchor represents a header that we do not yet have, but that we would like to have soon anchors are created when we know the hash of the header (from its children), and we can also derive its blockheight (also from its children), but the corresponding header either has not been requested yet, or has not been delivered yet. It is possible for one anchor to reference multiple links, because more than one header may share the same parent header. In such cases, `links` field will contain more than one pointer.

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 []ChainSegmentHeader

First item in ChainSegment is the anchor ChainSegment must be contigous and must not include bad headers

type ChainSegmentHeader

type ChainSegmentHeader struct {
	HeaderRaw rlp.RawValue
	Header    *types.Header
	Hash      common.Hash
	Number    uint64
}

type FeedHeaderFunc

type FeedHeaderFunc = func(header *types.Header, headerRaw []byte, hash libcommon.Hash, blockHeight uint64) (td *big.Int, err error)

type HeaderDownload

type HeaderDownload struct {
	DeliveryNotify chan struct{}

	QuitPoWMining chan struct{}

	BeaconRequestList *engineapi.RequestList       // Requests from ethbackend to staged sync
	PayloadStatusCh   chan engineapi.PayloadStatus // Responses (validation/execution status)
	ShutdownCh        chan struct{}                // Channel to signal shutdown
	// contains filtered or unexported fields
}

func NewHeaderDownload

func NewHeaderDownload(
	anchorLimit int,
	linkLimit int,
	engine consensus.Engine,
	headerReader services.HeaderAndCanonicalReader,
) *HeaderDownload

func (*HeaderDownload) AddHeadersFromSnapshot

func (hd *HeaderDownload) AddHeadersFromSnapshot(tx kv.Tx, n uint64, r services.FullBlockReader) error

func (*HeaderDownload) AddMinedHeader

func (hd *HeaderDownload) AddMinedHeader(header *types.Header) error

func (*HeaderDownload) AfterInitialCycle

func (hd *HeaderDownload) AfterInitialCycle()

func (*HeaderDownload) ClearPendingPayloadHash

func (hd *HeaderDownload) ClearPendingPayloadHash()

func (*HeaderDownload) ClearUnsettledForkChoice

func (hd *HeaderDownload) ClearUnsettledForkChoice()

func (*HeaderDownload) ExtractStats

func (hd *HeaderDownload) ExtractStats() Stats

func (*HeaderDownload) FetchingNew

func (hd *HeaderDownload) FetchingNew() bool

func (*HeaderDownload) FirstPoSHeight

func (hd *HeaderDownload) FirstPoSHeight() *uint64

func (*HeaderDownload) GetPendingPayloadHash

func (hd *HeaderDownload) GetPendingPayloadHash() libcommon.Hash

func (*HeaderDownload) GetPendingPayloadStatus

func (hd *HeaderDownload) GetPendingPayloadStatus() *engineapi.PayloadStatus

func (*HeaderDownload) GetUnsettledForkChoice

func (hd *HeaderDownload) GetUnsettledForkChoice() (*engineapi.ForkChoiceMessage, uint64)

func (*HeaderDownload) GrabAnnounces

func (hd *HeaderDownload) GrabAnnounces() []Announce

GrabAnnounces - returns all available announces and forget them

func (hd *HeaderDownload) HasLink(linkHash libcommon.Hash) bool

func (*HeaderDownload) HeadersCollector

func (hd *HeaderDownload) HeadersCollector() *etl.Collector

func (*HeaderDownload) InitialCycle

func (hd *HeaderDownload) InitialCycle() bool

func (*HeaderDownload) InsertHeader

func (hd *HeaderDownload) InsertHeader(hf FeedHeaderFunc, terminalTotalDifficulty *big.Int, logPrefix string, logChannel <-chan time.Time) (bool, bool, uint64, uint64, error)

func (*HeaderDownload) InsertHeaders

func (hd *HeaderDownload) InsertHeaders(hf FeedHeaderFunc, terminalTotalDifficulty *big.Int, logPrefix string, logChannel <-chan time.Time, currentTime uint64) (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) IsBadHeader

func (hd *HeaderDownload) IsBadHeader(headerHash libcommon.Hash) bool

func (*HeaderDownload) IsBadHeaderPoS

func (hd *HeaderDownload) IsBadHeaderPoS(tipHash libcommon.Hash) (bad bool, lastValidAncestor libcommon.Hash)

func (*HeaderDownload) LogAnchorState

func (hd *HeaderDownload) LogAnchorState()

func (*HeaderDownload) MarkAllVerified

func (hd *HeaderDownload) MarkAllVerified()

func (*HeaderDownload) POSSync

func (hd *HeaderDownload) POSSync() bool

func (*HeaderDownload) PoSDownloaderTip

func (hd *HeaderDownload) PoSDownloaderTip() libcommon.Hash

func (*HeaderDownload) PosStatus

func (hd *HeaderDownload) PosStatus() SyncStatus

func (*HeaderDownload) ProcessHeader

func (hd *HeaderDownload) ProcessHeader(sh ChainSegmentHeader, newBlock bool, peerID [64]byte) bool

func (*HeaderDownload) ProcessHeaders

func (hd *HeaderDownload) ProcessHeaders(csHeaders []ChainSegmentHeader, newBlock bool, peerID [64]byte) bool

func (*HeaderDownload) ProcessHeadersPOS

func (hd *HeaderDownload) ProcessHeadersPOS(csHeaders []ChainSegmentHeader, tx kv.Getter, peerId [64]byte) ([]PenaltyItem, error)

func (*HeaderDownload) Progress

func (hd *HeaderDownload) Progress() uint64

func (*HeaderDownload) ReadProgressFromDb

func (hd *HeaderDownload) ReadProgressFromDb(tx kv.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 kv.RoDB) error

func (*HeaderDownload) ReportBadHeader

func (hd *HeaderDownload) ReportBadHeader(headerHash libcommon.Hash)

ReportBadHeader -

func (*HeaderDownload) ReportBadHeaderPoS

func (hd *HeaderDownload) ReportBadHeaderPoS(badHeader, lastValidAncestor libcommon.Hash)

func (*HeaderDownload) RequestId

func (hd *HeaderDownload) RequestId() int

func (*HeaderDownload) RequestMoreHeaders

func (hd *HeaderDownload) RequestMoreHeaders(currentTime time.Time) (*HeaderRequest, []PenaltyItem)

func (*HeaderDownload) RequestSkeleton

func (hd *HeaderDownload) RequestSkeleton() *HeaderRequest

func (*HeaderDownload) SaveExternalAnnounce

func (hd *HeaderDownload) SaveExternalAnnounce(hash libcommon.Hash)

SaveExternalAnnounce - does mark hash as seen in external announcement only such hashes will broadcast further after

func (*HeaderDownload) SetFetchingNew

func (hd *HeaderDownload) SetFetchingNew(fetching bool)

func (*HeaderDownload) SetFirstPoSHeight

func (hd *HeaderDownload) SetFirstPoSHeight(blockHeight uint64)

func (*HeaderDownload) SetHeaderReader

func (hd *HeaderDownload) SetHeaderReader(headerReader consensus.ChainHeaderReader)

func (*HeaderDownload) SetHeaderToDownloadPoS

func (hd *HeaderDownload) SetHeaderToDownloadPoS(hash libcommon.Hash, height uint64)

func (*HeaderDownload) SetHeadersCollector

func (hd *HeaderDownload) SetHeadersCollector(collector *etl.Collector)

func (*HeaderDownload) SetPOSSync

func (hd *HeaderDownload) SetPOSSync(posSync bool)

func (*HeaderDownload) SetPendingPayloadHash

func (hd *HeaderDownload) SetPendingPayloadHash(header libcommon.Hash)

func (*HeaderDownload) SetPendingPayloadStatus

func (hd *HeaderDownload) SetPendingPayloadStatus(response *engineapi.PayloadStatus)

func (*HeaderDownload) SetPoSDownloaderTip

func (hd *HeaderDownload) SetPoSDownloaderTip(hash libcommon.Hash)

See https://hackmd.io/GDc0maGsQeKfP8o2C7L52w

func (*HeaderDownload) SetPosStatus

func (hd *HeaderDownload) SetPosStatus(status SyncStatus)

func (*HeaderDownload) SetRequestId

func (hd *HeaderDownload) SetRequestId(requestId int)

func (*HeaderDownload) SetUnsettledForkChoice

func (hd *HeaderDownload) SetUnsettledForkChoice(forkChoice *engineapi.ForkChoiceMessage, headHeight uint64)

func (*HeaderDownload) SingleHeaderAsSegment

func (hd *HeaderDownload) SingleHeaderAsSegment(headerRaw []byte, header *types.Header, penalizePoSBlocks bool) ([]ChainSegmentHeader, Penalty, error)

SingleHeaderAsSegment converts message containing 1 header into one singleton chain segment

func (*HeaderDownload) StartPoSDownloader

func (hd *HeaderDownload) StartPoSDownloader(
	ctx context.Context,
	headerReqSend func(context.Context, *HeaderRequest) ([64]byte, bool),
	penalize func(context.Context, []PenaltyItem),
)

func (*HeaderDownload) UpdateRetryTime

func (hd *HeaderDownload) UpdateRetryTime(req *HeaderRequest, currentTime time.Time, timeout time.Duration)

func (*HeaderDownload) UpdateStats

func (hd *HeaderDownload) UpdateStats(req *HeaderRequest, skeleton bool, peer [64]byte)

func (*HeaderDownload) VerifyHeader

func (hd *HeaderDownload) VerifyHeader(header *types.Header) error

type HeaderInserter

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

HeaderInserter encapsulates 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, headerReader services.HeaderAndCanonicalReader) *HeaderInserter

func (*HeaderInserter) BestHeaderChanged

func (hi *HeaderInserter) BestHeaderChanged() bool

func (*HeaderInserter) FeedHeaderPoS

func (hi *HeaderInserter) FeedHeaderPoS(db kv.GetPut, header *types.Header, hash libcommon.Hash) error

func (*HeaderInserter) FeedHeaderPoW

func (hi *HeaderInserter) FeedHeaderPoW(db kv.StatelessRwTx, headerReader services.HeaderReader, header *types.Header, headerRaw []byte, hash libcommon.Hash, blockHeight uint64) (td *big.Int, err error)

func (*HeaderInserter) ForkingPoint

func (hi *HeaderInserter) ForkingPoint(db kv.StatelessRwTx, header, parent *types.Header) (forkingPoint uint64, err error)

Find the forking point - i.e. the latest header on the canonical chain which is an ancestor of this one Most common case - forking point is the height of the parent header

func (*HeaderInserter) GetHighest

func (hi *HeaderInserter) GetHighest() uint64

func (*HeaderInserter) GetHighestHash

func (hi *HeaderInserter) GetHighestHash() libcommon.Hash

func (*HeaderInserter) GetHighestTimestamp

func (hi *HeaderInserter) GetHighestTimestamp() uint64

func (*HeaderInserter) NewFeedHeaderFunc

func (hi *HeaderInserter) NewFeedHeaderFunc(db kv.StatelessRwTx, headerReader services.HeaderReader) FeedHeaderFunc

func (*HeaderInserter) Unwind

func (hi *HeaderInserter) Unwind() bool

func (*HeaderInserter) UnwindPoint

func (hi *HeaderInserter) UnwindPoint() uint64

type HeaderRecord

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

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
	Anchor  *Anchor
}

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

type HeadersReverseSort

type HeadersReverseSort []ChainSegmentHeader

Implements sort.Interface so we can sort the incoming header in the message by block height

func (HeadersReverseSort) Len

func (h HeadersReverseSort) Len() int

func (HeadersReverseSort) Less

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

func (HeadersReverseSort) Swap

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

type HeadersSort

type HeadersSort []ChainSegmentHeader

Implements sort.Interface so we can sort the incoming header in the message by block height

func (HeadersSort) Len

func (h HeadersSort) Len() int

func (HeadersSort) Less

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

func (HeadersSort) Swap

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

type InsertQueue

type InsertQueue []*Link

InsertQueue keeps the links before they are inserted in the database It priorities them by block height (the lowest block height on the top), and if block heights are the same, by the verification status (verified/preverified on the top)

func (InsertQueue) Len

func (iq InsertQueue) Len() int

func (InsertQueue) Less

func (iq InsertQueue) Less(i, j int) bool

func (*InsertQueue) Pop

func (iq *InsertQueue) Pop() interface{}

func (*InsertQueue) Push

func (iq *InsertQueue) Push(x interface{})

func (InsertQueue) Swap

func (iq InsertQueue) 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
	NewBlockGossipAfterMergePenalty
)

func (Penalty) String

func (p Penalty) String() string

type PenaltyItem

type PenaltyItem struct {
	PeerID  [64]byte
	Penalty Penalty
}

type QueueID

type QueueID uint8
const (
	NoQueue QueueID = iota
	EntryQueueID
	InsertQueueID
	PersistedQueueID
)

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 Stats

type Stats struct {
	Requests            int
	SkeletonRequests    int
	Responses           int
	Duplicates          int
	ReqMinBlock         uint64
	ReqMaxBlock         uint64
	SkeletonReqMinBlock uint64
	SkeletonReqMaxBlock uint64
	RespMinBlock        uint64
	RespMaxBlock        uint64
}

type SyncStatus

type SyncStatus int

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