Documentation
¶
Overview ¶
Package swarm implements epoch-based swarm assignment for session workloads. Swarms are dynamically formed committees of nodes assigned to execute sessions.
Index ¶
- func ComputeBeaconID(epoch uint64, randomness, previousBeacon core.ID) core.ID
- type Assigner
- type Config
- type EpochBeacon
- type NodeStatus
- type Registry
- func (r *Registry) Activate(id core.ID) error
- func (r *Registry) Count() int
- func (r *Registry) CountActive() int
- func (r *Registry) Exit(id core.ID) error
- func (r *Registry) Get(id core.ID) (*ServiceNode, error)
- func (r *Registry) GetActive() []*ServiceNode
- func (r *Registry) GetActiveIDs() []core.ID
- func (r *Registry) GetByEndpoint(endpoint string) (*ServiceNode, error)
- func (r *Registry) Register(id core.ID, publicKey []byte, endpoint string, stake uint64) (*ServiceNode, error)
- func (r *Registry) Slash(id core.ID, evidence string) error
- func (r *Registry) Suspend(id core.ID, reason string) error
- func (r *Registry) UpdateHeartbeat(id core.ID) error
- type ServiceNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Assigner ¶
type Assigner struct {
// contains filtered or unexported fields
}
Assigner handles epoch-based swarm assignment.
func NewAssigner ¶
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) QuorumSize ¶
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 (*Registry) CountActive ¶
CountActive returns the number of active nodes.
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 ¶
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.
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.