Documentation
¶
Index ¶
- Constants
- Variables
- func IDFromPubKey(pubKey string) (iID identity.ID, err error)
- func IDFromStr(idStr string) (iID identity.ID, err error)
- func SetCoefficients(ema1 float64, ema2 float64, dec float64)
- type AccessBaseMana
- type AccessBaseManaVector
- func (a *AccessBaseManaVector) Book(txInfo *TxInfo)
- func (a *AccessBaseManaVector) ForEach(callback func(ID identity.ID, bm BaseMana) bool)
- func (a *AccessBaseManaVector) FromPersistable(p *PersistableBaseMana) (err error)
- func (a *AccessBaseManaVector) GetHighestManaNodes(n uint) (res []Node, t time.Time, err error)
- func (a *AccessBaseManaVector) GetHighestManaNodesFraction(p float64) (res []Node, t time.Time, err error)
- func (a *AccessBaseManaVector) GetMana(nodeID identity.ID, optionalUpdateTime ...time.Time) (float64, time.Time, error)
- func (a *AccessBaseManaVector) GetManaMap(optionalUpdateTime ...time.Time) (res NodeMap, t time.Time, err error)
- func (a *AccessBaseManaVector) Has(nodeID identity.ID) bool
- func (a *AccessBaseManaVector) LoadSnapshot(snapshot map[identity.ID]*SnapshotNode)
- func (a *AccessBaseManaVector) RemoveZeroNodes()
- func (a *AccessBaseManaVector) SetMana(nodeID identity.ID, bm BaseMana)
- func (a *AccessBaseManaVector) Size() int
- func (a *AccessBaseManaVector) ToPersistables() []*PersistableBaseMana
- func (a *AccessBaseManaVector) Type() Type
- func (a *AccessBaseManaVector) Update(nodeID identity.ID, t time.Time) error
- func (a *AccessBaseManaVector) UpdateAll(t time.Time) error
- func (a *AccessBaseManaVector) Vector() map[identity.ID]*AccessBaseMana
- type AccessManaRecord
- type AccessManaSnapshot
- type BaseMana
- type BaseManaJSON
- type BaseManaVector
- type ConsensusBaseMana
- type ConsensusBaseManaVector
- func (c *ConsensusBaseManaVector) Book(txInfo *TxInfo)
- func (c *ConsensusBaseManaVector) ForEach(callback func(ID identity.ID, bm BaseMana) bool)
- func (c *ConsensusBaseManaVector) FromPersistable(p *PersistableBaseMana) (err error)
- func (c *ConsensusBaseManaVector) GetHighestManaNodes(n uint) (res []Node, t time.Time, err error)
- func (c *ConsensusBaseManaVector) GetHighestManaNodesFraction(p float64) (res []Node, t time.Time, err error)
- func (c *ConsensusBaseManaVector) GetMana(nodeID identity.ID, optionalUpdateTime ...time.Time) (float64, time.Time, error)
- func (c *ConsensusBaseManaVector) GetManaMap(optionalUpdateTime ...time.Time) (res NodeMap, t time.Time, err error)
- func (c *ConsensusBaseManaVector) Has(nodeID identity.ID) bool
- func (c *ConsensusBaseManaVector) LoadSnapshot(snapshot map[identity.ID]*SnapshotNode)
- func (c *ConsensusBaseManaVector) RemoveZeroNodes()
- func (c *ConsensusBaseManaVector) SetMana(nodeID identity.ID, bm BaseMana)
- func (c *ConsensusBaseManaVector) Size() int
- func (c *ConsensusBaseManaVector) ToPersistables() []*PersistableBaseMana
- func (c *ConsensusBaseManaVector) Type() Type
- func (c *ConsensusBaseManaVector) Update(nodeID identity.ID, t time.Time) error
- func (c *ConsensusBaseManaVector) UpdateAll(t time.Time) error
- func (c *ConsensusBaseManaVector) Vector() map[identity.ID]*ConsensusBaseMana
- type ConsensusBasePastManaVectorMetadata
- func (c *ConsensusBasePastManaVectorMetadata) Bytes() []byte
- func (c *ConsensusBasePastManaVectorMetadata) FromBytes(data []byte) (result *ConsensusBasePastManaVectorMetadata, err error)
- func (c *ConsensusBasePastManaVectorMetadata) FromObjectStorage(_, value []byte) error
- func (c *ConsensusBasePastManaVectorMetadata) ObjectStorageKey() []byte
- func (c *ConsensusBasePastManaVectorMetadata) ObjectStorageValue() []byte
- type Event
- type EventSlice
- type InputInfo
- type ManaEvents
- type ManaRetrievalFunc
- type Node
- type NodeMap
- type NodeMapStr
- type NodeStr
- type PersistableBaseMana
- type PersistableEvent
- func (p *PersistableEvent) Bytes() []byte
- func (p *PersistableEvent) FromBytes(data []byte) (result *PersistableEvent, err error)
- func (p *PersistableEvent) FromObjectStorage(_, value []byte) error
- func (p *PersistableEvent) ObjectStorageKey() []byte
- func (p *PersistableEvent) ObjectStorageValue() []byte
- func (p *PersistableEvent) ToStringKeys() []string
- func (p *PersistableEvent) ToStringValues() []string
- type PledgedEvent
- type PledgedEventJSON
- type RevokedEvent
- type RevokedEventJSON
- type Snapshot
- func (s *Snapshot) Bytes() (serialized []byte)
- func (s *Snapshot) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
- func (s *Snapshot) MaxAccessManaUpdateTime() (maxTime time.Time)
- func (s *Snapshot) NodeSnapshot(nodeID identity.ID) (nodeSnapshot *SnapshotNode)
- func (s *Snapshot) ResetTime()
- func (s *Snapshot) String() (humanReadable string)
- type SnapshotNode
- func (s *SnapshotNode) AccessManaUpdateTime() (maxTime time.Time)
- func (s *SnapshotNode) AdjustAccessManaUpdateTime(diff time.Duration)
- func (s *SnapshotNode) Bytes() (serialized []byte)
- func (s *SnapshotNode) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
- func (s *SnapshotNode) String() (humanReadable string)
- type SortedTxSnapshot
- func (s SortedTxSnapshot) Bytes() (serialized []byte)
- func (s *SortedTxSnapshot) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
- func (s SortedTxSnapshot) Len() int
- func (s SortedTxSnapshot) Less(i, j int) bool
- func (s SortedTxSnapshot) String() (humanReadable string)
- func (s SortedTxSnapshot) Swap(i, j int)
- type TxInfo
- type TxSnapshot
- type Type
- type UpdatedEvent
- type UpdatedEventJSON
Constants ¶
const ( // EventTypePledge defines the type of a pledge event. EventTypePledge byte = iota // EventTypeRevoke defines the event type of a revoke event. EventTypeRevoke // EventTypeUpdate defines the event type of an updated event. EventTypeUpdate )
const ( // PrefixAccess is the storage prefix for access mana storage. PrefixAccess byte = iota // PrefixConsensus is the storage prefix for consensus mana storage. PrefixConsensus // PrefixAccessResearch is the storage prefix for research access mana storage. PrefixAccessResearch // PrefixConsensusResearch is the storage prefix for research consensus mana storage. PrefixConsensusResearch // PrefixEventStorage is the storage prefix for consensus mana event storage. PrefixEventStorage // PrefixConsensusPastVector is the storage prefix for consensus mana past vector storage. PrefixConsensusPastVector // PrefixConsensusPastMetadata is the storage prefix for consensus mana past vector metadata storage. PrefixConsensusPastMetadata )
const ( // OnlyMana1 takes only EBM1 into account when getting the mana values. OnlyMana1 float64 = 1.0 // OnlyMana2 takes only EBM2 into account when getting the mana values. OnlyMana2 float64 = 0.0 // Mixed takes both EBM1 and EBM2 into account (50-50) when getting the mana values. Mixed float64 = 0.5 // DeltaStopUpdate stops the update of the effective mana value if it is in the delta interval of the the base mana // value. Base mana can only be an integer, and effective mana tends to this integer value over time if there are no // pledges or revokes. // It is used primarily for consensus mana, since for access mana, base mana changes wrt to time. The updates for // access mana stop when the base mana value AND the effective value is in DeltaStopUpdates interval of 0. DeltaStopUpdate float64 = 0.001 // MinEffectiveMana defines the threshold to consider an effective mana value zero. MinEffectiveMana = 0.001 // MinBaseMana defines the threshold to consider the base mana value zero. MinBaseMana = 0.001 )
const (
// ConsensusBaseManaPastVectorMetadataStorageKey is the key to the consensus base vector metadata storage.
ConsensusBaseManaPastVectorMetadataStorageKey = "consensusBaseManaVectorMetadata"
)
Variables ¶
var ( // ErrAlreadyUpdated is returned if mana is tried to be updated at a later time. ErrAlreadyUpdated = errors.New("already updated to a later timestamp") // ErrBaseManaNegative is returned if base mana will become negative. ErrBaseManaNegative = errors.New("base mana should never be negative") // ErrEffBaseManaNegative is returned if base mana will become negative. ErrEffBaseManaNegative = errors.New("effective base mana should never be negative") // ErrUnknownManaType is returned if mana type could not be identified. ErrUnknownManaType = errors.New("unknown mana type") // ErrNodeNotFoundInBaseManaVector is returned if the node is not found in the base mana vector. ErrNodeNotFoundInBaseManaVector = errors.New("node not present in base mana vector") // ErrInvalidWeightParameter is returned if an invalid weight parameter is passed. ErrInvalidWeightParameter = errors.New("invalid weight parameter, outside of [0,1]") // ErrInvalidTargetManaType is returned if a research base mana vector can't handle the target mana type. ErrInvalidTargetManaType = errors.New("invalid target mana type") // ErrUnknownManaEvent is returned if mana event type could not be identified. ErrUnknownManaEvent = errors.New("unknown mana event") )
var (
// Decay is the mana decay (gamma) (used in access mana), in 1/sec.
Decay = 0.00003209
)
Functions ¶
func IDFromPubKey ¶
IDFromPubKey returns the ID from the given public key.
func SetCoefficients ¶
SetCoefficients sets the coefficients for mana calculation.
Types ¶
type AccessBaseMana ¶
type AccessBaseMana struct {
model.Mutable[AccessBaseMana, *AccessBaseMana, accessBaseManaModel] `serix:"0"`
}
AccessBaseMana holds information about the access base mana values of a single node.
func NewAccessBaseMana ¶ added in v0.9.0
func NewAccessBaseMana(baseMana, effectiveBaseMana float64, lastUpdated time.Time) (newAccessBaseMana *AccessBaseMana)
NewAccessBaseMana returns new base access mana vector.
func (*AccessBaseMana) BaseValue ¶
func (a *AccessBaseMana) BaseValue() float64
BaseValue returns base mana value.
func (*AccessBaseMana) EffectiveValue ¶
func (a *AccessBaseMana) EffectiveValue() float64
EffectiveValue returns effective base mana value.
func (*AccessBaseMana) LastUpdate ¶
func (a *AccessBaseMana) LastUpdate() time.Time
LastUpdate returns last update time.
type AccessBaseManaVector ¶
type AccessBaseManaVector struct {
model.Mutable[AccessBaseManaVector, *AccessBaseManaVector, accessBaseManaVectorModel] `serix:"0"`
}
AccessBaseManaVector represents a base mana vector.
func (*AccessBaseManaVector) Book ¶
func (a *AccessBaseManaVector) Book(txInfo *TxInfo)
Book books mana for a transaction.
func (*AccessBaseManaVector) ForEach ¶
func (a *AccessBaseManaVector) ForEach(callback func(ID identity.ID, bm BaseMana) bool)
ForEach iterates over the vector and calls the provided callback.
func (*AccessBaseManaVector) FromPersistable ¶
func (a *AccessBaseManaVector) FromPersistable(p *PersistableBaseMana) (err error)
FromPersistable fills the AccessBaseManaVector from persistable mana objects.
func (*AccessBaseManaVector) GetHighestManaNodes ¶
GetHighestManaNodes returns the n highest mana nodes in descending order. It also updates the mana values for each node. If n is zero, it returns all nodes.
func (*AccessBaseManaVector) GetHighestManaNodesFraction ¶ added in v0.5.5
func (a *AccessBaseManaVector) GetHighestManaNodesFraction(p float64) (res []Node, t time.Time, err error)
GetHighestManaNodesFraction returns the highest mana that own 'p' percent of total mana. It also updates the mana values for each node. If p is zero or greater than one, it returns all nodes.
func (*AccessBaseManaVector) GetMana ¶
func (a *AccessBaseManaVector) GetMana(nodeID identity.ID, optionalUpdateTime ...time.Time) (float64, time.Time, error)
GetMana returns Effective Base Mana 2.
func (*AccessBaseManaVector) GetManaMap ¶
func (a *AccessBaseManaVector) GetManaMap(optionalUpdateTime ...time.Time) (res NodeMap, t time.Time, err error)
GetManaMap returns mana perception of the node..
func (*AccessBaseManaVector) Has ¶
func (a *AccessBaseManaVector) Has(nodeID identity.ID) bool
Has returns if the given node has mana defined in the vector.
func (*AccessBaseManaVector) LoadSnapshot ¶ added in v0.5.7
func (a *AccessBaseManaVector) LoadSnapshot(snapshot map[identity.ID]*SnapshotNode)
LoadSnapshot loads the initial mana state into the base mana vector.
func (*AccessBaseManaVector) RemoveZeroNodes ¶
func (a *AccessBaseManaVector) RemoveZeroNodes()
RemoveZeroNodes removes the zero mana nodes from the vector.
func (*AccessBaseManaVector) SetMana ¶
func (a *AccessBaseManaVector) SetMana(nodeID identity.ID, bm BaseMana)
SetMana sets the base mana for a node.
func (*AccessBaseManaVector) Size ¶
func (a *AccessBaseManaVector) Size() int
Size returns the size of this mana vector.
func (*AccessBaseManaVector) ToPersistables ¶
func (a *AccessBaseManaVector) ToPersistables() []*PersistableBaseMana
ToPersistables converts the AccessBaseManaVector to a list of persistable mana objects.
func (*AccessBaseManaVector) Type ¶
func (a *AccessBaseManaVector) Type() Type
Type returns the type of this mana vector.
func (*AccessBaseManaVector) Update ¶
Update updates the mana entries for a particular node wrt time.
func (*AccessBaseManaVector) UpdateAll ¶
func (a *AccessBaseManaVector) UpdateAll(t time.Time) error
UpdateAll updates all entries in the base mana vector wrt to `t`.
func (*AccessBaseManaVector) Vector ¶ added in v0.9.0
func (a *AccessBaseManaVector) Vector() map[identity.ID]*AccessBaseMana
Vector returns the AccessBaseMana vector.
type AccessManaRecord ¶ added in v0.9.0
AccessManaRecord defines the info for the aMana snapshot.
type AccessManaSnapshot ¶ added in v0.6.2
AccessManaSnapshot defines the record for the aMana snapshot of one node.
func (*AccessManaSnapshot) Bytes ¶ added in v0.9.0
func (a *AccessManaSnapshot) Bytes() (serialized []byte)
Bytes returns a serialized version of the AccessManaSnapshot.
func (*AccessManaSnapshot) FromMarshalUtil ¶ added in v0.9.0
func (a *AccessManaSnapshot) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
FromMarshalUtil reads the AccessManaSnapshot from a MarshalUtil.
func (AccessManaSnapshot) String ¶ added in v0.9.0
func (a AccessManaSnapshot) String() (humanReadable string)
String returns a human-readable version of the AccessManaSnapshot.
type BaseMana ¶
type BaseMana interface {
BaseValue() float64
EffectiveValue() float64
LastUpdate() time.Time
// contains filtered or unexported methods
}
BaseMana is an interface for a collection of base mana values of a single node.
type BaseManaJSON ¶
type BaseManaJSON struct {
BaseMana float64 `json:"baseMana"`
EffectiveBaseMana float64 `json:"effectiveBaseMana"`
LastUpdated int64 `json:"lastUpdated"`
}
BaseManaJSON is a JSON serializable form of a BaseMana.
type BaseManaVector ¶
type BaseManaVector interface {
// Type returns the type of the base mana vector (access/consensus).
Type() Type
// Size returns the size of the base mana vector.
Size() int
// Has tells if a certain node is present in the base mana vactor.
Has(identity.ID) bool
// LoadSnapshot loads the initial mana state into the base mana vector.
LoadSnapshot(map[identity.ID]*SnapshotNode)
// Book books mana into the base mana vector.
Book(*TxInfo)
// Update updates the mana entries for a particular node wrt time.
Update(identity.ID, time.Time) error
// UpdateAll updates all entries in the base mana vector wrt to time.
UpdateAll(time.Time) error
// GetMana returns the mana value of a node with default weights.
GetMana(identity.ID, ...time.Time) (float64, time.Time, error)
// GetManaMap returns the map derived from the vector.
GetManaMap(...time.Time) (NodeMap, time.Time, error)
// GetHighestManaNodes returns the n highest mana nodes in descending order.
GetHighestManaNodes(uint) ([]Node, time.Time, error)
// GetHighestManaNodesFraction returns the highest mana that own 'p' percent of total mana.
GetHighestManaNodesFraction(p float64) ([]Node, time.Time, error)
// SetMana sets the base mana for a node.
SetMana(identity.ID, BaseMana)
// ForEach executes a callback function for each entry in the vector.
ForEach(func(identity.ID, BaseMana) bool)
// ToPersistables converts the BaseManaVector to a list of persistable mana objects.
ToPersistables() []*PersistableBaseMana
// FromPersistable fills the BaseManaVector from persistable mana objects.
FromPersistable(*PersistableBaseMana) error
// RemoveZeroNodes removes all zero mana nodes from the mana vector.
RemoveZeroNodes()
}
BaseManaVector is an interface for vectors that store base mana values of nodes in the network.
func NewBaseManaVector ¶
func NewBaseManaVector(vectorType Type) (BaseManaVector, error)
NewBaseManaVector creates and returns a new base mana vector for the specified type.
type ConsensusBaseMana ¶
type ConsensusBaseMana struct {
model.Mutable[ConsensusBaseMana, *ConsensusBaseMana, consensusBaseManaModel] `serix:"0"`
}
ConsensusBaseMana holds information about the consensus base mana values of a single node.
func NewConsensusBaseMana ¶ added in v0.9.0
func NewConsensusBaseMana(baseMana float64) *ConsensusBaseMana
func (*ConsensusBaseMana) BaseValue ¶
func (c *ConsensusBaseMana) BaseValue() float64
BaseValue returns the base mana value (BM1).
func (*ConsensusBaseMana) EffectiveValue ¶
func (c *ConsensusBaseMana) EffectiveValue() float64
EffectiveValue returns the effective base mana value (EBM1).
func (*ConsensusBaseMana) LastUpdate ¶
func (c *ConsensusBaseMana) LastUpdate() time.Time
LastUpdate returns the last update time.
type ConsensusBaseManaVector ¶
type ConsensusBaseManaVector struct {
model.Mutable[ConsensusBaseManaVector, *ConsensusBaseManaVector, consensusBaseManaVectorModel] `serix:"0"`
}
ConsensusBaseManaVector represents a base mana vector.
func (*ConsensusBaseManaVector) Book ¶
func (c *ConsensusBaseManaVector) Book(txInfo *TxInfo)
Book books mana for a transaction.
func (*ConsensusBaseManaVector) ForEach ¶
func (c *ConsensusBaseManaVector) ForEach(callback func(ID identity.ID, bm BaseMana) bool)
ForEach iterates over the vector and calls the provided callback.
func (*ConsensusBaseManaVector) FromPersistable ¶
func (c *ConsensusBaseManaVector) FromPersistable(p *PersistableBaseMana) (err error)
FromPersistable fills the ConsensusBaseManaVector from persistable mana objects.
func (*ConsensusBaseManaVector) GetHighestManaNodes ¶
GetHighestManaNodes return the n highest mana nodes in descending order. It also updates the mana values for each node. If n is zero, it returns all nodes.
func (*ConsensusBaseManaVector) GetHighestManaNodesFraction ¶ added in v0.5.5
func (c *ConsensusBaseManaVector) GetHighestManaNodesFraction(p float64) (res []Node, t time.Time, err error)
GetHighestManaNodesFraction returns the highest mana that own 'p' percent of total mana. It also updates the mana values for each node. If p is zero or greater than one, it returns all nodes.
func (*ConsensusBaseManaVector) GetMana ¶
func (c *ConsensusBaseManaVector) GetMana(nodeID identity.ID, optionalUpdateTime ...time.Time) (float64, time.Time, error)
GetMana returns the Effective Base Mana.
func (*ConsensusBaseManaVector) GetManaMap ¶
func (c *ConsensusBaseManaVector) GetManaMap(optionalUpdateTime ...time.Time) (res NodeMap, t time.Time, err error)
GetManaMap returns mana perception of the node.
func (*ConsensusBaseManaVector) Has ¶
func (c *ConsensusBaseManaVector) Has(nodeID identity.ID) bool
Has returns if the given node has mana defined in the vector.
func (*ConsensusBaseManaVector) LoadSnapshot ¶ added in v0.5.7
func (c *ConsensusBaseManaVector) LoadSnapshot(snapshot map[identity.ID]*SnapshotNode)
LoadSnapshot loads the snapshot.
func (*ConsensusBaseManaVector) RemoveZeroNodes ¶
func (c *ConsensusBaseManaVector) RemoveZeroNodes()
RemoveZeroNodes removes the zero mana nodes from the vector.
func (*ConsensusBaseManaVector) SetMana ¶
func (c *ConsensusBaseManaVector) SetMana(nodeID identity.ID, bm BaseMana)
SetMana sets the base mana for a node.
func (*ConsensusBaseManaVector) Size ¶
func (c *ConsensusBaseManaVector) Size() int
Size returns the size of this mana vector.
func (*ConsensusBaseManaVector) ToPersistables ¶
func (c *ConsensusBaseManaVector) ToPersistables() []*PersistableBaseMana
ToPersistables converts the baseManaVector to a list of persistable mana objects.
func (*ConsensusBaseManaVector) Type ¶
func (c *ConsensusBaseManaVector) Type() Type
Type returns the type of this mana vector.
func (*ConsensusBaseManaVector) Update ¶
Update updates the mana entries for a particular node wrt time.
func (*ConsensusBaseManaVector) UpdateAll ¶
func (c *ConsensusBaseManaVector) UpdateAll(t time.Time) error
UpdateAll updates all entries in the base mana vector wrt to `t`.
func (*ConsensusBaseManaVector) Vector ¶ added in v0.9.0
func (c *ConsensusBaseManaVector) Vector() map[identity.ID]*ConsensusBaseMana
Vector returns the ConsensusBaseMana vector.
type ConsensusBasePastManaVectorMetadata ¶
type ConsensusBasePastManaVectorMetadata struct {
objectstorage.StorableObjectFlags
Timestamp time.Time `serix:"0" json:"timestamp"`
// contains filtered or unexported fields
}
ConsensusBasePastManaVectorMetadata holds metadata for the past consensus mana vector.
func (*ConsensusBasePastManaVectorMetadata) Bytes ¶
func (c *ConsensusBasePastManaVectorMetadata) Bytes() []byte
Bytes marshals the consensus base past mana vector metadata into a sequence of bytes.
func (*ConsensusBasePastManaVectorMetadata) FromBytes ¶ added in v0.8.10
func (c *ConsensusBasePastManaVectorMetadata) FromBytes(data []byte) (result *ConsensusBasePastManaVectorMetadata, err error)
FromBytes unmarshalls bytes into a metadata.
func (*ConsensusBasePastManaVectorMetadata) FromObjectStorage ¶ added in v0.8.10
func (c *ConsensusBasePastManaVectorMetadata) FromObjectStorage(_, value []byte) error
FromObjectStorage creates an ConsensusBasePastManaVectorMetadata from sequences of key and bytes.
func (*ConsensusBasePastManaVectorMetadata) ObjectStorageKey ¶
func (c *ConsensusBasePastManaVectorMetadata) ObjectStorageKey() []byte
ObjectStorageKey returns the key of the metadata.
func (*ConsensusBasePastManaVectorMetadata) ObjectStorageValue ¶
func (c *ConsensusBasePastManaVectorMetadata) ObjectStorageValue() []byte
ObjectStorageValue returns the bytes of the metadata.
type Event ¶
type Event interface {
// Type returns the type of the event.
Type() byte
// ToJSONSerializable returns a struct that can be serialized into JSON object.
ToJSONSerializable() interface{}
// ToPersistable returns an event that can be persisted.
ToPersistable() *PersistableEvent
// Timestamp returns the time of the event.
Timestamp() time.Time
// String returns a human readable version of the event.
String() string
}
Event is the interface definition of an event.
func FromPersistableEvent ¶
func FromPersistableEvent(p *PersistableEvent) (Event, error)
FromPersistableEvent parses a persistable event to a regular event.
type EventSlice ¶
type EventSlice []Event
EventSlice is a slice of events.
func (EventSlice) Sort ¶
func (e EventSlice) Sort()
Sort sorts a slice of events ASC by their timestamp with preference for RevokedEvent.
type InputInfo ¶
type InputInfo struct {
// Timestamp is the timestamp of the transaction that created this output (input).
TimeStamp time.Time
// Amount is the balance of the input.
Amount float64
// PledgeID is a map of mana types and the node to which the transaction that created the output pledges its mana type to.
PledgeID map[Type]identity.ID
// InputID is the input consumed.
InputID utxo.OutputID
}
InputInfo holds mana related info about an input within a transaction.
type ManaEvents ¶ added in v0.9.0
type ManaEvents struct {
// Fired when mana was pledged to a node.
Pledged *event.Event[*PledgedEvent]
// Fired when mana was revoked from a node.
Revoked *event.Event[*RevokedEvent]
// Fired when mana of a node was updated.
Updated *event.Event[*UpdatedEvent]
}
ManaEvents represents events happening in the mana package.
var Events *ManaEvents
type ManaRetrievalFunc ¶ added in v0.7.6
ManaRetrievalFunc returns the mana value of a node with default weights.
type NodeMap ¶
NodeMap is a map of nodeID and mana value.
func (NodeMap) GetPercentile ¶
GetPercentile returns the top percentile the node belongs to relative to the network in terms of mana.
func (NodeMap) ToNodeStrList ¶
ToNodeStrList converts a NodeMap to list of NodeStr.
type NodeStr ¶
type NodeStr struct {
ShortNodeID string `json:"shortNodeID"`
NodeID string `json:"nodeID"`
Mana float64 `json:"mana"`
}
NodeStr defines a node and its mana value. The node ID is stringified.
type PersistableBaseMana ¶
type PersistableBaseMana struct {
model.Storable[identity.ID, PersistableBaseMana, *PersistableBaseMana, persistableBaseManaModel] `serix:"0"`
}
PersistableBaseMana represents a base mana vector that can be persisted.
func NewPersistableBaseMana ¶ added in v0.9.0
func (*PersistableBaseMana) BaseValues ¶
func (v *PersistableBaseMana) BaseValues() []float64
func (*PersistableBaseMana) EffectiveValues ¶
func (v *PersistableBaseMana) EffectiveValues() []float64
func (*PersistableBaseMana) LastUpdated ¶
func (v *PersistableBaseMana) LastUpdated() time.Time
func (*PersistableBaseMana) ManaType ¶
func (v *PersistableBaseMana) ManaType() Type
func (*PersistableBaseMana) NodeID ¶
func (v *PersistableBaseMana) NodeID() identity.ID
type PersistableEvent ¶
type PersistableEvent struct {
objectstorage.StorableObjectFlags
Type byte `serix:"0"` // pledge or revoke
ManaType Type `serix:"1"` // access or consensus
NodeID identity.ID `serix:"2"`
Time time.Time `serix:"3"`
TransactionID utxo.TransactionID `serix:"4"`
Amount float64 `serix:"5"`
InputID utxo.OutputID `serix:"6"` // for revoke event
// contains filtered or unexported fields
}
PersistableEvent is a persistable event.
func (*PersistableEvent) Bytes ¶
func (p *PersistableEvent) Bytes() []byte
Bytes marshals the persistable event into a sequence of bytes.
func (*PersistableEvent) FromBytes ¶ added in v0.8.10
func (p *PersistableEvent) FromBytes(data []byte) (result *PersistableEvent, err error)
FromBytes unmarshalls bytes into a persistable event.
func (*PersistableEvent) FromObjectStorage ¶ added in v0.8.10
func (p *PersistableEvent) FromObjectStorage(_, value []byte) error
FromObjectStorage creates an PersistableEvent from sequences of key and bytes.
func (*PersistableEvent) ObjectStorageKey ¶
func (p *PersistableEvent) ObjectStorageKey() []byte
ObjectStorageKey returns the key of the persistable mana.
func (*PersistableEvent) ObjectStorageValue ¶
func (p *PersistableEvent) ObjectStorageValue() []byte
ObjectStorageValue returns the bytes of the event.
func (*PersistableEvent) ToStringKeys ¶
func (p *PersistableEvent) ToStringKeys() []string
ToStringKeys returns the keys (properties) of the persistable event as a list of strings.
func (*PersistableEvent) ToStringValues ¶
func (p *PersistableEvent) ToStringValues() []string
ToStringValues returns the persistableEvents values as a string array.
type PledgedEvent ¶
type PledgedEvent struct {
NodeID identity.ID
Amount float64
Time time.Time
ManaType Type // access or consensus
TransactionID utxo.TransactionID
}
PledgedEvent is the struct that is passed along with triggering a Pledged event.
func (*PledgedEvent) String ¶ added in v0.5.7
func (p *PledgedEvent) String() string
String returns a human readable version of the event.
func (*PledgedEvent) Timestamp ¶
func (p *PledgedEvent) Timestamp() time.Time
Timestamp returns time the event was fired.
func (*PledgedEvent) ToJSONSerializable ¶
func (p *PledgedEvent) ToJSONSerializable() interface{}
ToJSONSerializable returns a struct that can be serialized into JSON object.
func (*PledgedEvent) ToPersistable ¶
func (p *PledgedEvent) ToPersistable() *PersistableEvent
ToPersistable returns an event that can be persisted.
type PledgedEventJSON ¶
type PledgedEventJSON struct {
ManaType string `json:"manaType"`
NodeID string `json:"nodeID"`
Time int64 `json:"time"`
TxID string `json:"txID"`
Amount float64 `json:"amount"`
}
PledgedEventJSON is a JSON serializable form of a PledgedEvent.
type RevokedEvent ¶
type RevokedEvent struct {
NodeID identity.ID
Amount float64
Time time.Time
ManaType Type // shall only be consensus for now
TransactionID utxo.TransactionID
InputID utxo.OutputID
}
RevokedEvent is the struct that is passed along with triggering a Revoked event.
func (*RevokedEvent) String ¶ added in v0.5.7
func (r *RevokedEvent) String() string
String returns a human readable version of the event.
func (*RevokedEvent) Timestamp ¶
func (r *RevokedEvent) Timestamp() time.Time
Timestamp returns time the event was fired.
func (*RevokedEvent) ToJSONSerializable ¶
func (r *RevokedEvent) ToJSONSerializable() interface{}
ToJSONSerializable returns a struct that can be serialized into JSON object.
func (*RevokedEvent) ToPersistable ¶
func (r *RevokedEvent) ToPersistable() *PersistableEvent
ToPersistable returns an event that can be persisted.
type RevokedEventJSON ¶
type RevokedEventJSON struct {
ManaType string `json:"manaType"`
NodeID string `json:"nodeID"`
Time int64 `json:"time"`
TxID string `json:"txID"`
Amount float64 `json:"amount"`
InputID string `json:"inputID"`
}
RevokedEventJSON is a JSON serializable form of a RevokedEvent.
type Snapshot ¶ added in v0.9.0
type Snapshot struct {
ByNodeID map[identity.ID]*SnapshotNode
}
Snapshot defines a snapshot of the ledger state.
func NewSnapshot ¶ added in v0.9.0
func NewSnapshot() *Snapshot
func (*Snapshot) FromMarshalUtil ¶ added in v0.9.0
func (s *Snapshot) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
func (*Snapshot) MaxAccessManaUpdateTime ¶ added in v0.9.0
func (*Snapshot) NodeSnapshot ¶ added in v0.9.0
func (s *Snapshot) NodeSnapshot(nodeID identity.ID) (nodeSnapshot *SnapshotNode)
type SnapshotNode ¶ added in v0.6.2
type SnapshotNode struct {
AccessMana *AccessManaSnapshot
SortedTxSnapshot SortedTxSnapshot
}
SnapshotNode defines the record for the mana snapshot of one node.
func (*SnapshotNode) AccessManaUpdateTime ¶ added in v0.9.0
func (s *SnapshotNode) AccessManaUpdateTime() (maxTime time.Time)
func (*SnapshotNode) AdjustAccessManaUpdateTime ¶ added in v0.9.0
func (s *SnapshotNode) AdjustAccessManaUpdateTime(diff time.Duration)
func (*SnapshotNode) Bytes ¶ added in v0.9.0
func (s *SnapshotNode) Bytes() (serialized []byte)
Bytes returns a serialized version of the SnapshotNode.
func (*SnapshotNode) FromMarshalUtil ¶ added in v0.9.0
func (s *SnapshotNode) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
func (*SnapshotNode) String ¶ added in v0.9.0
func (s *SnapshotNode) String() (humanReadable string)
String returns a human-readable version of the SnapshotNode.
type SortedTxSnapshot ¶ added in v0.6.2
type SortedTxSnapshot []*TxSnapshot
SortedTxSnapshot defines a list of SnapshotInfo sorted by timestamp.
func (SortedTxSnapshot) Bytes ¶ added in v0.9.0
func (s SortedTxSnapshot) Bytes() (serialized []byte)
func (*SortedTxSnapshot) FromMarshalUtil ¶ added in v0.9.0
func (s *SortedTxSnapshot) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
func (SortedTxSnapshot) Len ¶ added in v0.6.2
func (s SortedTxSnapshot) Len() int
func (SortedTxSnapshot) Less ¶ added in v0.6.2
func (s SortedTxSnapshot) Less(i, j int) bool
func (SortedTxSnapshot) String ¶ added in v0.9.0
func (s SortedTxSnapshot) String() (humanReadable string)
func (SortedTxSnapshot) Swap ¶ added in v0.6.2
func (s SortedTxSnapshot) Swap(i, j int)
type TxInfo ¶
type TxInfo struct {
// Timestamp is the timestamp of the transaction.
TimeStamp time.Time
// TransactionID is the ID of the transaction.
TransactionID utxo.TransactionID
// TotalBalance is the amount of funds being transferred via the transaction.
TotalBalance float64
// PledgeID is a map of mana types and the node to which this transaction pledges its mana type to.
PledgeID map[Type]identity.ID
// InputInfos is a slice of InputInfo that holds mana related info about each input within the transaction.
InputInfos []InputInfo
}
TxInfo holds information related to the transaction which we are processing for mana calculation.
type TxSnapshot ¶ added in v0.6.2
type TxSnapshot struct {
Value float64
TxID utxo.TransactionID
Timestamp time.Time
}
TxSnapshot defines the record of one transaction.
func (*TxSnapshot) Bytes ¶ added in v0.9.0
func (t *TxSnapshot) Bytes() (serialized []byte)
func (*TxSnapshot) FromMarshalUtil ¶ added in v0.9.0
func (t *TxSnapshot) FromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (err error)
func (*TxSnapshot) String ¶ added in v0.9.0
func (t *TxSnapshot) String() (humanReadable string)
String returns a human-readable version of the TxSnapshot.
type Type ¶
type Type byte
Type is the mana type.
const ( // AccessMana is mana associated with access to the network. AccessMana Type = iota // ConsensusMana is mana associated with consensus weights in the network. ConsensusMana // WeightedMana is a weighted combination of Mana 1 (consensus) and Mana 2 (access) for research purposes. WeightedMana // ResearchAccess is a special type of WeightedMana, that targets access pledges. ResearchAccess // ResearchConsensus is a special type of WeightedMana, that targets consensus pledges. ResearchConsensus )
func TypeFromString ¶
TypeFromString parses a string and returns the type of mana it defines.
type UpdatedEvent ¶
type UpdatedEvent struct {
NodeID identity.ID
OldMana BaseMana
NewMana BaseMana
ManaType Type // access or consensus
}
UpdatedEvent is the struct that is passed along with triggering an Updated event.
func (*UpdatedEvent) String ¶ added in v0.5.7
func (u *UpdatedEvent) String() string
String returns a human readable version of the event.
func (*UpdatedEvent) Timestamp ¶
func (u *UpdatedEvent) Timestamp() time.Time
Timestamp returns time the event was fired.
func (*UpdatedEvent) ToJSONSerializable ¶
func (u *UpdatedEvent) ToJSONSerializable() interface{}
ToJSONSerializable returns a struct that can be serialized into JSON object.
func (*UpdatedEvent) ToPersistable ¶
func (u *UpdatedEvent) ToPersistable() *PersistableEvent
ToPersistable converts the event to a persistable event.
type UpdatedEventJSON ¶
type UpdatedEventJSON struct {
NodeID string `json:"nodeID"`
OldMana interface{} `json:"oldMana"`
NewMana interface{} `json:"newMana"`
ManaType string `json:"manaType"`
}
UpdatedEventJSON is a JSON serializable form of an UpdatedEvent.