epoch

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GenesisTime is the time (Unix in seconds) of the genesis.
	GenesisTime int64 = 1662385954
	// Duration is the default epoch duration in seconds.
	Duration int64 = 10
)

Functions

This section is empty.

Types

type ActivityLog

type ActivityLog struct {
	model.Mutable[ActivityLog, *ActivityLog, activityLogModel] `serix:"0"`
}

ActivityLog is a time-based log of node activity. It stores information when a node is active and provides functionality to query for certain timeframes.

func NewActivityLog

func NewActivityLog() *ActivityLog

NewActivityLog is the constructor for ActivityLog.

func (*ActivityLog) Active

func (a *ActivityLog) Active(nodeID identity.ID) (active bool)

Active returns true if the provided node was active.

func (*ActivityLog) Add

func (a *ActivityLog) Add(nodeID identity.ID) (added bool)

Add adds a node to the activity log.

func (*ActivityLog) Clone

func (a *ActivityLog) Clone() *ActivityLog

Clone clones the ActivityLog.

func (*ActivityLog) ForEach

func (a *ActivityLog) ForEach(callback func(nodeID identity.ID) (err error)) (err error)

ForEach iterates through the activity set and calls the callback for every element.

func (*ActivityLog) Remove

func (a *ActivityLog) Remove(nodeID identity.ID) (removed bool)

Remove removes a node from the activity log.

func (*ActivityLog) Size

func (a *ActivityLog) Size() int

Size returns the size of the activity log.

func (*ActivityLog) String

func (a *ActivityLog) String() string

String returns a human-readable version of ActivityLog.

type CommitmentRoots

type CommitmentRoots struct {
	MeshRoot          MerkleRoot `serix:"0"`
	StateMutationRoot MerkleRoot `serix:"1"`
	StateRoot         MerkleRoot `serix:"2"`
	ManaRoot          MerkleRoot `serix:"3"`
}

CommitmentRoots contains roots of trees of an epoch.

type EC

type EC = MerkleRoot

type ECR

type ECR = MerkleRoot

func ComputeECR

func ComputeECR(meshRoot, stateMutationRoot, stateRoot, manaRoot MerkleRoot) ECR

ComputeECR calculates an ECR from the tree roots.

type ECRecord

type ECRecord struct {
	model.Storable[Index, ECRecord, *ECRecord, ecRecord] `serix:"0"`
}

ECRecord is a storable object represents the ecRecord of an epoch.

func NewECRecord

func NewECRecord(ei Index) (new *ECRecord)

NewECRecord creates and returns a ECRecord of the given EI.

func (*ECRecord) Bytes

func (e *ECRecord) Bytes() (bytes []byte, err error)

func (*ECRecord) ComputeEC

func (e *ECRecord) ComputeEC() (ec EC)

ComputeEC calculates the epoch commitment hash from the given ECRecord.

func (*ECRecord) ECR

func (e *ECRecord) ECR() ECR

ECR returns the ECR of an ECRecord.

func (*ECRecord) EI

func (e *ECRecord) EI() Index

func (*ECRecord) FromBytes

func (e *ECRecord) FromBytes(bytes []byte) (err error)

func (*ECRecord) PrevEC

func (e *ECRecord) PrevEC() EC

PrevEC returns the EC of an ECRecord.

func (*ECRecord) Roots

func (e *ECRecord) Roots() *CommitmentRoots

Roots returns the CommitmentRoots of an ECRecord.

func (*ECRecord) SetECR

func (e *ECRecord) SetECR(ecr ECR)

SetECR sets the ECR of an ECRecord.

func (*ECRecord) SetEI

func (e *ECRecord) SetEI(ei Index)

func (*ECRecord) SetPrevEC

func (e *ECRecord) SetPrevEC(prevEC EC)

SetPrevEC sets the PrevEC of an ECRecord.

func (*ECRecord) SetRoots

func (e *ECRecord) SetRoots(roots *CommitmentRoots)

SetRoots sets the CommitmentRoots of an ECRecord.

type Index

type Index int64

Index is the ID of an epoch.

func IndexFromBytes

func IndexFromBytes(bytes []byte) (ei Index, consumedBytes int, err error)

func IndexFromTime

func IndexFromTime(t time.Time) Index

IndexFromTime calculates the EI for the given time.

func (Index) Bytes

func (i Index) Bytes() []byte

func (Index) EndTime

func (i Index) EndTime() time.Time

EndTime calculates the end time of the given epoch.

func (Index) StartTime

func (i Index) StartTime() time.Time

StartTime calculates the start time of the given epoch.

func (Index) String

func (i Index) String() string

type MerkleRoot

type MerkleRoot [blake2b.Size256]byte

func NewMerkleRoot

func NewMerkleRoot(bytes []byte) MerkleRoot

func (MerkleRoot) Base58

func (m MerkleRoot) Base58() string

func (MerkleRoot) Bytes

func (m MerkleRoot) Bytes() []byte

type NodesActivityLog

type NodesActivityLog struct {
	shrinkingmap.ShrinkingMap[Index, *ActivityLog] `serix:"0,lengthPrefixType=uint32"`
}

func NewNodesActivityLog

func NewNodesActivityLog() *NodesActivityLog

func (*NodesActivityLog) Bytes

func (al *NodesActivityLog) Bytes() []byte

func (*NodesActivityLog) FromBytes

func (al *NodesActivityLog) FromBytes(data []byte) (err error)

type SnapshotEpochActivity

type SnapshotEpochActivity map[Index]*SnapshotNodeActivity

SnapshotEpochActivity is the data structure to store node activity for the snapshot.

func NewSnapshotEpochActivity

func NewSnapshotEpochActivity() SnapshotEpochActivity

NewSnapshotEpochActivity creates a new SnapshotEpochActivity instance.

type SnapshotNodeActivity

type SnapshotNodeActivity struct {
	model.Mutable[SnapshotNodeActivity, *SnapshotNodeActivity, nodeActivityModel] `serix:"0"`
}

SnapshotNodeActivity is structure to store nodes activity for an epoch.

func NewSnapshotNodeActivity

func NewSnapshotNodeActivity() *SnapshotNodeActivity

NewSnapshotNodeActivity creates a new SnapshotNodeActivity instance.

func (*SnapshotNodeActivity) NodeActivity

func (s *SnapshotNodeActivity) NodeActivity(nodeID identity.ID) uint64

NodeActivity returns activity counter for a given node.

func (*SnapshotNodeActivity) NodesLog

func (s *SnapshotNodeActivity) NodesLog() map[identity.ID]uint64

NodesLog returns its activity map of nodes.

func (*SnapshotNodeActivity) SetNodeActivity

func (s *SnapshotNodeActivity) SetNodeActivity(nodeID identity.ID, activity uint64)

SetNodeActivity adds a node activity record to the activity log.

Jump to

Keyboard shortcuts

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