utreexobackends

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedFlag

type CachedFlag uint8

CachedFlag is the status of each of the cached elements in the NodesBackEnd.

const (
	// Fresh means it's never been in the database
	Fresh CachedFlag = 1 << iota

	// Modified means it's been in the database and has been modified in the cache.
	Modified

	// Removed means that the key it belongs to has been removed but it's still
	// in the cache.
	Removed
)

type CachedLeaf

type CachedLeaf struct {
	Leaf  utreexo.Leaf
	Flags CachedFlag
}

CachedLeaf has the leaf and a flag for the status in the cache.

func (*CachedLeaf) IsFresh

func (c *CachedLeaf) IsFresh() bool

IsFresh returns if the cached leaf has never been in the database.

func (*CachedLeaf) IsModified

func (c *CachedLeaf) IsModified() bool

IsModified returns if the cached leaf has been in the database and was modified in the cache.

func (*CachedLeaf) IsRemoved

func (c *CachedLeaf) IsRemoved() bool

IsRemoved returns if the key for this cached leaf has been removed.

type CachedLeavesMapSlice

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

CachedLeavesMapSlice is a slice of maps for utxo entries. The slice of maps are needed to guarantee that the map will only take up N amount of bytes. As of v1.20, the go runtime will allocate 2^N + few extra buckets, meaning that for large N, we'll allocate a lot of extra memory if the amount of entries goes over the previously allocated buckets. A slice of maps allows us to have a better control of how much total memory gets allocated by all the maps.

func NewCachedLeavesMapSlice

func NewCachedLeavesMapSlice(maxTotalMemoryUsage int64) (CachedLeavesMapSlice, int64)

NewCachedLeavesMapSlice returns a new CachedLeavesMapSlice and the total amount of elements that the map slice can accomodate.

func (*CachedLeavesMapSlice) ClearMaps added in v0.4.0

func (ms *CachedLeavesMapSlice) ClearMaps()

ClearMaps clears all maps

This function is safe for concurrent access.

func (*CachedLeavesMapSlice) Delete

func (ms *CachedLeavesMapSlice) Delete(k utreexo.Hash)

Delete attempts to delete the given outpoint in all of the maps. No-op if the outpoint doesn't exist.

This function is safe for concurrent access.

func (*CachedLeavesMapSlice) DeleteMaps

func (ms *CachedLeavesMapSlice) DeleteMaps()

DeleteMaps deletes all maps and allocate new ones with the maxEntries defined in ms.maxEntries.

This function is safe for concurrent access.

func (*CachedLeavesMapSlice) ForEach

func (ms *CachedLeavesMapSlice) ForEach(fn func(utreexo.Hash, CachedPosition) error) error

ForEach loops through all the elements in the cachedleaves map slice and calls fn with the key-value pairs.

This function is safe for concurrent access.

func (*CachedLeavesMapSlice) Get

Get looks for the outpoint in all the maps in the map slice and returns the entry. nil and false is returned if the outpoint is not found.

This function is safe for concurrent access.

func (*CachedLeavesMapSlice) Length

func (ms *CachedLeavesMapSlice) Length() int

Length returns the length of all the maps in the map slice added together.

This function is safe for concurrent access.

func (*CachedLeavesMapSlice) Overflowed added in v0.4.0

func (ms *CachedLeavesMapSlice) Overflowed() bool

Overflowed returns true if the map slice overflowed.

func (*CachedLeavesMapSlice) Put

Put puts the keys and the values into one of the maps in the map slice. If the existing maps are all full and it fails to put the entry in the cache, it will return false.

This function is safe for concurrent access.

type CachedPosition added in v0.4.0

type CachedPosition struct {
	Position uint64
	Flags    CachedFlag
}

CachedPosition has the leaf and a flag for the status in the cache.

func (*CachedPosition) IsFresh added in v0.4.0

func (c *CachedPosition) IsFresh() bool

IsFresh returns if the cached Position has never been in the database.

func (*CachedPosition) IsModified added in v0.4.0

func (c *CachedPosition) IsModified() bool

IsModified returns if the cached leaf has been in the database and was modified in the cache.

func (*CachedPosition) IsRemoved added in v0.4.0

func (c *CachedPosition) IsRemoved() bool

IsRemoved returns if the key for this cached leaf has been removed.

type NodesMapSlice

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

NodesMapSlice is a slice of maps for utxo entries. The slice of maps are needed to guarantee that the map will only take up N amount of bytes. As of v1.20, the go runtime will allocate 2^N + few extra buckets, meaning that for large N, we'll allocate a lot of extra memory if the amount of entries goes over the previously allocated buckets. A slice of maps allows us to have a better control of how much total memory gets allocated by all the maps.

func NewNodesMapSlice

func NewNodesMapSlice(maxTotalMemoryUsage int64) (NodesMapSlice, int64)

NewNodesMapSlice returns a new NodesMapSlice and the total amount of elements that the map slice can accomodate.

func (*NodesMapSlice) ClearMaps added in v0.4.0

func (ms *NodesMapSlice) ClearMaps()

ClearMaps clears all maps

This function is safe for concurrent access.

func (*NodesMapSlice) DeleteMaps

func (ms *NodesMapSlice) DeleteMaps()

DeleteMaps deletes all maps and allocate new ones with the maxEntries defined in ms.maxEntries.

This function is safe for concurrent access.

func (*NodesMapSlice) ForEach

func (ms *NodesMapSlice) ForEach(fn func(uint64, CachedLeaf) error) error

ForEach loops through all the elements in the nodes map slice and calls fn with the key-value pairs.

This function is safe for concurrent access.

func (*NodesMapSlice) Get

func (ms *NodesMapSlice) Get(k uint64) (CachedLeaf, bool)

get looks for the outpoint in all the maps in the map slice and returns the entry. nil and false is returned if the outpoint is not found.

This function is safe for concurrent access.

func (*NodesMapSlice) Length

func (ms *NodesMapSlice) Length() int

Length returns the length of all the maps in the map slice added together.

This function is safe for concurrent access.

func (*NodesMapSlice) Overflowed added in v0.4.0

func (ms *NodesMapSlice) Overflowed() bool

Overflowed returns true if the map slice overflowed.

func (*NodesMapSlice) Put

func (ms *NodesMapSlice) Put(k uint64, v CachedLeaf) bool

put puts the keys and the values into one of the maps in the map slice. If the existing maps are all full and it fails to put the entry in the cache, it will return false.

This function is safe for concurrent access.

Jump to

Keyboard shortcuts

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