sybilprotection

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0, BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type Weight struct {
	Value      int64      `serix:"0"`
	UpdateTime slot.Index `serix:"1"`
}

Weight is a weight annotated with the slot it was last updated in.

func NewWeight

func NewWeight(value int64, updateTime slot.Index) (newWeight *Weight)

NewWeight creates a new Weight instance.

func (Weight) Bytes

func (w Weight) Bytes() ([]byte, error)

Bytes returns a serialized version of the Weight.

func (*Weight) FromBytes

func (w *Weight) FromBytes(bytes []byte) (int, error)

FromBytes parses a serialized version of the Weight.

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) Add

func (w *WeightedSet) Add(id identity.ID) (added bool)

func (*WeightedSet) Delete

func (w *WeightedSet) Delete(id identity.ID) (removed bool)

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 (w *WeightedSet) ForEachWeighted(callback func(id identity.ID, weight int64) error) (err error)

func (*WeightedSet) Get

func (w *WeightedSet) Get(id identity.ID) (weight *Weight, exists bool)

func (*WeightedSet) Has

func (w *WeightedSet) Has(id identity.ID) (has bool)

func (*WeightedSet) Members

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

func NewWeights(store kvstore.KVStore) (newWeights *Weights)

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

func (w *Weights) ForEach(callback func(id identity.ID, weight *Weight) bool) (err error)

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

func (*Weights) Get

func (w *Weights) Get(id identity.ID) (weight *Weight, exists bool)

Get returns the weight of the given identity.

func (*Weights) Map

func (w *Weights) Map() (weights map[identity.ID]int64, err error)

Map returns the weights as a map.

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

func (w *Weights) TotalWeight() (totalWeight int64)

TotalWeight returns the total weight of all identities.

func (*Weights) TotalWeightWithoutZeroIdentity

func (w *Weights) TotalWeightWithoutZeroIdentity() int64

TotalWeightWithoutZeroIdentity returns the total weight of all identities minus the zero identity.

func (*Weights) Update

func (w *Weights) Update(id identity.ID, weightDiff *Weight)

Update updates the weight of the given identity.

func (*Weights) UpdateTotalWeightSlot

func (w *Weights) UpdateTotalWeightSlot(index slot.Index)

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) Get

func (w *WeightsBatch) Get(id identity.ID) (diff int64)

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.

func (*WeightsBatch) Update

func (w *WeightsBatch) Update(id identity.ID, diff int64)

Update updates the weight diff of the given identity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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