spendpruner

package
v4.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2023 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrNoConsumer indicates a spend journal consumer hash does not exist.
	ErrNoConsumer = ErrorKind("ErrNoConsumer")

	// ErrLoadSpendDeps indicates an error loading consumer
	// spend dependencies.
	ErrLoadSpendDeps = ErrorKind("ErrLoadSpendDeps")

	// ErrNeedSpendData indicates an error asserting a spend data dependency.
	ErrNeedSpendData = ErrorKind("ErrNeedSpendData")

	// ErrUpdateConsumerDeps indicates an error updating consumer spend
	// dependencies.
	ErrUpdateConsumerDeps = ErrorKind("ErrUpdateConsumerDeps")
)

These constants are used to identify a specific PruneError.

Variables

This section is empty.

Functions

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type ErrorKind

type ErrorKind string

ErrorKind identifies a kind of error. It has full support for errors.Is and errors.As, so the caller can directly check against an error kind when determining the reason for an error.

func (ErrorKind) Error

func (e ErrorKind) Error() string

Error satisfies the error interface and prints human-readable errors.

type PruneError

type PruneError struct {
	Description string
	Err         error
}

PruneError identifies a spend journal pruner error. It has full support for errors.Is and errors.As, so the caller can ascertain the specific reason for the error by checking the underlying error.

func (PruneError) Error

func (e PruneError) Error() string

Error satisfies the error interface and prints human-readable errors.

func (PruneError) Unwrap

func (e PruneError) Unwrap() error

Unwrap returns the underlying wrapped error.

type SpendConsumer

type SpendConsumer interface {
	// ID returns the identifier of the consumer.
	ID() string

	// NeedSpendData checks whether the associated spend journal entry for the
	// provided block hash will be needed by the consumer.
	NeedSpendData(hash *chainhash.Hash) (bool, error)
}

SpendConsumer describes the requirements for implementing a spend journal consumer.

All functions MUST be safe for concurrent access.

type SpendJournalNotification

type SpendJournalNotification struct {
	BlockHash *chainhash.Hash
	Event     spendPrunerEventType
	Done      chan bool
}

SpendJournalNotification represents the notification received by the pruner on block connections and disconnections.

type SpendJournalPruner

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

SpendJournalPruner represents a spend journal pruner that ensures spend journal entries needed by consumers are retained until no longer needed.

func NewSpendJournalPruner

func NewSpendJournalPruner(db database.DB, removeSpendEntry func(hash *chainhash.Hash) error) (*SpendJournalPruner, error)

NewSpendJournalPruner initializes a spend journal pruner.

func (*SpendJournalPruner) AddConsumer

func (s *SpendJournalPruner) AddConsumer(consumer SpendConsumer)

AddConsumer adds a spend journal consumer to the pruner.

func (*SpendJournalPruner) DependencyExists

func (s *SpendJournalPruner) DependencyExists(blockHash *chainhash.Hash) bool

DependencyExists determines whether there are spend consumer dependencies for the provided block hash.

func (*SpendJournalPruner) FetchConsumer

func (s *SpendJournalPruner) FetchConsumer(id string) (SpendConsumer, error)

FetchConsumer returns the spend journal consumer associated with the provided id.

func (*SpendJournalPruner) HandleSignals

func (s *SpendJournalPruner) HandleSignals(ctx context.Context)

HandleSignals processes incoming signals to the spend pruner.

func (*SpendJournalPruner) MaybePruneSpendData

func (s *SpendJournalPruner) MaybePruneSpendData(blockHash *chainhash.Hash, done chan bool) error

MaybePruneSpendData firsts adds consumer spend dependencies for the provided blockhash if any. If there are no dependencies the spend journal entry associated with the provided block hash is pruned.

func (*SpendJournalPruner) NotifyConnectedBlock

func (s *SpendJournalPruner) NotifyConnectedBlock(blockHash *chainhash.Hash)

NotifyConnectedBlock signals the spend pruner of the provided connected block hash.

func (*SpendJournalPruner) RemoveSpendConsumerDependency

func (s *SpendJournalPruner) RemoveSpendConsumerDependency(dbTx database.Tx, blockHash *chainhash.Hash, consumerID string) error

RemoveSpendConsumerDependency removes the provided spend consumer dependency associated with the provided block hash from the spend pruner. The block hash is removed as a key of the dependents map once all its dependency entries are removed.

Jump to

Keyboard shortcuts

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