mirror of
https://github.com/luxfi/vm.git
synced 2026-10-30 15:13:40 +00:00
- Fix dag package imports to use vm/proto/pb/dag instead of node/proto - Fix api/health test to use atomic.Atomic from github.com/luxfi/atomic - Fix components/message test to use crypto.RandomBytes - Fix chains/manager to use correct EngineType constant
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package registry
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/vm/manager"
|
|
)
|
|
|
|
var _ VMRegistry = (*vmRegistry)(nil)
|
|
|
|
// VMRegistry defines functionality to get any new virtual machines on the node,
|
|
// and install them if they're not already installed.
|
|
type VMRegistry interface {
|
|
// Reload installs all non-installed vms on the node.
|
|
Reload(ctx context.Context) ([]ids.ID, map[ids.ID]error, error)
|
|
}
|
|
|
|
// VMRegistryConfig defines configurations for VMRegistry
|
|
type VMRegistryConfig struct {
|
|
VMGetter VMGetter
|
|
VMManager manager.Manager
|
|
}
|
|
|
|
type vmRegistry struct {
|
|
config VMRegistryConfig
|
|
}
|
|
|
|
// NewVMRegistry returns a VMRegistry
|
|
func NewVMRegistry(config VMRegistryConfig) VMRegistry {
|
|
return &vmRegistry{
|
|
config: config,
|
|
}
|
|
}
|
|
|
|
func (r *vmRegistry) Reload(ctx context.Context) ([]ids.ID, map[ids.ID]error, error) {
|
|
_, unregisteredVMs, err := r.config.VMGetter.Get()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
registeredVms := make([]ids.ID, 0, len(unregisteredVMs))
|
|
failedVMs := make(map[ids.ID]error)
|
|
|
|
for vmID, factory := range unregisteredVMs {
|
|
if err := r.config.VMManager.RegisterFactory(ctx, vmID, factory); err != nil {
|
|
failedVMs[vmID] = err
|
|
continue
|
|
}
|
|
|
|
registeredVms = append(registeredVms, vmID)
|
|
}
|
|
return registeredVms, failedVMs, nil
|
|
}
|