Documentation ¶
Index ¶
- type SortedSpenders
- func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Add(spender *Spender[SpenderID, ResourceID, VoteRank]) bool
- func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) ForEach(callback func(*Spender[SpenderID, ResourceID, VoteRank]) error, ...) error
- func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Range(callback func(*Spender[SpenderID, ResourceID, VoteRank]), ...)
- func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Remove(id SpenderID) bool
- func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) Shutdown() []*Spender[SpenderID, ResourceID, VoteRank]
- func (s *SortedSpenders[SpenderID, ResourceID, VoteRank]) String() string
- type SpendDAG
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) AcceptanceState(spenderIDs ds.Set[SpenderID]) acceptance.State
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) AllSpendsSupported(seat account.SeatIndex, spenderIDs ds.Set[SpenderID]) bool
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) CastVotes(vote *vote.Vote[VoteRank], spenderIDs ds.Set[SpenderID]) error
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) ConflictingSpenders(spenderID SpenderID) (conflictingSpenders ds.Set[SpenderID], exists bool)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) CreateSpender(id SpenderID)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) Events() *spenddag.Events[SpenderID, ResourceID]
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) EvictSpender(spenderID SpenderID)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) FutureCone(spenderIDs ds.Set[SpenderID]) (futureCone ds.Set[SpenderID])
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) LikedInstead(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) ReadConsistent(...) error
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SetAccepted(spenderID SpenderID)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) Shutdown()
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpendSetMembers(spendSetID ResourceID) (spenders ds.Set[SpenderID], exists bool)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpendSets(spenderID SpenderID) (spendSets ds.Set[ResourceID], exists bool)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderChildren(spenderID SpenderID) (spendChildren ds.Set[SpenderID], exists bool)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderParents(spenderID SpenderID) (spendParents ds.Set[SpenderID], exists bool)
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderVoters(spenderID SpenderID) (spendVoters ds.Set[account.SeatIndex])
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderWeight(spenderID SpenderID) int64
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) UnacceptedSpenders(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) UpdateSpenderParents(spenderID SpenderID, addedParentIDs ds.Set[SpenderID], ...) error
- func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) UpdateSpentResources(id SpenderID, resourceIDs ds.Set[ResourceID]) error
- type SpendSet
- func (c *SpendSet[SpenderID, ResourceID, VoteRank]) Add(addedSpender *Spender[SpenderID, ResourceID, VoteRank]) (otherMembers ds.Set[*Spender[SpenderID, ResourceID, VoteRank]], err error)
- func (c *SpendSet[SpenderID, ResourceID, VoteRank]) ForEach(callback func(parent *Spender[SpenderID, ResourceID, VoteRank]) error) error
- func (c *SpendSet[SpenderID, ResourceID, VoteRank]) OnAllMembersEvicted(callback func(prevValue, newValue bool))
- func (c *SpendSet[SpenderID, ResourceID, VoteRank]) Remove(removedSpender *Spender[SpenderID, ResourceID, VoteRank]) (removed bool)
- type Spender
- func (c *Spender[SpenderID, ResourceID, VoteRank]) ApplyVote(vote *vote.Vote[VoteRank])
- func (c *Spender[SpenderID, ResourceID, VoteRank]) Compare(other *Spender[SpenderID, ResourceID, VoteRank]) int
- func (c *Spender[SpenderID, ResourceID, VoteRank]) Evict() (evictedSpends []SpenderID)
- func (c *Spender[SpenderID, ResourceID, VoteRank]) IsAccepted() bool
- func (c *Spender[SpenderID, ResourceID, VoteRank]) IsLiked() bool
- func (c *Spender[SpenderID, ResourceID, VoteRank]) IsPending() bool
- func (c *Spender[SpenderID, ResourceID, VoteRank]) IsPreferred() bool
- func (c *Spender[SpenderID, ResourceID, VoteRank]) IsRejected() bool
- func (c *Spender[SpenderID, ResourceID, VoteRank]) JoinSpendSets(spendSets ds.Set[*SpendSet[SpenderID, ResourceID, VoteRank]]) (joinedSpendSets ds.Set[ResourceID], err error)
- func (c *Spender[SpenderID, ResourceID, VoteRank]) LikedInstead() ds.Set[*Spender[SpenderID, ResourceID, VoteRank]]
- func (c *Spender[SpenderID, ResourceID, VoteRank]) PreferredInstead() *Spender[SpenderID, ResourceID, VoteRank]
- func (c *Spender[SpenderID, ResourceID, VoteRank]) Shutdown()
- func (c *Spender[SpenderID, ResourceID, VoteRank]) String() string
- func (c *Spender[SpenderID, ResourceID, VoteRank]) UpdateParents(addedParents ds.Set[*Spender[SpenderID, ResourceID, VoteRank]], ...) (updated bool)
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 (*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 (*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 (*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 (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderChildren ¶
func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderParents ¶
func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderVoters ¶
func (*SpendDAG[SpenderID, ResourceID, VoteRank]) SpenderWeight ¶
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.
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]) 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.
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]) 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 ¶
IsAccepted returns true if the Spend is accepted.
func (*Spender[SpenderID, ResourceID, VoteRank]) IsLiked ¶
IsLiked returns true if the Spend is liked instead of other conflicting Spenders.
func (*Spender[SpenderID, ResourceID, VoteRank]) IsPending ¶
IsPending returns true if the Spend is pending.
func (*Spender[SpenderID, ResourceID, VoteRank]) IsPreferred ¶
IsPreferred returns true if the Spend is preferred instead of its conflicting Spender.
func (*Spender[SpenderID, ResourceID, VoteRank]) IsRejected ¶
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 ¶
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.