Documentation ¶
Index ¶
- Constants
- func DecodeTips(encodings []string) (map[libcommon.Hash]HeaderRecord, error)
- type Anchor
- type Announce
- type CalcDifficultyFunc
- type ChainSegment
- type ChainSegmentHeader
- type FeedHeaderFunc
- type HeaderDownload
- func (hd *HeaderDownload) AddHeadersFromSnapshot(tx kv.Tx, n uint64, r services.FullBlockReader) error
- func (hd *HeaderDownload) AddMinedHeader(header *types.Header) error
- func (hd *HeaderDownload) AfterInitialCycle()
- func (hd *HeaderDownload) ClearPendingPayloadHash()
- func (hd *HeaderDownload) ClearUnsettledForkChoice()
- func (hd *HeaderDownload) ExtractStats() Stats
- func (hd *HeaderDownload) FetchingNew() bool
- func (hd *HeaderDownload) FirstPoSHeight() *uint64
- func (hd *HeaderDownload) GetPendingPayloadHash() libcommon.Hash
- func (hd *HeaderDownload) GetPendingPayloadStatus() *engineapi.PayloadStatus
- func (hd *HeaderDownload) GetUnsettledForkChoice() (*engineapi.ForkChoiceMessage, uint64)
- func (hd *HeaderDownload) GrabAnnounces() []Announce
- func (hd *HeaderDownload) HasLink(linkHash libcommon.Hash) bool
- func (hd *HeaderDownload) HeadersCollector() *etl.Collector
- func (hd *HeaderDownload) InitialCycle() bool
- func (hd *HeaderDownload) InsertHeader(hf FeedHeaderFunc, terminalTotalDifficulty *big.Int, logPrefix string, ...) (bool, bool, uint64, uint64, error)
- func (hd *HeaderDownload) InsertHeaders(hf FeedHeaderFunc, terminalTotalDifficulty *big.Int, logPrefix string, ...) (bool, error)
- func (hd *HeaderDownload) IsBadHeader(headerHash libcommon.Hash) bool
- func (hd *HeaderDownload) IsBadHeaderPoS(tipHash libcommon.Hash) (bad bool, lastValidAncestor libcommon.Hash)
- func (hd *HeaderDownload) LogAnchorState()
- func (hd *HeaderDownload) MarkAllVerified()
- func (hd *HeaderDownload) POSSync() bool
- func (hd *HeaderDownload) PoSDownloaderTip() libcommon.Hash
- func (hd *HeaderDownload) PosStatus() SyncStatus
- func (hd *HeaderDownload) ProcessHeader(sh ChainSegmentHeader, newBlock bool, peerID [64]byte) bool
- func (hd *HeaderDownload) ProcessHeaders(csHeaders []ChainSegmentHeader, newBlock bool, peerID [64]byte) bool
- func (hd *HeaderDownload) ProcessHeadersPOS(csHeaders []ChainSegmentHeader, tx kv.Getter, peerId [64]byte) ([]PenaltyItem, error)
- func (hd *HeaderDownload) Progress() uint64
- func (hd *HeaderDownload) ReadProgressFromDb(tx kv.RwTx) (err error)
- func (hd *HeaderDownload) RecoverFromDb(db kv.RoDB) error
- func (hd *HeaderDownload) ReportBadHeader(headerHash libcommon.Hash)
- func (hd *HeaderDownload) ReportBadHeaderPoS(badHeader, lastValidAncestor libcommon.Hash)
- func (hd *HeaderDownload) RequestId() int
- func (hd *HeaderDownload) RequestMoreHeaders(currentTime time.Time) (*HeaderRequest, []PenaltyItem)
- func (hd *HeaderDownload) RequestSkeleton() *HeaderRequest
- func (hd *HeaderDownload) SaveExternalAnnounce(hash libcommon.Hash)
- func (hd *HeaderDownload) SetFetchingNew(fetching bool)
- func (hd *HeaderDownload) SetFirstPoSHeight(blockHeight uint64)
- func (hd *HeaderDownload) SetHeaderReader(headerReader consensus.ChainHeaderReader)
- func (hd *HeaderDownload) SetHeaderToDownloadPoS(hash libcommon.Hash, height uint64)
- func (hd *HeaderDownload) SetHeadersCollector(collector *etl.Collector)
- func (hd *HeaderDownload) SetPOSSync(posSync bool)
- func (hd *HeaderDownload) SetPendingPayloadHash(header libcommon.Hash)
- func (hd *HeaderDownload) SetPendingPayloadStatus(response *engineapi.PayloadStatus)
- func (hd *HeaderDownload) SetPoSDownloaderTip(hash libcommon.Hash)
- func (hd *HeaderDownload) SetPosStatus(status SyncStatus)
- func (hd *HeaderDownload) SetRequestId(requestId int)
- func (hd *HeaderDownload) SetUnsettledForkChoice(forkChoice *engineapi.ForkChoiceMessage, headHeight uint64)
- func (hd *HeaderDownload) SingleHeaderAsSegment(headerRaw []byte, header *types.Header, penalizePoSBlocks bool) ([]ChainSegmentHeader, Penalty, error)
- func (hd *HeaderDownload) StartPoSDownloader(ctx context.Context, ...)
- func (hd *HeaderDownload) UpdateRetryTime(req *HeaderRequest, currentTime time.Time, timeout time.Duration)
- func (hd *HeaderDownload) UpdateStats(req *HeaderRequest, skeleton bool, peer [64]byte)
- func (hd *HeaderDownload) VerifyHeader(header *types.Header) error
- type HeaderInserter
- func (hi *HeaderInserter) BestHeaderChanged() bool
- func (hi *HeaderInserter) FeedHeaderPoS(db kv.GetPut, header *types.Header, hash libcommon.Hash) error
- func (hi *HeaderInserter) FeedHeaderPoW(db kv.StatelessRwTx, headerReader services.HeaderReader, header *types.Header, ...) (td *big.Int, err error)
- func (hi *HeaderInserter) ForkingPoint(db kv.StatelessRwTx, header, parent *types.Header) (forkingPoint uint64, err error)
- func (hi *HeaderInserter) GetHighest() uint64
- func (hi *HeaderInserter) GetHighestHash() libcommon.Hash
- func (hi *HeaderInserter) GetHighestTimestamp() uint64
- func (hi *HeaderInserter) NewFeedHeaderFunc(db kv.StatelessRwTx, headerReader services.HeaderReader) FeedHeaderFunc
- func (hi *HeaderInserter) Unwind() bool
- func (hi *HeaderInserter) UnwindPoint() uint64
- type HeaderRecord
- type HeaderRequest
- type HeadersReverseSort
- type HeadersSort
- type InsertQueue
- type Link
- type LinkQueue
- type PeerHandle
- type PeerPenalty
- type Penalty
- type PenaltyItem
- type QueueID
- type SeenAnnounces
- type Stats
- type SyncStatus
- type VerifySealFunc
Constants ¶
const ( Idle = iota Syncing Synced // if we found a canonical hash during backward sync, in this case our sync process is done )
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 CalcDifficultyFunc ¶
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 FeedHeaderFunc ¶
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 (*HeaderDownload) HeadersCollector ¶
func (hd *HeaderDownload) HeadersCollector() *etl.Collector
func (*HeaderDownload) InitialCycle ¶
func (hd *HeaderDownload) InitialCycle() bool
func (*HeaderDownload) InsertHeader ¶
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 (*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)
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 (*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 ¶
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 ¶
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)
type SyncStatus ¶
type SyncStatus int