Documentation ¶
Index ¶
- func MergeToMaster[ConflictIDType, ResourceIDType comparable](mergeToMaster bool) options.Option[ConflictDAG[ConflictIDType, ResourceIDType]]
- type Conflict
- func (c *Conflict[ConflictIDType, ResourceIDType]) Children() (children *advancedset.AdvancedSet[*Conflict[ConflictIDType, ResourceIDType]])
- func (c *Conflict[ConflictIDType, ResourceIDType]) ConfirmationState() (confirmationState confirmation.State)
- func (c *Conflict[ConflictIDType, ResourceIDType]) ConflictSets() (...)
- func (c *Conflict[ConflictIDType, ResourceIDType]) ForEachConflictingConflict(...)
- func (c *Conflict[ConflictIDType, ResourceIDType]) ID() ConflictIDType
- func (c *Conflict[ConflictIDType, ResourceIDType]) Parents() (parents *advancedset.AdvancedSet[ConflictIDType])
- type ConflictDAG
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ConfirmationState(conflictIDs *advancedset.AdvancedSet[ConflictIDType]) (confirmationState confirmation.State)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) Conflict(conflictID ConflictIDType) (conflict *Conflict[ConflictIDType, ResourceIDType], exists bool)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ConflictSet(resourceID ResourceIDType) (conflictSet *ConflictSet[ConflictIDType, ResourceIDType], exists bool)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) CreateConflict(id ConflictIDType, parentIDs *advancedset.AdvancedSet[ConflictIDType], ...) (created bool)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) DetermineVotes(conflictIDs *advancedset.AdvancedSet[ConflictIDType]) (addedConflicts, revokedConflicts *advancedset.AdvancedSet[ConflictIDType], ...)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ForEachConflict(consumer func(conflict *Conflict[ConflictIDType, ResourceIDType]))
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ForEachConnectedConflictingConflictID(rootConflict *Conflict[ConflictIDType, ResourceIDType], ...)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) HandleOrphanedConflict(conflictID ConflictIDType)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) SetConflictAccepted(conflictID ConflictIDType) (modified bool)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) UnconfirmedConflicts(conflictIDs *advancedset.AdvancedSet[ConflictIDType]) (pendingConflictIDs *advancedset.AdvancedSet[ConflictIDType])
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictParents(id ConflictIDType, removedConflictIDs *advancedset.AdvancedSet[ConflictIDType], ...) (updated bool)
- func (c *ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictingResources(id ConflictIDType, ...) (updated bool)
- type ConflictParentsUpdatedEvent
- type ConflictSet
- func (c *ConflictSet[ConflictIDType, ResourceIDType]) AddConflictMember(conflict *Conflict[ConflictIDType, ResourceIDType]) (added bool)
- func (c *ConflictSet[ConflictIDType, ResourceIDType]) Conflicts() *advancedset.AdvancedSet[*Conflict[ConflictIDType, ResourceIDType]]
- func (c *ConflictSet[ConflictIDType, ResourceIDType]) ID() (id ResourceIDType)
- type Events
- type TestFramework
- func (t *TestFramework) AssertConfirmationState(expectedConfirmationState map[string]confirmation.State)
- func (t *TestFramework) AssertConflictParentsAndChildren(expectedParents map[string][]string)
- func (t *TestFramework) AssertConflictSetsAndConflicts(expectedConflictSetToConflictsAliases map[string][]string)
- func (t *TestFramework) ConfirmationState(conflictAliases ...string) confirmation.State
- func (t *TestFramework) ConflictID(alias string) (conflictID utxo.TransactionID)
- func (t *TestFramework) ConflictIDs(aliases ...string) (conflictIDs utxo.TransactionIDs)
- func (t *TestFramework) ConflictSetID(alias string) (conflictSetID utxo.OutputID)
- func (t *TestFramework) ConflictSetIDs(aliases ...string) (conflictSetIDs utxo.OutputIDs)
- func (t *TestFramework) CreateConflict(conflictAlias string, parentConflictIDs utxo.TransactionIDs, ...)
- func (t *TestFramework) DetermineVotes(conflictAliases ...string) (addedConflicts, revokedConflicts *advancedset.AdvancedSet[utxo.TransactionID], ...)
- func (t *TestFramework) RegisterConflictIDAlias(alias string, conflictID utxo.TransactionID)
- func (t *TestFramework) RegisterConflictSetIDAlias(alias string, conflictSetID utxo.OutputID)
- func (t *TestFramework) SetConflictAccepted(conflictAlias string)
- func (t *TestFramework) UnconfirmedConflicts(conflictAliases ...string) *advancedset.AdvancedSet[utxo.TransactionID]
- func (t *TestFramework) UpdateConflictParents(conflictAlias string, addedConflictAlias string, ...)
- func (t *TestFramework) UpdateConflictingResources(conflictAlias string, conflictingResourcesAliases ...string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeToMaster ¶
func MergeToMaster[ConflictIDType, ResourceIDType comparable](mergeToMaster bool) options.Option[ConflictDAG[ConflictIDType, ResourceIDType]]
Types ¶
type Conflict ¶
type Conflict[ConflictIDType, ResourceIDType comparable] struct { // contains filtered or unexported fields }
func NewConflict ¶
func NewConflict[ConflictIDType comparable, ResourceIDType comparable](id ConflictIDType, parents *advancedset.AdvancedSet[ConflictIDType], conflictSets *advancedset.AdvancedSet[*ConflictSet[ConflictIDType, ResourceIDType]], confirmationState confirmation.State) (c *Conflict[ConflictIDType, ResourceIDType])
func (*Conflict[ConflictIDType, ResourceIDType]) Children ¶
func (c *Conflict[ConflictIDType, ResourceIDType]) Children() (children *advancedset.AdvancedSet[*Conflict[ConflictIDType, ResourceIDType]])
func (*Conflict[ConflictIDType, ResourceIDType]) ConfirmationState ¶
func (c *Conflict[ConflictIDType, ResourceIDType]) ConfirmationState() (confirmationState confirmation.State)
ConfirmationState returns the ConfirmationState of the Conflict.
func (*Conflict[ConflictIDType, ResourceIDType]) ConflictSets ¶
func (c *Conflict[ConflictIDType, ResourceIDType]) ConflictSets() (conflictSets *advancedset.AdvancedSet[*ConflictSet[ConflictIDType, ResourceIDType]])
ConflictSets returns the identifiers of the conflict sets that this Conflict is part of.
func (*Conflict[ConflictIDType, ResourceIDType]) ForEachConflictingConflict ¶
func (*Conflict[ConflictIDType, ResourceIDType]) ID ¶
func (c *Conflict[ConflictIDType, ResourceIDType]) ID() ConflictIDType
func (*Conflict[ConflictIDType, ResourceIDType]) Parents ¶
func (c *Conflict[ConflictIDType, ResourceIDType]) Parents() (parents *advancedset.AdvancedSet[ConflictIDType])
Parents returns the parent ConflictIDs that this Conflict depends on.
type ConflictDAG ¶
type ConflictDAG[ConflictIDType, ResourceIDType comparable] struct { // Events contains the Events of the ConflictDAG. Events *Events[ConflictIDType, ResourceIDType] // WeightsMutex is a mutex that prevents updating conflict weights when creating references for a new block. // It is used by different components, but it is placed here because it's easily accessible in all needed components. // It serves more as a quick-fix, as eventually conflict tracking spread across multiple components // (ConflictDAG, ConflictResolver, ConflictsTracker) will be refactored into a single component that handles locking nicely. WeightsMutex syncutils.RWMutexFake // contains filtered or unexported fields }
ConflictDAG represents a generic DAG that is able to model causal dependencies between conflicts that try to access a shared set of resources.
func New ¶
func New[ConflictIDType, ResourceIDType comparable](opts ...options.Option[ConflictDAG[ConflictIDType, ResourceIDType]]) (c *ConflictDAG[ConflictIDType, ResourceIDType])
New is the constructor for the BlockDAG and creates a new BlockDAG instance.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) ConfirmationState ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ConfirmationState(conflictIDs *advancedset.AdvancedSet[ConflictIDType]) (confirmationState confirmation.State)
ConfirmationState returns the ConfirmationState of the given ConflictIDs.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) Conflict ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) Conflict(conflictID ConflictIDType) (conflict *Conflict[ConflictIDType, ResourceIDType], exists bool)
func (*ConflictDAG[ConflictIDType, ResourceIDType]) ConflictSet ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ConflictSet(resourceID ResourceIDType) (conflictSet *ConflictSet[ConflictIDType, ResourceIDType], exists bool)
func (*ConflictDAG[ConflictIDType, ResourceIDType]) CreateConflict ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) CreateConflict(id ConflictIDType, parentIDs *advancedset.AdvancedSet[ConflictIDType], conflictingResourceIDs *advancedset.AdvancedSet[ResourceIDType], confirmationState confirmation.State) (created bool)
CreateConflict creates a new Conflict in the ConflictDAG and returns true if the Conflict was created.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) DetermineVotes ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) DetermineVotes(conflictIDs *advancedset.AdvancedSet[ConflictIDType]) (addedConflicts, revokedConflicts *advancedset.AdvancedSet[ConflictIDType], isInvalid bool)
DetermineVotes iterates over a set of conflicts and, taking into account the opinion a Voter expressed previously, computes the conflicts that will receive additional weight, the ones that will see their weight revoked, and if the result constitutes an overall valid state transition.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) ForEachConflict ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ForEachConflict(consumer func(conflict *Conflict[ConflictIDType, ResourceIDType]))
ForEachConflict iterates over every existing Conflict in the entire Storage.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) ForEachConnectedConflictingConflictID ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) ForEachConnectedConflictingConflictID(rootConflict *Conflict[ConflictIDType, ResourceIDType], callback func(conflictingConflict *Conflict[ConflictIDType, ResourceIDType]))
ForEachConnectedConflictingConflictID executes the callback for each Conflict that is directly or indirectly connected to the named Conflict through a chain of intersecting conflicts.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) HandleOrphanedConflict ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) HandleOrphanedConflict(conflictID ConflictIDType)
func (*ConflictDAG[ConflictIDType, ResourceIDType]) SetConflictAccepted ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) SetConflictAccepted(conflictID ConflictIDType) (modified bool)
SetConflictAccepted sets the ConfirmationState of the given Conflict to be Accepted - it automatically sets also the conflicting conflicts to be rejected.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) UnconfirmedConflicts ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) UnconfirmedConflicts(conflictIDs *advancedset.AdvancedSet[ConflictIDType]) (pendingConflictIDs *advancedset.AdvancedSet[ConflictIDType])
UnconfirmedConflicts takes a set of ConflictIDs and removes all the Accepted/Confirmed Conflicts (leaving only the pending or rejected ones behind).
func (*ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictParents ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictParents(id ConflictIDType, removedConflictIDs *advancedset.AdvancedSet[ConflictIDType], addedConflictID ConflictIDType) (updated bool)
UpdateConflictParents changes the parents of a Conflict after a fork.
func (*ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictingResources ¶
func (c *ConflictDAG[ConflictIDType, ResourceIDType]) UpdateConflictingResources(id ConflictIDType, conflictingResourceIDs *advancedset.AdvancedSet[ResourceIDType]) (updated bool)
UpdateConflictingResources adds the Conflict to the given ConflictSets - it returns true if the conflict membership was modified during this operation.
type ConflictParentsUpdatedEvent ¶
type ConflictParentsUpdatedEvent[ConflictIDType, ResourceIDType comparable] struct { // ConflictIDType contains the identifier of the updated Conflict. ConflictID ConflictIDType // AddedConflict contains the forked parent Conflict that replaces the removed parents. AddedConflict ConflictIDType // RemovedConflicts contains the parent ConflictIDTypes that were replaced by the newly forked Conflict. RemovedConflicts *advancedset.AdvancedSet[ConflictIDType] // ParentsConflictIDs contains the updated list of parent ConflictIDTypes. ParentsConflictIDs *advancedset.AdvancedSet[ConflictIDType] }
ConflictParentsUpdatedEvent is a container that acts as a dictionary for the ConflictParentsUpdated event related parameters.
type ConflictSet ¶
type ConflictSet[ConflictIDType, ResourceIDType comparable] struct { // contains filtered or unexported fields }
func NewConflictSet ¶
func NewConflictSet[ConflictIDType comparable, ResourceIDType comparable](id ResourceIDType) (c *ConflictSet[ConflictIDType, ResourceIDType])
func (*ConflictSet[ConflictIDType, ResourceIDType]) AddConflictMember ¶
func (c *ConflictSet[ConflictIDType, ResourceIDType]) AddConflictMember(conflict *Conflict[ConflictIDType, ResourceIDType]) (added bool)
func (*ConflictSet[ConflictIDType, ResourceIDType]) Conflicts ¶
func (c *ConflictSet[ConflictIDType, ResourceIDType]) Conflicts() *advancedset.AdvancedSet[*Conflict[ConflictIDType, ResourceIDType]]
func (*ConflictSet[ConflictIDType, ResourceIDType]) ID ¶
func (c *ConflictSet[ConflictIDType, ResourceIDType]) ID() (id ResourceIDType)
type Events ¶
type Events[ConflictIDType, ResourceIDType comparable] struct { // ConflictCreated is an event that gets triggered whenever a new Conflict is created. ConflictCreated *event.Event1[*Conflict[ConflictIDType, ResourceIDType]] // ConflictUpdated is an event that gets triggered whenever the ConflictIDTypes of a Conflict are updated. ConflictUpdated *event.Event1[*Conflict[ConflictIDType, ResourceIDType]] // ConflictParentsUpdated is an event that gets triggered whenever the parent ConflictIDTypeTypes of a Conflict are updated. ConflictParentsUpdated *event.Event1[*ConflictParentsUpdatedEvent[ConflictIDType, ResourceIDType]] // ConflictAccepted is an event that gets triggered whenever a Conflict is confirmed. ConflictAccepted *event.Event1[*Conflict[ConflictIDType, ResourceIDType]] // ConflictRejected is an event that gets triggered whenever a Conflict is rejected. ConflictRejected *event.Event1[*Conflict[ConflictIDType, ResourceIDType]] // ConflictNotConflicting is an event that gets triggered whenever all conflicting conflits have been orphaned and rejected.. ConflictNotConflicting *event.Event1[*Conflict[ConflictIDType, ResourceIDType]] event.Group[Events[ConflictIDType, ResourceIDType], *Events[ConflictIDType, ResourceIDType]] }
Events is a container that acts as a dictionary for the events of a ConflictDAG.
func NewEvents ¶
func NewEvents[ConflictIDType, ResourceIDType comparable](optsLinkTarget ...*Events[ConflictIDType, ResourceIDType]) (events *Events[ConflictIDType, ResourceIDType])
NewEvents contains the constructor of the Events object (it is generated by a generic factory).
type TestFramework ¶
type TestFramework struct { Instance *ConflictDAG[utxo.TransactionID, utxo.OutputID] // contains filtered or unexported fields }
func NewDefaultTestFramework ¶
func NewDefaultTestFramework(t *testing.T, opts ...options.Option[ConflictDAG[utxo.TransactionID, utxo.OutputID]]) *TestFramework
func NewTestFramework ¶
func NewTestFramework(test *testing.T, conflictDAGInstance *ConflictDAG[utxo.TransactionID, utxo.OutputID]) *TestFramework
NewTestFramework is the constructor of the TestFramework.
func (*TestFramework) AssertConfirmationState ¶
func (t *TestFramework) AssertConfirmationState(expectedConfirmationState map[string]confirmation.State)
func (*TestFramework) AssertConflictParentsAndChildren ¶
func (t *TestFramework) AssertConflictParentsAndChildren(expectedParents map[string][]string)
AssertConflictParentsAndChildren asserts the structure of the conflict DAG as specified in expectedParents. "conflict3": {"conflict1","conflict2"} asserts that "conflict3" should have "conflict1" and "conflict2" as parents. It also verifies the reverse mapping, that there is a child reference from "conflict1"->"conflict3" and "conflict2"->"conflict3".
func (*TestFramework) AssertConflictSetsAndConflicts ¶
func (t *TestFramework) AssertConflictSetsAndConflicts(expectedConflictSetToConflictsAliases map[string][]string)
AssertConflictSetsAndConflicts asserts conflict membership from ConflictSetID -> Conflict but also the reverse mapping Conflict -> ConflictSetID. expectedConflictAliases should be specified as "conflictSetID1": {"conflict1", "conflict2"}.
func (*TestFramework) ConfirmationState ¶
func (t *TestFramework) ConfirmationState(conflictAliases ...string) confirmation.State
func (*TestFramework) ConflictID ¶
func (t *TestFramework) ConflictID(alias string) (conflictID utxo.TransactionID)
func (*TestFramework) ConflictIDs ¶
func (t *TestFramework) ConflictIDs(aliases ...string) (conflictIDs utxo.TransactionIDs)
func (*TestFramework) ConflictSetID ¶
func (t *TestFramework) ConflictSetID(alias string) (conflictSetID utxo.OutputID)
func (*TestFramework) ConflictSetIDs ¶
func (t *TestFramework) ConflictSetIDs(aliases ...string) (conflictSetIDs utxo.OutputIDs)
func (*TestFramework) CreateConflict ¶
func (t *TestFramework) CreateConflict(conflictAlias string, parentConflictIDs utxo.TransactionIDs, conflictSetAliases ...string)
func (*TestFramework) DetermineVotes ¶
func (t *TestFramework) DetermineVotes(conflictAliases ...string) (addedConflicts, revokedConflicts *advancedset.AdvancedSet[utxo.TransactionID], isInvalid bool)
func (*TestFramework) RegisterConflictIDAlias ¶
func (t *TestFramework) RegisterConflictIDAlias(alias string, conflictID utxo.TransactionID)
func (*TestFramework) RegisterConflictSetIDAlias ¶
func (t *TestFramework) RegisterConflictSetIDAlias(alias string, conflictSetID utxo.OutputID)
func (*TestFramework) SetConflictAccepted ¶
func (t *TestFramework) SetConflictAccepted(conflictAlias string)
func (*TestFramework) UnconfirmedConflicts ¶
func (t *TestFramework) UnconfirmedConflicts(conflictAliases ...string) *advancedset.AdvancedSet[utxo.TransactionID]
func (*TestFramework) UpdateConflictParents ¶
func (t *TestFramework) UpdateConflictParents(conflictAlias string, addedConflictAlias string, removedConflictAliases ...string)
func (*TestFramework) UpdateConflictingResources ¶
func (t *TestFramework) UpdateConflictingResources(conflictAlias string, conflictingResourcesAliases ...string)