spenddagv1

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SortedSpenders

type SortedSpenders[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]] struct {
	// contains filtered or unexported fields
}

SortedSpenders is a set of Spenders that is sorted by their weight.

func NewSortedSpenders

func NewSortedSpenders[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]](owner *Spender[SpenderID, ResourceID, VoteRank], pendingUpdatesCounter *syncutils.Counter) *SortedSpenders[SpenderID, ResourceID, VoteRank]

NewSortedSpenders creates a new SortedSpenders that is owned by the given Spender.

func (*SortedSpenders[SpenderID, ResourceID, VoteRank]) Add

func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Add(spender *Spender[SpenderID, ResourceID, VoteRank]) bool

Add adds the given Spend to the SortedSpends.

func (*SortedSpenders[SpenderID, ResourceID, VoteRank]) ForEach

func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) ForEach(callback func(*Spender[SpenderID, ResourceID, VoteRank]) error, optIncludeOwner ...bool) error

ForEach iterates over all Spends of the SortedSpends and calls the given callback for each of them.

func (*SortedSpenders[SpenderID, ResourceID, VoteRank]) Range

func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Range(callback func(*Spender[SpenderID, ResourceID, VoteRank]), optIncludeOwner ...bool)

Range iterates over all Spends of the SortedSpends and calls the given callback for each of them (without manual error handling).

func (*SortedSpenders[SpenderID, ResourceID, VoteRank]) Remove

func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Remove(id SpenderID) bool

Remove removes the Spend with the given ID from the SortedSpends.

func (*SortedSpenders[SpenderID, ResourceID, VoteRank]) Shutdown

func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Shutdown() []*Spender[SpenderID, ResourceID, VoteRank]

func (*SortedSpenders[SpenderID, ResourceID, VoteRank]) String

func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) String() string

String returns a human-readable representation of the SortedSpends.

type SpendDAG

type SpendDAG[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]] struct {
	// contains filtered or unexported fields
}

SpendDAG represents a data structure that tracks causal relationships between Spends and that allows to efficiently manage these Spends (and vote on their fate).

func New

func New[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]](seatCount func() int) *SpendDAG[SpenderID, ResourceID, VoteRank]

New creates a new spenddag.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) AcceptanceState

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) AcceptanceState(spenderIDs ds.Set[SpenderID]) acceptance.State

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) AllSpendsSupported

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) AllSpendsSupported(seat account.SeatIndex, spenderIDs ds.Set[SpenderID]) bool

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) CastVotes

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) CastVotes(vote *vote.Vote[VoteRank], spenderIDs ds.Set[SpenderID]) error

CastVotes applies the given votes to the spenddag.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) ConflictingSpenders

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) ConflictingSpenders(spenderID SpenderID) (conflictingSpenders ds.Set[SpenderID], exists bool)

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) CreateSpender

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) CreateSpender(id SpenderID)

CreateSpender creates a new Spender.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) Events

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) Events() *spenddag.Events[SpenderID, ResourceID]

Events returns the events of the spenddag.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) EvictSpender

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) EvictSpender(spenderID SpenderID)

EvictSpend removes spend with given SpenderID from spenddag.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) FutureCone

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) FutureCone(spenderIDs ds.Set[SpenderID]) (futureCone ds.Set[SpenderID])

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) LikedInstead

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) LikedInstead(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]

LikedInstead returns the SpenderIDs of the Spenders that are liked instead of the Spenders.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) ReadConsistent

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) ReadConsistent(callback func(spenddag spenddag.ReadLockedSpendDAG[SpenderID, ResourceID, VoteRank]) error) error

ReadConsistent write locks the spenddag and exposes read-only methods to the callback to perform multiple reads while maintaining the same spenddag state.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SetAccepted

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SetAccepted(spenderID SpenderID)

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) Shutdown

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) Shutdown()

Shutdown shuts down the SpendDAG.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpendSetMembers

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpendSetMembers(spendSetID ResourceID) (spenders ds.Set[SpenderID], exists bool)

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpendSets

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpendSets(spenderID SpenderID) (spendSets ds.Set[ResourceID], exists bool)

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderChildren

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderChildren(spenderID SpenderID) (spendChildren ds.Set[SpenderID], exists bool)

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderParents

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderParents(spenderID SpenderID) (spendParents ds.Set[SpenderID], exists bool)

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderVoters

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderVoters(spenderID SpenderID) (spendVoters ds.Set[account.SeatIndex])

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderWeight

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderWeight(spenderID SpenderID) int64

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) UnacceptedSpenders

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) UnacceptedSpenders(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]

UnacceptedSpends takes a set of SpenderIDs and removes all the accepted Spends (leaving only the pending or rejected ones behind).

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) UpdateSpenderParents

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) UpdateSpenderParents(spenderID SpenderID, addedParentIDs ds.Set[SpenderID], removedParentIDs ds.Set[SpenderID]) error

UpdateSpenderParents updates the parents of the given Spend and returns an error if the operation failed.

func (*SpendDAG[SpenderID, ResourceID, VoteRank]) UpdateSpentResources

func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) UpdateSpentResources(id SpenderID, resourceIDs ds.Set[ResourceID]) error

type SpendSet

type SpendSet[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]] struct {
	// ID is the ID of the Resource being spent.
	ID ResourceID
	// contains filtered or unexported fields
}

SpendSet represents a set of Spenders of a Resource. If there's more than 1 spender in a SpendSet, they are conflicting with each other over the shared Resource.

func NewSpendSet

func NewSpendSet[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]](id ResourceID) *SpendSet[SpenderID, ResourceID, VoteRank]

NewSpendSet creates a new SpendSet containing spenders (e.g. a transaction) of a common resource (e.g. a utxo).

func (*SpendSet[SpenderID, ResourceID, VoteRank]) Add

func (c *SpendSet[SpenderID, ResourceID, VoteRank]) Add(addedSpender *Spender[SpenderID, ResourceID, VoteRank]) (otherMembers ds.Set[*Spender[SpenderID, ResourceID, VoteRank]], err error)

Add adds a Spender to the SpendSet and returns all other members of the set.

func (*SpendSet[SpenderID, ResourceID, VoteRank]) ForEach

func (c *SpendSet[SpenderID, ResourceID, VoteRank]) ForEach(callback func(parent *Spender[SpenderID, ResourceID, VoteRank]) error) error

func (*SpendSet[SpenderID, ResourceID, VoteRank]) OnAllMembersEvicted

func (c *SpendSet[SpenderID, ResourceID, VoteRank]) OnAllMembersEvicted(callback func(prevValue, newValue bool))

OnAllMembersEvicted executes a callback when all members of the SpendSet are evicted and the SpendSet itself can be evicted.

func (*SpendSet[SpenderID, ResourceID, VoteRank]) Remove

func (c *SpendSet[SpenderID, ResourceID, VoteRank]) Remove(removedSpender *Spender[SpenderID, ResourceID, VoteRank]) (removed bool)

Remove removes a Spender from the SpendSet and returns all remaining members of the set.

type Spender

type Spender[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]] struct {
	// ID is the identifier of the Spender.
	ID SpenderID

	// Parents is the set of parents of the Spender.
	Parents ds.Set[*Spender[SpenderID, ResourceID, VoteRank]]

	// Children is the set of children of the Spender.
	Children ds.Set[*Spender[SpenderID, ResourceID, VoteRank]]

	// SpendSets is the set of SpendSets that the Spend is part of.
	SpendSets ds.Set[*SpendSet[SpenderID, ResourceID, VoteRank]]

	// ConflictingSpenders is the set of spenders that try to spend one of more of the same resources as this Spender.
	ConflictingSpenders *SortedSpenders[SpenderID, ResourceID, VoteRank]

	// Weight is the Weight of the Spender.
	Weight *weight.Weight

	// LatestVotes is the set of the latest votes of the Spender.
	LatestVotes *shrinkingmap.ShrinkingMap[account.SeatIndex, *vote.Vote[VoteRank]]

	// AcceptanceStateUpdated is triggered when the AcceptanceState of the Spender is updated.
	AcceptanceStateUpdated *event.Event2[acceptance.State, acceptance.State]

	// PreferredInsteadUpdated is triggered when the preferred instead value of the Spender is updated.
	PreferredInsteadUpdated *event.Event1[*Spender[SpenderID, ResourceID, VoteRank]]

	// LikedInsteadAdded is triggered when a liked instead reference is added to the Spender.
	LikedInsteadAdded *event.Event1[*Spender[SpenderID, ResourceID, VoteRank]]

	// LikedInsteadRemoved is triggered when a liked instead reference is removed from the Spender.
	LikedInsteadRemoved *event.Event1[*Spender[SpenderID, ResourceID, VoteRank]]
	// contains filtered or unexported fields
}

Spender is a spender of resources that is part of a Spend DAG. An example of a spender is a transaction, and the resource it spends is a utxo.

func NewSpender

func NewSpender[SpenderID, ResourceID spenddag.IDType, VoteRank spenddag.VoteRankType[VoteRank]](id SpenderID, initialWeight *weight.Weight, pendingTasksCounter *syncutils.Counter, acceptanceThresholdProvider func() int64) *Spender[SpenderID, ResourceID, VoteRank]

NewSpend creates a new Spender.

func (*Spender[SpenderID, ResourceID, VoteRank]) ApplyVote

func (c *Spender[SpenderID, ResourceID, VoteRank]) ApplyVote(vote *vote.Vote[VoteRank])

func (*Spender[SpenderID, ResourceID, VoteRank]) Compare

func (c *Spender[SpenderID, ResourceID, VoteRank]) Compare(other *Spender[SpenderID, ResourceID, VoteRank]) int

Compare compares the Spender to the given other Spender.

func (*Spender[SpenderID, ResourceID, VoteRank]) Evict

func (c *Spender[SpenderID, ResourceID, VoteRank]) Evict() (evictedSpends []SpenderID)

Evict cleans up the sortedSpender.

func (*Spender[SpenderID, ResourceID, VoteRank]) IsAccepted

func (c *Spender[SpenderID, ResourceID, VoteRank]) IsAccepted() bool

IsAccepted returns true if the Spend is accepted.

func (*Spender[SpenderID, ResourceID, VoteRank]) IsLiked

func (c *Spender[SpenderID, ResourceID, VoteRank]) IsLiked() bool

IsLiked returns true if the Spend is liked instead of other conflicting Spenders.

func (*Spender[SpenderID, ResourceID, VoteRank]) IsPending

func (c *Spender[SpenderID, ResourceID, VoteRank]) IsPending() bool

IsPending returns true if the Spend is pending.

func (*Spender[SpenderID, ResourceID, VoteRank]) IsPreferred

func (c *Spender[SpenderID, ResourceID, VoteRank]) IsPreferred() bool

IsPreferred returns true if the Spend is preferred instead of its conflicting Spender.

func (*Spender[SpenderID, ResourceID, VoteRank]) IsRejected

func (c *Spender[SpenderID, ResourceID, VoteRank]) IsRejected() bool

IsRejected returns true if the Spend is rejected.

func (*Spender[SpenderID, ResourceID, VoteRank]) JoinSpendSets

func (c *Spender[SpenderID, ResourceID, VoteRank]) JoinSpendSets(spendSets ds.Set[*SpendSet[SpenderID, ResourceID, VoteRank]]) (joinedSpendSets ds.Set[ResourceID], err error)

JoinSpendSets registers the Spender with the given SpendSets.

func (*Spender[SpenderID, ResourceID, VoteRank]) LikedInstead

func (c *Spender[SpenderID, ResourceID, VoteRank]) LikedInstead() ds.Set[*Spender[SpenderID, ResourceID, VoteRank]]

LikedInstead returns the set of liked instead Spenders.

func (*Spender[SpenderID, ResourceID, VoteRank]) PreferredInstead

func (c *Spender[SpenderID, ResourceID, VoteRank]) PreferredInstead() *Spender[SpenderID, ResourceID, VoteRank]

PreferredInstead returns the preferred instead value of the Spender.

func (*Spender[SpenderID, ResourceID, VoteRank]) Shutdown

func (c *Spender[SpenderID, ResourceID, VoteRank]) Shutdown()

Shutdown shuts down the Spender.

func (*Spender[SpenderID, ResourceID, VoteRank]) String

func (c *Spender[SpenderID, ResourceID, VoteRank]) String() string

String returns a human-readable representation of the Spender.

func (*Spender[SpenderID, ResourceID, VoteRank]) UpdateParents

func (c *Spender[SpenderID, ResourceID, VoteRank]) UpdateParents(addedParents ds.Set[*Spender[SpenderID, ResourceID, VoteRank]], removedParents ds.Set[*Spender[SpenderID, ResourceID, VoteRank]]) (updated bool)

UpdateParents updates the parents of the Spender.

Jump to

Keyboard shortcuts

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