headerfs

package
v0.0.0-...-f0bdd0e Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 struct {
	// contains filtered or unexported fields
}

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

func NewBlockHeaderStore

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

New 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.

func (*BlockHeaderStore) BlockLocatorFromHash

func (h *BlockHeaderStore) BlockLocatorFromHash(hash *chainhash.Hash) (blockchain.BlockLocator, error)

BlockLocatorFromHash computes a block locator given a particular hash. The standard Bitcoin algorithm to compute block locators are employed.

func (*BlockHeaderStore) ChainTip

func (h *BlockHeaderStore) ChainTip() (*wire.BlockHeader, uint32, error)

ChainTip returns the best known block header and height for the BlockHeaderStore.

func (*BlockHeaderStore) CheckConnectivity

func (h *BlockHeaderStore) CheckConnectivity() error

CheckConnectivity cycles through all of the block headers on disk, from last to first, and makes sure they all connect to each other. Additionally, at each block header, we also ensure that the index entry for that height and hash also match up properly.

func (*BlockHeaderStore) FetchHeader

func (h *BlockHeaderStore) FetchHeader(hash *chainhash.Hash) (*wire.BlockHeader, uint32, error)

FetchHeader attempts to retrieve a block header determined by the passed block height.

func (*BlockHeaderStore) FetchHeaderByHeight

func (h *BlockHeaderStore) FetchHeaderByHeight(height uint32) (*wire.BlockHeader, error)

FetchHeaderByHeight attempts to retrieve a target block header based on a block height.

func (*BlockHeaderStore) HeightFromHash

func (h *BlockHeaderStore) HeightFromHash(hash *chainhash.Hash) (uint32, error)

HeightFromHash returns the height of a particualr block header given its hash.

func (*BlockHeaderStore) LatestBlockLocator

func (h *BlockHeaderStore) LatestBlockLocator() (blockchain.BlockLocator, error)

LatestBlockLocator returns the latest block locator object based on the tip of the current main chain from the PoV of the database and flat files.

func (*BlockHeaderStore) RollbackLastBlock

func (h *BlockHeaderStore) RollbackLastBlock() (*waddrmgr.BlockStamp, error)

RollbackLastBlock rollsback both the index, and on-disk header file 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.

func (*BlockHeaderStore) WriteHeaders

func (h *BlockHeaderStore) WriteHeaders(hdrs ...BlockHeader) error

WriteHeaders writes a set of headers to disk and updates the index in a single atomic transaction.

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) (*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) 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 returnd.

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

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

	// ExtendedFilter is a header type that represents the extended filter
	// header type for the filter header chain.
	ExtendedFilter
)

Jump to

Keyboard shortcuts

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