headerfs

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: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockHeaderSize is the size in bytes of the Block header type.
	BlockHeaderSize = 80

	// RegularFilterHeaderSize is the size in bytes of the RegularFilter
	// header type.
	RegularFilterHeaderSize = 32
)
View Source
const (
	// MedianTimeBlocks is the number of previous blocks which should be
	// used to calculate the median time used to validate block timestamps.
	MedianTimeBlocks = 11
)

Variables

View Source
var (
	// ErrHeightNotFound is returned when a specified height isn't found in
	// a target index.
	ErrHeightNotFound = fmt.Errorf("target height not found in index")

	// ErrHashNotFound is returned when a specified block hash isn't found
	// in a target index.
	ErrHashNotFound = fmt.Errorf("target hash not found in index")
)

Functions

This section is empty.

Types

type BlockHeader

type BlockHeader struct {
	*wire.BlockHeader

	// Height is the height of this block header within the current main
	// chain.
	Height uint32
}

BlockHeader is a Bitcoin block header that also has its height included.

type BlockHeaderStore

type BlockHeaderStore interface {
	// ChainTip returns the best known block header and height for the
	// BlockHeaderStore.
	ChainTip() (*wire.BlockHeader, uint32, error)

	// LatestBlockLocator returns the latest block locator object based on
	// the tip of the current main chain from the PoV of the
	// BlockHeaderStore.
	LatestBlockLocator() (blockchain.BlockLocator, error)

	// FetchHeaderByHeight attempts to retrieve a target block header based
	// on a block height.
	FetchHeaderByHeight(height uint32) (*wire.BlockHeader, error)

	// FetchHeaderAncestors fetches the numHeaders block headers that are
	// the ancestors of the target stop hash. A total of numHeaders+1
	// headers will be returned, as we'll walk back numHeaders distance to
	// collect each header, then return the final header specified by the
	// stop hash. We'll also return the starting height of the header range
	// as well so callers can compute the height of each header without
	// knowing the height of the stop hash.
	FetchHeaderAncestors(uint32, *chainhash.Hash) ([]wire.BlockHeader,
		uint32, error)

	// HeightFromHash returns the height of a particular block header given
	// its hash.
	HeightFromHash(*chainhash.Hash) (uint32, error)

	// FetchHeader attempts to retrieve a block header determined by the
	// passed block height.
	FetchHeader(*chainhash.Hash) (*wire.BlockHeader, uint32, error)

	// WriteHeaders adds a set of headers to the BlockHeaderStore in a
	// single atomic transaction.
	WriteHeaders(...BlockHeader) error

	// RollbackLastBlock rolls back the BlockHeaderStore by a _single_
	// header. This method is meant to be used in the case of re-org which
	// disconnects the latest block header from the end of the main chain.
	// The information about the new header tip after truncation is
	// returned.
	RollbackLastBlock() (*waddrmgr.BlockStamp, error)

	// CalcPastMedianTime calculates the median time of the previous few blocks
	// prior to, and including, the block node.
	//
	// This function is safe for concurrent access.
	CalcPastMedianTime([]*wire.BlockHeader) (time.Time, error)
}

BlockHeaderStore is an interface that provides an abstraction for a generic store for block headers.

func NewBlockHeaderStore

func NewBlockHeaderStore(filePath string, db walletdb.DB,
	netParams *chaincfg.Params) (BlockHeaderStore, error)

NewBlockHeaderStore creates a new instance of the blockHeaderStore based on a target file path, an open database instance, and finally a set of parameters for the target chain. These parameters are required as if this is the initial start up of the blockHeaderStore, then the initial genesis header will need to be inserted.

type ErrHeaderNotFound

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

ErrHeaderNotFound is returned when a target header on disk (flat file) can't be found.

type FilterHeader

type FilterHeader struct {
	// HeaderHash is the hash of the block header that this filter header
	// corresponds to.
	HeaderHash chainhash.Hash

	// FilterHash is the filter header itself.
	FilterHash chainhash.Hash

	// Height is the block height of the filter header in the main chain.
	Height uint32
}

FilterHeader represents a filter header (basic or extended). The filter header itself is coupled with the block height and hash of the filter's block.

type FilterHeaderStore

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

FilterHeaderStore is an implementation of a fully fledged database for any variant of filter headers. The FilterHeaderStore combines a flat file to store the block headers with a database instance for managing the index into the set of flat files.

func NewFilterHeaderStore

func NewFilterHeaderStore(filePath string, db walletdb.DB,
	filterType HeaderType, netParams *chaincfg.Params,
	headerStateAssertion *FilterHeader) (*FilterHeaderStore, error)

NewFilterHeaderStore returns a new instance of the FilterHeaderStore based on a target file path, filter type, and target net parameters. These parameters are required as if this is the initial start up of the FilterHeaderStore, then the initial genesis filter header will need to be inserted.

func (*FilterHeaderStore) ChainTip

func (f *FilterHeaderStore) ChainTip() (*chainhash.Hash, uint32, error)

ChainTip returns the latest filter header and height known to the FilterHeaderStore.

func (*FilterHeaderStore) FetchHeader

func (f *FilterHeaderStore) FetchHeader(hash *chainhash.Hash) (*chainhash.Hash, error)

FetchHeader returns the filter header that corresponds to the passed block height.

func (*FilterHeaderStore) FetchHeaderAncestors

func (f *FilterHeaderStore) FetchHeaderAncestors(numHeaders uint32,
	stopHash *chainhash.Hash) ([]chainhash.Hash, uint32, error)

FetchHeaderAncestors fetches the numHeaders filter headers that are the ancestors of the target stop block hash. A total of numHeaders+1 headers will be returned, as we'll walk back numHeaders distance to collect each header, then return the final header specified by the stop hash. We'll also return the starting height of the header range as well so callers can compute the height of each header without knowing the height of the stop hash.

func (*FilterHeaderStore) FetchHeaderByHeight

func (f *FilterHeaderStore) FetchHeaderByHeight(height uint32) (*chainhash.Hash, error)

FetchHeaderByHeight returns the filter header for a particular block height.

func (*FilterHeaderStore) RollbackLastBlock

func (f *FilterHeaderStore) RollbackLastBlock(newTip *chainhash.Hash) (*waddrmgr.BlockStamp, error)

RollbackLastBlock rollsback both the index, and on-disk header file by a _single_ filter header. This method is meant to be used in the case of re-org which disconnects the latest filter header from the end of the main chain. The information about the latest header tip after truncation is returned.

func (*FilterHeaderStore) WriteHeaders

func (f *FilterHeaderStore) WriteHeaders(hdrs ...FilterHeader) error

WriteHeaders writes a batch of filter headers to persistent storage. The headers themselves are appended to the flat file, and then the index updated to reflect the new entires.

type HeaderType

type HeaderType uint8

HeaderType is an enum-like type which defines the various header types that are stored within the index.

const (
	// Block is the header type that represents regular Bitcoin block
	// headers.
	Block HeaderType = iota

	// RegularFilter is a header type that represents the basic filter
	// header type for the filter header chain.
	RegularFilter
)

Jump to

Keyboard shortcuts

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