swarm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package swarm implements epoch-based swarm assignment for session workloads. Swarms are dynamically formed committees of nodes assigned to execute sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeBeaconID

func ComputeBeaconID(epoch uint64, randomness, previousBeacon core.ID) core.ID

ComputeBeaconID computes a deterministic beacon ID.

Types

type Assigner

type Assigner struct {
	// contains filtered or unexported fields
}

Assigner handles epoch-based swarm assignment.

func NewAssigner

func NewAssigner(config *Config) *Assigner

NewAssigner creates a new swarm assigner.

func (*Assigner) AssignCommittee

func (a *Assigner) AssignCommittee(
	serviceID core.ID,
	epoch uint64,
	epochRandomness core.ID,
	eligibleNodes []core.ID,
) ([]core.ID, error)

AssignCommittee assigns a committee for a session based on epoch randomness. Uses deterministic selection based on epoch beacon and service ID.

func (*Assigner) IsQuorum

func (a *Assigner) IsQuorum(participants, committeeSize int) bool

IsQuorum checks if the given number of participants meets quorum.

func (*Assigner) QuorumSize

func (a *Assigner) QuorumSize(committeeSize int) int

QuorumSize returns the number of nodes required for quorum.

type Config

type Config struct {
	// MinCommitteeSize is the minimum number of nodes in a committee
	MinCommitteeSize int

	// MaxCommitteeSize is the maximum number of nodes in a committee
	MaxCommitteeSize int

	// QuorumThreshold is the fraction of committee required for quorum (e.g., 0.67)
	QuorumThreshold float64
}

Config holds swarm assignment configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default swarm configuration.

type EpochBeacon

type EpochBeacon struct {
	// Epoch number
	Epoch uint64 `json:"epoch"`

	// Randomness is the VRF output for this epoch
	Randomness core.ID `json:"randomness"`

	// PreviousBeacon is the hash of the previous epoch's beacon
	PreviousBeacon core.ID `json:"previousBeacon"`

	// AttestationID is the threshold attestation over this beacon
	AttestationID core.ID `json:"attestationId"`
}

EpochBeacon represents epoch randomness for swarm assignment.

func NewEpochBeacon

func NewEpochBeacon(epoch uint64, randomness, previousBeacon core.ID) *EpochBeacon

NewEpochBeacon creates a new epoch beacon.

type NodeStatus

type NodeStatus uint8

NodeStatus represents the status of a service node.

const (
	NodeStatusUnknown    NodeStatus = iota
	NodeStatusRegistered            // Registered but not yet active
	NodeStatusActive                // Active and available for assignment
	NodeStatusSuspended             // Temporarily suspended
	NodeStatusExited                // Voluntarily exited
	NodeStatusSlashed               // Slashed for misbehavior
)

func (NodeStatus) String

func (s NodeStatus) String() string

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages service node registration and lifecycle.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new service node registry.

func (*Registry) Activate

func (r *Registry) Activate(id core.ID) error

Activate activates a registered node.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the total number of nodes.

func (*Registry) CountActive

func (r *Registry) CountActive() int

CountActive returns the number of active nodes.

func (*Registry) Exit

func (r *Registry) Exit(id core.ID) error

Exit marks a node as voluntarily exited.

func (*Registry) Get

func (r *Registry) Get(id core.ID) (*ServiceNode, error)

Get retrieves a node by ID.

func (*Registry) GetActive

func (r *Registry) GetActive() []*ServiceNode

GetActive returns all active nodes.

func (*Registry) GetActiveIDs

func (r *Registry) GetActiveIDs() []core.ID

GetActiveIDs returns IDs of all active nodes.

func (*Registry) GetByEndpoint

func (r *Registry) GetByEndpoint(endpoint string) (*ServiceNode, error)

GetByEndpoint retrieves a node by endpoint.

func (*Registry) Register

func (r *Registry) Register(id core.ID, publicKey []byte, endpoint string, stake uint64) (*ServiceNode, error)

Register registers a new service node.

func (*Registry) Slash

func (r *Registry) Slash(id core.ID, evidence string) error

Slash slashes a node for misbehavior.

func (*Registry) Suspend

func (r *Registry) Suspend(id core.ID, reason string) error

Suspend suspends an active node.

func (*Registry) UpdateHeartbeat

func (r *Registry) UpdateHeartbeat(id core.ID) error

UpdateHeartbeat updates a node's last seen time.

type ServiceNode

type ServiceNode struct {
	// ID is the node identifier
	ID core.ID `json:"id"`

	// PublicKey is the node's public key (PQ-safe)
	PublicKey []byte `json:"publicKey"`

	// Endpoint is the node's network endpoint
	Endpoint string `json:"endpoint"`

	// Status is the current node status
	Status NodeStatus `json:"status"`

	// Stake is the amount staked by this node
	Stake uint64 `json:"stake"`

	// RegisteredAt is when the node was registered
	RegisteredAt time.Time `json:"registeredAt"`

	// LastSeenAt is when the node was last seen active
	LastSeenAt time.Time `json:"lastSeenAt"`

	// Metadata contains additional node metadata
	Metadata map[string]string `json:"metadata,omitempty"`
}

ServiceNode represents a registered service node.

Jump to

Keyboard shortcuts

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