bloom

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxFilterLoadHashFuncs is the maximum number of hash functions to
	// load into the Bloom filter.
	MaxFilterLoadHashFuncs = 50

	// MaxFilterLoadFilterSize is the maximum size in bytes a filter may be.
	MaxFilterLoadFilterSize = 36000
)

Variables

This section is empty.

Functions

func CheckMerkleBlock

func CheckMerkleBlock(m msg.MerkleBlock) ([]*common.Uint256, error)

take in a merkle block, parse through it, and return txids indicated If there's any problem return an error. Checks self-consistency only. doing it with a stack instead of recursion. Because... OK I don't know why I'm just not in to recursion OK?

func HashMerkleBranches

func HashMerkleBranches(left *common.Uint256, right *common.Uint256) *common.Uint256

HashMerkleBranches takes two hashes, treated as the left and right tree nodes, and returns the hash of their concatenation. This is a helper function used to aid in the generation of a merkle tree.

func MakeMerkleParent

func MakeMerkleParent(left *common.Uint256, right *common.Uint256) (*common.Uint256, error)

func MurmurHash3

func MurmurHash3(seed uint32, data []byte) uint32

MurmurHash3 implements a non-cryptographic hash function using the MurmurHash3 algorithm. This implementation yields a 32-bit hash value which is suitable for general hash-based lookups. The seed can be used to effectively randomize the hash function. This makes it ideal for use in bloom filters which need multiple independent hash functions.

func NewMerkleBlock

func NewMerkleBlock(block *types.Block, filter *Filter) (*msg.MerkleBlock, []uint32)

NewMerkleBlock returns a new *MerkleBlock

func NewTxFilter

func NewTxFilter() filter.TxFilter

Types

type Filter

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

Filter defines a bitcoin bloom filter that provides easy manipulation of raw filter data.

func LoadFilter

func LoadFilter(msg *msg.FilterLoad) *Filter

LoadFilter creates a new Filter instance with the given underlying msg.FilterLoad.

func NewFilter

func NewFilter(elements, tweak uint32, fprate float64) *Filter

NewFilter creates a new bloom filter instance, mainly to be used by SPV clients. The tweak parameter is a random value added to the seed value. The false positive rate is the probability of a false positive where 1.0 is "match everything" and zero is unachievable. Thus, providing any false positive rates less than 0 or greater than 1 will be adjusted to the valid range.

For more information on what values to use for both elements and fprate, see https://en.wikipedia.org/wiki/Bloom_filter.

func (*Filter) Add

func (bf *Filter) Add(data []byte)

Add adds the passed byte slice to the bloom filter.

This function is safe for concurrent access.

func (*Filter) AddHash

func (bf *Filter) AddHash(hash *common.Uint256)

AddHash adds the passed chainhash.Hash to the Filter.

This function is safe for concurrent access.

func (*Filter) AddOutPoint

func (bf *Filter) AddOutPoint(outpoint *types.OutPoint)

AddOutPoint adds the passed tx outpoint to the bloom filter.

This function is safe for concurrent access.

func (*Filter) GetFilterLoadMsg

func (bf *Filter) GetFilterLoadMsg() *msg.FilterLoad

func (*Filter) IsLoaded

func (bf *Filter) IsLoaded() bool

IsLoaded returns true if a filter is loaded, otherwise false.

This function is safe for concurrent access.

func (*Filter) MatchTxAndUpdate

func (bf *Filter) MatchTxAndUpdate(tx *types.Transaction) bool

MatchTxAndUpdate returns true if the bloom filter matches data within the passed tx, otherwise false is returned. If the filter does match the passed tx, it will also update the filter depending on the bloom update flags set via the loaded filter if needed.

This function is safe for concurrent access.

func (*Filter) Matches

func (bf *Filter) Matches(data []byte) bool

Matches returns true if the bloom filter might contain the passed data and false if it definitely does not.

This function is safe for concurrent access.

func (*Filter) MatchesOutPoint

func (bf *Filter) MatchesOutPoint(outpoint *types.OutPoint) bool

MatchesOutPoint returns true if the bloom filter might contain the passed outpoint and false if it definitely does not.

This function is safe for concurrent access.

func (*Filter) Reload

func (bf *Filter) Reload(msg *msg.FilterLoad)

Reload loads a new filter replacing any existing filter.

This function is safe for concurrent access.

func (*Filter) Unload

func (bf *Filter) Unload()

Unload unloads the bloom filter.

This function is safe for concurrent access.

type MBlock

type MBlock struct {
	NumTx       uint32
	AllHashes   []*common.Uint256
	FinalHashes []*common.Uint256
	MatchedBits []byte
	Bits        []byte
}

MBlock is used to house intermediate information needed to generate a MerkleBlock according to a filter.

func (*MBlock) CalcHash

func (m *MBlock) CalcHash(height, pos uint32) *common.Uint256

calcHash returns the hash for a sub-tree given a depth-first height and node position.

func (*MBlock) CalcTreeWidth

func (m *MBlock) CalcTreeWidth(height uint32) uint32

calcTreeWidth calculates and returns the the number of nodes (width) or a merkle tree at the given depth-first height.

func (*MBlock) TraverseAndBuild

func (m *MBlock) TraverseAndBuild(height, pos uint32)

traverseAndBuild builds a partial merkle tree using a recursive depth-first approach. As it calculates the hashes, it also saves whether or not each node is a parent node and a list of final hashes to be included in the merkle block.

type MerkleBranch

type MerkleBranch struct {
	Branches []common.Uint256
	Index    int
}

func GetTxMerkleBranch

func GetTxMerkleBranch(msg msg.MerkleBlock, txID *common.Uint256) (*MerkleBranch, error)

type MerkleProof

type MerkleProof struct {
	BlockHash    common.Uint256
	Height       uint32
	Transactions uint32
	Hashes       []*common.Uint256
	Flags        []byte
}

func (*MerkleProof) Deserialize

func (p *MerkleProof) Deserialize(r io.Reader) error

func (*MerkleProof) Serialize

func (p *MerkleProof) Serialize(w io.Writer) error

type TxFilter

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

func (*TxFilter) Add

func (f *TxFilter) Add(filter []byte) error

func (*TxFilter) Load

func (f *TxFilter) Load(filter []byte) error

func (*TxFilter) MatchConfirmed

func (f *TxFilter) MatchConfirmed(tx *types.Transaction) bool

func (*TxFilter) MatchUnconfirmed

func (f *TxFilter) MatchUnconfirmed(tx *types.Transaction) bool

Jump to

Keyboard shortcuts

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