headerlist

package
v0.0.0-...-3e3078a Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundedMemoryChain

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

BoundedMemoryChain is an implemetnation of the headerlist.Chain interface which has a bounded size. The chain will be stored purely in memory. This is useful for enforcing that only the past N headers are stored in memory, or even as the primary header store. If an element inserted to the end of the chain exceeds the size limit, then the head of the chain will be moved forward removing a single entry from the head of the chain.

func NewBoundedMemoryChain

func NewBoundedMemoryChain(maxNodes uint32) *BoundedMemoryChain

NewBoundedMemoryChain returns a new instance of the BoundedMemoryChain with a target max number of nodes.

func (*BoundedMemoryChain) Back

func (b *BoundedMemoryChain) Back() *Node

Back returns the end of the chain. If the chain is empty, then this return a pointer to a nil node.

NOTE: Part of the Chain interface.

func (*BoundedMemoryChain) FetchHeaderAncestors

func (b *BoundedMemoryChain) FetchHeaderAncestors(n *Node, numNodes int) []*wire.BlockHeader

FetchHeaderAncestors will return the requested number of ancestors for the given node

func (*BoundedMemoryChain) Front

func (b *BoundedMemoryChain) Front() *Node

Front returns the head of the chain. If the chain is empty, then this returns a pointer to a nil node.

NOTE: Part of the Chain interface.

func (*BoundedMemoryChain) PushBack

func (b *BoundedMemoryChain) PushBack(n Node) *Node

PushBack will push a new entry to the end of the chain. The entry added to the chain is also returned in place. As the chain is bounded, if the length of the chain is exceeded, then the front of the chain will be walked forward one element.

NOTE: Part of the Chain interface.

func (*BoundedMemoryChain) ResetHeaderState

func (b *BoundedMemoryChain) ResetHeaderState(n Node, store headerfs.BlockHeaderStore) error

ResetHeaderState resets the state of all nodes. After this method, it will be as if the chain was just newly created. It will load the last 1000 blocks into the index if possible. This is necessary for calculating the difficulty after a few startup.

NOTE: Part of the Chain interface.

type Chain

type Chain interface {
	// ResetHeaderState resets the state of all nodes. After this method, it will
	// be as if the chain was just newly created.
	ResetHeaderState(Node, headerfs.BlockHeaderStore) error

	// Back returns the end of the chain. If the chain is empty, then this
	// return a pointer to a nil node.
	Back() *Node

	// Front returns the head of the chain. If the chain is empty, then
	// this returns a  pointer to a nil node.
	Front() *Node

	// PushBack will push a new entry to the end of the chain. The entry
	// added to the chain is also returned in place.
	PushBack(Node) *Node

	// Fetch the given number of ancestor headers for the given node
	FetchHeaderAncestors(*Node, int) []*wire.BlockHeader
}

Chain is an interface that stores a list of Nodes. Each node represents a header in the main chain and also includes a height along with it. This is meant to serve as a replacement to list.List which provides similar functionality, but allows implementations to use custom storage backends and semantics.

type Node

type Node struct {
	// Height is the height of this node within the main chain.
	Height int32

	// Header is the header that this node represents.
	Header wire.BlockHeader
	// contains filtered or unexported fields
}

Node is a node within the Chain. Each node stores a header as well as a height. Nodes can also be used to traverse the chain backwards via their Prev() method.

func (*Node) Prev

func (n *Node) Prev() *Node

Prev attempts to access the prior node within the header chain relative to this node. If this is the start of the chain, then this method will return nil.

func (*Node) SetPrev

func (n *Node) SetPrev(prev *Node)

SetPrev sets the previous node for this node

Jump to

Keyboard shortcuts

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