tipselect

package
v2.0.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 14 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")
)

Functions

func RandomInsecure

func RandomInsecure(min int, max int) int

RandomInsecure returns a random int in the range of min to max. the result is not cryptographically secure. RandomInsecure is inclusive max value.

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
	// BlockID is the block ID of the tip.
	BlockID iotago.BlockID
	// TimeFirstChild is the timestamp the tip was referenced for the first time by another block.
	TimeFirstChild time.Time
	// ChildrenCount is the amount the tip was referenced by other blocks.
	ChildrenCount *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"`
}

TipSelStats holds the stats for a tipselection run.

type TipSelectionFunc

type TipSelectionFunc = func() (iotago.BlockIDs, error)

TipSelectionFunc is a function which performs a tipselection and returns 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(
	shutdownCtx context.Context,
	tipScoreCalculator *tangle.TipScoreCalculator,
	syncManager *syncmanager.SyncManager,
	serverMetrics *metrics.ServerMetrics,
	retentionRulesTipsLimitNonLazy int,
	maxReferencedTipAgeNonLazy time.Duration,
	maxChildrenNonLazy uint32,
	retentionRulesTipsLimitSemiLazy int,
	maxReferencedTipAgeSemiLazy time.Duration,
	maxChildrenSemiLazy uint32) *TipSelector

New creates a new tip-selector.

func (*TipSelector) AddTip

func (ts *TipSelector) AddTip(blockMeta *storage.BlockMetadata)

AddTip adds the given block 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() (iotago.BlockIDs, error)

SelectNonLazyTips selects two non-lazy tips.

func (*TipSelector) SelectSemiLazyTips

func (ts *TipSelector) SelectSemiLazyTips() (iotago.BlockIDs, error)

SelectSemiLazyTips selects two semi-lazy tips.

func (*TipSelector) SelectTipsWithSemiLazyAllowed

func (ts *TipSelector) SelectTipsWithSemiLazyAllowed() (tips iotago.BlockIDs, err error)

SelectTipsWithSemiLazyAllowed tries to select semi-lazy tips first, but uses non-lazy tips instead if not enough semi-lazy tips are found. This functionality may be useful for healthy spammers.

func (*TipSelector) TipCount

func (ts *TipSelector) TipCount() (int, int)

TipCount returns the current amount of available tips in the non-lazy and semi-lazy pool.

func (*TipSelector) UpdateScores

func (ts *TipSelector) UpdateScores() (int, error)

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