aivm

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name = "aivm"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AIAgent

type AIAgent struct {
	ID           ids.ShortID `json:"id"`
	Name         string      `json:"name"`
	Capabilities []string    `json:"capabilities"`
	Subnet       ids.ID      `json:"subnet"`
	Endpoint     string      `json:"endpoint"`
	PublicKey    []byte      `json:"publicKey"`
}

AIAgent represents an AI agent or model provider

type AITask

type AITask struct {
	ID          ids.ID      `json:"id"`
	Requester   ids.ShortID `json:"requester"`
	TaskType    string      `json:"taskType"`
	Parameters  []byte      `json:"parameters"`
	Status      TaskStatus  `json:"status"`
	Result      []byte      `json:"result,omitempty"`
	ProofOfWork []byte      `json:"proofOfWork,omitempty"`
	Fee         uint64      `json:"fee"`
	CreatedAt   int64       `json:"createdAt"`
	CompletedAt int64       `json:"completedAt,omitempty"`
}

AITask represents an AI computation task

type Block

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

Block represents a block in the AI Chain

func (*Block) Accept

func (b *Block) Accept(context.Context) error

Accept implements the chain.Block interface

func (*Block) Bytes

func (b *Block) Bytes() []byte

Bytes implements the chain.Block interface

func (*Block) Height

func (b *Block) Height() uint64

Height implements the chain.Block interface

func (*Block) ID

func (b *Block) ID() ids.ID

ID implements the chain.Block interface

func (*Block) Parent

func (b *Block) Parent() ids.ID

Parent implements the chain.Block interface

func (*Block) Reject

func (b *Block) Reject(context.Context) error

Reject implements the chain.Block interface

func (*Block) Status

func (b *Block) Status() choices.Status

Status implements the chain.Block interface

func (*Block) Timestamp added in v1.16.56

func (b *Block) Timestamp() time.Time

Timestamp implements the chain.Block interface

func (*Block) Verify

func (b *Block) Verify(ctx context.Context) error

Verify implements the chain.Block interface

type ComputeMetrics added in v1.20.0

type ComputeMetrics struct {
	ExecutionTime time.Duration `json:"executionTime"`
	GPUTime       time.Duration `json:"gpuTime"`
	MemoryUsed    uint64        `json:"memoryUsed"`
	PowerUsed     float64       `json:"powerUsed"` // Watts
	Accuracy      float64       `json:"accuracy,omitempty"`
	Throughput    float64       `json:"throughput,omitempty"`
}

ComputeMetrics tracks computation metrics

type DiscountTier added in v1.20.0

type DiscountTier struct {
	MinHours uint64  `json:"minHours"`
	Discount float64 `json:"discount"` // Percentage
}

DiscountTier defines volume discounts

type Factory

type Factory struct{}

Factory creates new instances of the AI VM

func (*Factory) New

func (f *Factory) New(log.Logger) (interface{}, error)

New returns a new instance of the AI VM

type GPUProvider

type GPUProvider struct {
	NodeID       ids.NodeID     `json:"nodeId"`
	ProviderInfo ProviderInfo   `json:"providerInfo"`
	GPUs         []GPUSpec      `json:"gpus"`
	Status       ProviderStatus `json:"status"`
	Reputation   float64        `json:"reputation"`
	TasksHandled uint64         `json:"tasksHandled"`
	JoinedAt     time.Time      `json:"joinedAt"`
}

GPUProvider represents a GPU compute provider

type GPUSpec added in v1.20.0

type GPUSpec struct {
	Model        string  `json:"model"`  // e.g., "RTX 4090", "A100", "H100"
	Memory       uint64  `json:"memory"` // VRAM in GB
	ComputeUnits int     `json:"computeUnits"`
	Performance  float64 `json:"performance"` // TFLOPS
	Available    bool    `json:"available"`
	Temperature  float64 `json:"temperature"`
	Utilization  float64 `json:"utilization"`
}

GPUSpec defines GPU specifications

type GPUSubnet added in v1.20.0

type GPUSubnet struct {
	SubnetID    ids.ID          `json:"subnetId"`
	Name        string          `json:"name"`
	Config      GPUSubnetConfig `json:"config"`
	Providers   []GPUProvider   `json:"providers"`
	Tasks       []GPUTask       `json:"tasks"`
	Performance SubnetMetrics   `json:"performance"`
	// contains filtered or unexported fields
}

GPUSubnet represents a GPU-powered subnet for AI computation

func (*GPUSubnet) GetSubnetStats added in v1.20.0

func (s *GPUSubnet) GetSubnetStats() SubnetMetrics

GetSubnetStats returns subnet statistics

func (*GPUSubnet) RegisterProvider added in v1.20.0

func (s *GPUSubnet) RegisterProvider(nodeID ids.NodeID, info ProviderInfo, gpus []GPUSpec) error

RegisterProvider registers a GPU provider to a subnet

func (*GPUSubnet) SubmitTask added in v1.20.0

func (s *GPUSubnet) SubmitTask(ctx context.Context, taskType string, requirements TaskRequirements, requester ids.ShortID) (*GPUTask, error)

SubmitTask submits a new GPU task

type GPUSubnetConfig added in v1.20.0

type GPUSubnetConfig struct {
	MinGPUCount      int                `json:"minGpuCount"`
	RequiredGPUTypes []string           `json:"requiredGpuTypes"`
	TaskTypes        []string           `json:"taskTypes"`
	PricingModel     PricingModel       `json:"pricingModel"`
	QualityMetrics   QualityRequirement `json:"qualityMetrics"`
	NetworkTopology  string             `json:"networkTopology"` // "mesh", "star", "hybrid"
}

GPUSubnetConfig defines configuration for GPU subnet

func TestGPUSubnet added in v1.20.0

func TestGPUSubnet() *GPUSubnetConfig

TestGPUSubnet creates a test GPU subnet configuration

type GPUSubnetManager added in v1.20.0

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

GPUSubnetManager manages GPU subnets

func NewGPUSubnetManager added in v1.20.0

func NewGPUSubnetManager(aivm *VM, log log.Logger) *GPUSubnetManager

NewGPUSubnetManager creates a new GPU subnet manager

func (*GPUSubnetManager) CreateSubnet added in v1.20.0

func (m *GPUSubnetManager) CreateSubnet(name string, config GPUSubnetConfig) (*GPUSubnet, error)

CreateSubnet creates a new GPU subnet

type GPUTask added in v1.20.0

type GPUTask struct {
	TaskID       ids.ID           `json:"taskId"`
	Type         string           `json:"type"` // "training", "inference", "rendering", "mining"
	Requirements TaskRequirements `json:"requirements"`
	Requester    ids.ShortID      `json:"requester"`
	Provider     ids.NodeID       `json:"provider"`
	Status       TaskStatus       `json:"status"`
	Result       GPUTaskResult    `json:"result"`
	CreatedAt    time.Time        `json:"createdAt"`
	StartedAt    time.Time        `json:"startedAt"`
	CompletedAt  time.Time        `json:"completedAt"`
}

GPUTask represents an AI computation task

type GPUTaskResult added in v1.20.0

type GPUTaskResult struct {
	Success     bool           `json:"success"`
	Output      []byte         `json:"output,omitempty"`
	Metrics     ComputeMetrics `json:"metrics"`
	ProofOfWork []byte         `json:"proofOfWork"`
	Error       string         `json:"error,omitempty"`
}

GPUTaskResult contains GPU task execution results

type Pricing added in v1.20.0

type Pricing struct {
	HourlyRate  uint64        `json:"hourlyRate"`
	MinDuration time.Duration `json:"minDuration"`
	MaxDuration time.Duration `json:"maxDuration"`
	Currency    string        `json:"currency"` // "LUX"
}

Pricing contains provider-specific pricing

type PricingModel added in v1.20.0

type PricingModel struct {
	BasePrice       uint64         `json:"basePrice"` // Per GPU hour
	PricePerTFLOPS  uint64         `json:"pricePerTflops"`
	SurgeMultiplier float64        `json:"surgeMultiplier"`
	DiscountTiers   []DiscountTier `json:"discountTiers"`
}

PricingModel defines pricing for GPU compute

type ProviderInfo added in v1.20.0

type ProviderInfo struct {
	Name         string   `json:"name"`
	Location     string   `json:"location"`
	Capabilities []string `json:"capabilities"`
	Pricing      Pricing  `json:"pricing"`
}

ProviderInfo contains provider details

type ProviderStatus added in v1.20.0

type ProviderStatus struct {
	Online       bool      `json:"online"`
	LastSeen     time.Time `json:"lastSeen"`
	Uptime       float64   `json:"uptime"`
	FailureRate  float64   `json:"failureRate"`
	CurrentTasks int       `json:"currentTasks"`
	MaxTasks     int       `json:"maxTasks"`
}

ProviderStatus represents provider status

type QualityRequirement added in v1.20.0

type QualityRequirement struct {
	MinReputation  float64 `json:"minReputation"`
	MaxFailureRate float64 `json:"maxFailureRate"`
	MinUptime      float64 `json:"minUptime"`
	RequireSLA     bool    `json:"requireSla"`
}

QualityRequirement defines quality requirements

type SubnetMetrics added in v1.20.0

type SubnetMetrics struct {
	TotalTasks      uint64        `json:"totalTasks"`
	CompletedTasks  uint64        `json:"completedTasks"`
	FailedTasks     uint64        `json:"failedTasks"`
	AverageLatency  time.Duration `json:"averageLatency"`
	TotalGPUHours   float64       `json:"totalGpuHours"`
	NetworkHashrate float64       `json:"networkHashrate"`
	ActiveProviders int           `json:"activeProviders"`
}

SubnetMetrics tracks subnet performance

type TaskRequirements added in v1.20.0

type TaskRequirements struct {
	GPUModel     string            `json:"gpuModel,omitempty"`
	MinMemory    uint64            `json:"minMemory"`
	MinCompute   float64           `json:"minCompute"`
	MaxLatency   time.Duration     `json:"maxLatency"`
	DataSize     uint64            `json:"dataSize"`
	ModelSize    uint64            `json:"modelSize,omitempty"`
	Framework    string            `json:"framework,omitempty"` // "pytorch", "tensorflow", "jax"
	CustomParams map[string]string `json:"customParams,omitempty"`
}

TaskRequirements defines task requirements

type TaskResult

type TaskResult struct {
	TaskID      ids.ID      `json:"taskId"`
	ExecutorID  ids.ShortID `json:"executorId"`
	Result      []byte      `json:"result"`
	Proof       []byte      `json:"proof"`
	ComputeTime uint64      `json:"computeTime"`
}

TaskResult represents the result of an AI task

type TaskStatus

type TaskStatus uint8

TaskStatus represents the status of an AI task

const (
	TaskPending TaskStatus = iota
	TaskAssigned
	TaskProcessing
	TaskCompleted
	TaskFailed
)

type VM

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

VM implements the chain.ChainVM interface for the AI Chain (A-Chain) This chain is specialized for AI computation and agent coordination

func (*VM) AppGossip

func (vm *VM) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error

AppGossip implements the common.AppHandler interface

func (*VM) AppRequest

func (vm *VM) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, request []byte) error

AppRequest implements the common.AppHandler interface

func (*VM) AppRequestFailed

func (vm *VM) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, appErr *common.AppError) error

AppRequestFailed implements the common.AppHandler interface

func (*VM) AppResponse

func (vm *VM) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error

AppResponse implements the common.AppHandler interface

func (*VM) BuildBlock

func (vm *VM) BuildBlock(ctx context.Context) (block.Block, error)

BuildBlock implements the chain.ChainVM interface

func (*VM) Connected

func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error

Connected implements the validators.Connector interface

func (*VM) CreateHandlers

func (vm *VM) CreateHandlers(context.Context) (map[string]http.Handler, error)

CreateHandlers implements the core.VM interface

func (*VM) CrossChainAppRequest

func (vm *VM) CrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, msg []byte) error

CrossChainAppRequest implements the core.VM interface

func (*VM) CrossChainAppRequestFailed

func (vm *VM) CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32, appErr *common.AppError) error

CrossChainAppRequestFailed implements the core.VM interface

func (*VM) CrossChainAppResponse

func (vm *VM) CrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, msg []byte) error

CrossChainAppResponse implements the core.VM interface

func (*VM) Disconnected

func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error

Disconnected implements the validators.Connector interface

func (*VM) GetBlock

func (vm *VM) GetBlock(ctx context.Context, blkID ids.ID) (block.Block, error)

GetBlock implements the chain.ChainVM interface

func (*VM) GetBlockIDAtHeight

func (vm *VM) GetBlockIDAtHeight(ctx context.Context, height uint64) (ids.ID, error)

GetBlockIDAtHeight implements the chain.ChainVM interface

func (*VM) HealthCheck

func (vm *VM) HealthCheck(context.Context) (any, error)

HealthCheck implements the health.Checker interface

func (*VM) Initialize

func (vm *VM) Initialize(
	ctx context.Context,
	chainCtx *consensusctx.Context,
	db database.Database,
	genesisBytes []byte,
	upgradeBytes []byte,
	configBytes []byte,
	toEngine chan<- block.Message,
	fxs []*consensus.Fx,
	appSender appsender.AppSender,
) error

Initialize implements the core.VM interface

func (*VM) LastAccepted

func (vm *VM) LastAccepted(context.Context) (ids.ID, error)

LastAccepted implements the chain.ChainVM interface

func (*VM) ParseBlock

func (vm *VM) ParseBlock(ctx context.Context, blockBytes []byte) (block.Block, error)

ParseBlock implements the chain.ChainVM interface

func (*VM) SetPreference

func (vm *VM) SetPreference(ctx context.Context, blkID ids.ID) error

SetPreference implements the chain.ChainVM interface

func (*VM) SetState

func (vm *VM) SetState(ctx context.Context, state core.State) error

SetState implements the core.VM interface

func (*VM) Shutdown

func (vm *VM) Shutdown(context.Context) error

Shutdown implements the core.VM interface

func (*VM) Version

func (vm *VM) Version(context.Context) (string, error)

Version implements the core.VM interface

Jump to

Keyboard shortcuts

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