Documentation ¶
Index ¶
- Variables
- type HeaviestSelector
- func (s *HeaviestSelector) Continue()
- func (s *HeaviestSelector) OnNewSolidBlock(blockMeta *inx.BlockMetadata) (trackedBlocksCount int)
- func (s *HeaviestSelector) Reset()
- func (s *HeaviestSelector) SelectTips(minRequiredTips int) (iotago.BlockIDs, error)
- func (s *HeaviestSelector) Stop()
- func (s *HeaviestSelector) TipsToList() *TrackedBlocksList
- func (s *HeaviestSelector) TrackedBlocksCount() (trackedBlocksCount int)
- type TrackedBlocksList
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoTipsAvailable is returned when no tips are available in the node. ErrNoTipsAvailable = errors.New("no tips available") )
Functions ¶
This section is empty.
Types ¶
type HeaviestSelector ¶
HeaviestSelector implements the heaviest branch selection strategy.
func New ¶
func New(minHeaviestBranchUnreferencedBlocksThreshold int, maxHeaviestBranchTipsPerCheckpoint int, randomTipsPerCheckpoint int, heaviestBranchSelectionTimeout time.Duration) *HeaviestSelector
New creates a new HeaviestSelector instance.
func (*HeaviestSelector) Continue ¶ added in v1.0.0
func (s *HeaviestSelector) Continue()
func (*HeaviestSelector) OnNewSolidBlock ¶
func (s *HeaviestSelector) OnNewSolidBlock(blockMeta *inx.BlockMetadata) (trackedBlocksCount int)
OnNewSolidBlock adds a new block to be processed by s. The block must be solid and OnNewSolidBlock must be called in the order of solidification. The block must also not be below max depth.
func (*HeaviestSelector) Reset ¶
func (s *HeaviestSelector) Reset()
Reset resets the tracked blocks map and tips list of s.
func (*HeaviestSelector) SelectTips ¶
func (s *HeaviestSelector) SelectTips(minRequiredTips int) (iotago.BlockIDs, error)
SelectTips tries to collect tips that confirm the most recent blocks since the last reset of the selector. best tips are determined by counting the referenced blocks (heaviest branches) and by "removing" the blocks of the referenced cone of the already chosen tips in the bitsets of the available tips. only tips are considered that were present at the beginning of the SelectTips call, to prevent attackers from creating heavier branches while we are searching the best tips. "maxHeaviestBranchTipsPerCheckpoint" is the amount of tips that are collected if the current best tip is not below "UnreferencedBlocksThreshold" before. a minimum amount of selected tips can be enforced, even if none of the heaviest branches matches the "minHeaviestBranchUnreferencedBlocksThreshold" criteria. if at least one heaviest branch tip was found, "randomTipsPerCheckpoint" random tips are added to add some additional randomness to prevent parasite chain attacks. the selection is canceled after a fixed deadline. in this case, it returns the current collected tips.
func (*HeaviestSelector) Stop ¶ added in v1.0.0
func (s *HeaviestSelector) Stop()
func (*HeaviestSelector) TipsToList ¶ added in v1.0.0
func (s *HeaviestSelector) TipsToList() *TrackedBlocksList
TipsToList returns a new list containing the current tips.
func (*HeaviestSelector) TrackedBlocksCount ¶
func (s *HeaviestSelector) TrackedBlocksCount() (trackedBlocksCount int)
TrackedBlocksCount returns the amount of known blocks.
type TrackedBlocksList ¶ added in v1.0.0
type TrackedBlocksList struct {
// contains filtered or unexported fields
}
func (*TrackedBlocksList) Len ¶ added in v1.0.0
func (il *TrackedBlocksList) Len() int
Len returns the length of the inner blocks slice.