Documentation ¶
Index ¶
- Variables
- type Events
- type SybilProtection
- type Weight
- type WeightedSet
- func (w *WeightedSet) Add(id identity.ID) (added bool)
- func (w *WeightedSet) Delete(id identity.ID) (removed bool)
- func (w *WeightedSet) Detach()
- func (w *WeightedSet) ForEach(callback func(id identity.ID) error) (err error)
- func (w *WeightedSet) ForEachWeighted(callback func(id identity.ID, weight int64) error) (err error)
- func (w *WeightedSet) Get(id identity.ID) (weight *Weight, exists bool)
- func (w *WeightedSet) Has(id identity.ID) (has bool)
- func (w *WeightedSet) Members() *advancedset.AdvancedSet[identity.ID]
- func (w *WeightedSet) TotalWeight() (totalWeight int64)
- type Weights
- func (w *Weights) BatchUpdate(batch *WeightsBatch)
- func (w *Weights) ForEach(callback func(id identity.ID, weight *Weight) bool) (err error)
- func (w *Weights) Get(id identity.ID) (weight *Weight, exists bool)
- func (w *Weights) Map() (weights map[identity.ID]int64, err error)
- func (w *Weights) NewWeightedSet(members ...identity.ID) (newWeightedSet *WeightedSet)
- func (w *Weights) Root() (root types.Identifier)
- func (w *Weights) TotalWeight() (totalWeight int64)
- func (w *Weights) TotalWeightWithoutZeroIdentity() int64
- func (w *Weights) Update(id identity.ID, weightDiff *Weight)
- func (w *Weights) UpdateTotalWeightSlot(index slot.Index)
- type WeightsBatch
- func (w *WeightsBatch) ForEach(consumer func(id identity.ID, diff int64))
- func (w *WeightsBatch) Get(id identity.ID) (diff int64)
- func (w *WeightsBatch) TargetSlot() (targetSlot slot.Index)
- func (w *WeightsBatch) TotalDiff() (totalDiff int64)
- func (w *WeightsBatch) Update(id identity.ID, diff int64)
Constants ¶
This section is empty.
Variables ¶
var NewEvents = event.CreateGroupConstructor(func() (newEvents *Events) { return &Events{ WeightsUpdated: event.New1[*WeightsBatch](), } })
NewEvents contains the constructor of the Events object (it is generated by a generic factory).
Functions ¶
This section is empty.
Types ¶
type Events ¶
type Events struct { // WeightUpdated is triggered when a weight of a node is updated. WeightsUpdated *event.Event1[*WeightsBatch] // LinkableCollection is a generic trait that allows to link multiple collections of events together. event.Group[Events, *Events] }
Events is a collection of events that can be triggered by the SybilProtection.
type SybilProtection ¶
type SybilProtection interface { // Weights returns the weights of identities in the SybilProtection. Weights() (weights *Weights) // Validators returns the set of online validators that is used to track acceptance. Validators() (validators *WeightedSet) // Committable is a trait that stores information about the latest commitment. traits.Committable // Interface embeds the required methods of the module.Interface. module.Interface }
SybilProtection is the minimal interface for the SybilProtection component of the ZIPP protocol.
type Weight ¶
Weight is a weight annotated with the slot it was last updated in.
type WeightedSet ¶
type WeightedSet struct { Weights *Weights // contains filtered or unexported fields }
func NewWeightedSet ¶
func NewWeightedSet(weights *Weights, optMembers ...identity.ID) (newWeightedSet *WeightedSet)
func (*WeightedSet) Detach ¶
func (w *WeightedSet) Detach()
func (*WeightedSet) ForEach ¶
func (w *WeightedSet) ForEach(callback func(id identity.ID) error) (err error)
func (*WeightedSet) ForEachWeighted ¶
func (*WeightedSet) Members ¶
func (w *WeightedSet) Members() *advancedset.AdvancedSet[identity.ID]
func (*WeightedSet) TotalWeight ¶
func (w *WeightedSet) TotalWeight() (totalWeight int64)
type Weights ¶
type Weights struct { // Events is a collection of events related to the Weights. Events *Events // contains filtered or unexported fields }
Weights is a mapping between a collection of identities and their weights.
func NewWeights ¶
NewWeights creates a new Weights instance.
func (*Weights) BatchUpdate ¶
func (w *Weights) BatchUpdate(batch *WeightsBatch)
BatchUpdate updates the weights of multiple identities at once.
func (*Weights) ForEach ¶
ForEach iterates over all weights and calls the given callback for each of them.
func (*Weights) NewWeightedSet ¶
func (w *Weights) NewWeightedSet(members ...identity.ID) (newWeightedSet *WeightedSet)
NewWeightedSet creates a new WeightedSet instance, that maintains a correct and updated total weight of its members.
func (*Weights) Root ¶
func (w *Weights) Root() (root types.Identifier)
Root returns the root of the merkle tree of the stored weights.
func (*Weights) TotalWeight ¶
TotalWeight returns the total weight of all identities.
func (*Weights) TotalWeightWithoutZeroIdentity ¶
TotalWeightWithoutZeroIdentity returns the total weight of all identities minus the zero identity.
func (*Weights) UpdateTotalWeightSlot ¶
type WeightsBatch ¶
type WeightsBatch struct {
// contains filtered or unexported fields
}
WeightsBatch is a batch of weight diffs that can be applied to a Weights instance.
func NewWeightsBatch ¶
func NewWeightsBatch(targetSlot slot.Index) (newWeightDiffs *WeightsBatch)
NewWeightsBatch creates a new WeightsBatch instance.
func (*WeightsBatch) ForEach ¶
func (w *WeightsBatch) ForEach(consumer func(id identity.ID, diff int64))
ForEach iterates over all weight diffs in the batch.
func (*WeightsBatch) TargetSlot ¶
func (w *WeightsBatch) TargetSlot() (targetSlot slot.Index)
TargetSlot returns the slot that the batch is targeting.
func (*WeightsBatch) TotalDiff ¶
func (w *WeightsBatch) TotalDiff() (totalDiff int64)
TotalDiff returns the total weight diff of the batch.