tipselect

package
v0.5.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoTipsAvailable is returned when no tips are available in the node.
	ErrNoTipsAvailable = errors.New("no tips available")
	// ErrTipLazy is returned when the choosen tip was lazy already.
	ErrTipLazy = errors.New("tip already lazy")
)

Functions

func TipCaller

func TipCaller(handler interface{}, params ...interface{})

TipCaller is used to signal tip events.

func WalkerStatsCaller

func WalkerStatsCaller(handler interface{}, params ...interface{})

WalkerStatsCaller is used to signal tip selection events.

Types

type Events

type Events struct {
	// TipAdded is fired when a tip is added.
	TipAdded *events.Event
	// TipRemoved is fired when a tip is removed.
	TipRemoved *events.Event
	// TipSelPerformed is fired when a tipselection was performed.
	TipSelPerformed *events.Event
}

Events represents events happening on the tip-selector.

type Score

type Score int

Score defines the score of a tip.

const (
	// ScoreLazy is a lazy tip and should not be selected.
	ScoreLazy Score = iota
	// ScoreSemiLazy is a somewhat lazy tip.
	ScoreSemiLazy
	// ScoreNonLazy is a non-lazy tip.
	ScoreNonLazy
)

type Tip

type Tip struct {
	// Score is the score of the tip.
	Score Score
	// Hash is the transaction hash of the tip.
	Hash hornet.Hash
	// TimeFirstApprover is the timestamp the tip was referenced for the first time by another transaction.
	TimeFirstApprover time.Time
	// ApproversCount is the amount the tip was referenced by other transactions.
	ApproversCount *atomic.Uint32
}

Tip defines a tip.

type TipSelStats

type TipSelStats struct {
	// The duration of the tip-selection for a single tip.
	Duration time.Duration `json:"duration"`
	// The amount of lazy tips found and removed during the tip-selection.
	LazyTips int `json:"lazy_tips"`
}

TipSelStats holds the stats for a tipselection run.

type TipSelectionFunc

type TipSelectionFunc = func() (hornet.Hashes, error)

TipSelectionFunc is a function which performs a tipselection and returns two tips.

type TipSelector

type TipSelector struct {

	// Events are the events that are triggered by the TipSelector.
	Events Events
	// contains filtered or unexported fields
}

TipSelector manages a list of tips and emits events for their removal and addition.

func New

func New(maxDeltaTxYoungestRootSnapshotIndexToLSMI int,
	maxDeltaTxApproveesOldestRootSnapshotIndexToLSMI int,
	belowMaxDepth int,
	retentionRulesTipsLimitNonLazy int,
	maxReferencedTipAgeSecondsNonLazy time.Duration,
	maxApproversNonLazy uint32,
	retentionRulesTipsLimitSemiLazy int,
	maxReferencedTipAgeSecondsSemiLazy time.Duration,
	maxApproversSemiLazy uint32) *TipSelector

New creates a new tip-selector.

func (*TipSelector) AddTip

func (ts *TipSelector) AddTip(bndl *tangle.Bundle)

AddTip adds the given tailTxHash as a tip.

func (*TipSelector) CleanUpReferencedTips

func (ts *TipSelector) CleanUpReferencedTips() int

CleanUpReferencedTips checks if tips were referenced before and removes them if they reached their maximum age.

func (*TipSelector) SelectNonLazyTips

func (ts *TipSelector) SelectNonLazyTips() (hornet.Hashes, error)

SelectNonLazyTips selects two non-lazy tips.

func (*TipSelector) SelectSemiLazyTips

func (ts *TipSelector) SelectSemiLazyTips() (hornet.Hashes, error)

SelectSemiLazyTips selects two semi-lazy tips.

func (*TipSelector) UpdateScores

func (ts *TipSelector) UpdateScores() int

UpdateScores updates the scores of the tips and removes lazy ones.

Jump to

Keyboard shortcuts

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