From dbddfa581e9edc26a4af66dfeed97fb4ff43b28f Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Tue, 14 Jan 2025 11:04:50 +0100 Subject: [PATCH] Fix getConfiguredRuntimeIDs function RuntimeIds are extracted from the config only. Previously they were extracted with combination of config and bundle registry manifests. Since discovery is copying bundles, this meant that even if you removed the bundle from the registry, the `Discover` function would still find it, thus effectively you were unable to unconfigure the runtime. --- go/runtime/bundle/discovery_test.go | 2 +- go/runtime/registry/config.go | 23 ++++++++++++++++++++--- go/runtime/registry/registry.go | 10 ++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/go/runtime/bundle/discovery_test.go b/go/runtime/bundle/discovery_test.go index 1f3b59aa2e2..db74f2bb965 100644 --- a/go/runtime/bundle/discovery_test.go +++ b/go/runtime/bundle/discovery_test.go @@ -166,7 +166,7 @@ func TestCleanStaleExplodedBundles(t *testing.T) { require.NoError(t, err) } - // Ensure bundle were exploded succesfully. + // Ensure bundle were exploded successfully. entries, err := os.ReadDir(ExplodedPath(dir)) require.NoError(t, err) // 2 x RONL manifest + "detached subdir". diff --git a/go/runtime/registry/config.go b/go/runtime/registry/config.go index d86aff68241..15652a0213a 100644 --- a/go/runtime/registry/config.go +++ b/go/runtime/registry/config.go @@ -13,6 +13,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/common" "github.com/oasisprotocol/oasis-core/go/common/identity" + "github.com/oasisprotocol/oasis-core/go/common/logging" "github.com/oasisprotocol/oasis-core/go/common/persistent" "github.com/oasisprotocol/oasis-core/go/common/sgx/pcs" "github.com/oasisprotocol/oasis-core/go/config" @@ -37,7 +38,7 @@ func getLocalConfig(runtimeID common.Namespace) map[string]interface{} { return config.GlobalConfig.Runtime.GetLocalConfig(runtimeID) } -func getConfiguredRuntimeIDs(registry bundle.Registry) ([]common.Namespace, error) { +func getConfiguredRuntimeIDs(logger *logging.Logger) ([]common.Namespace, error) { // Check if any runtimes are configured to be hosted. runtimes := make(map[common.Namespace]struct{}) for _, cfg := range config.GlobalConfig.Runtime.Runtimes { @@ -46,8 +47,24 @@ func getConfiguredRuntimeIDs(registry bundle.Registry) ([]common.Namespace, erro // Support legacy configurations where runtimes are specified within // configured bundles. - for _, manifest := range registry.GetManifests() { - runtimes[manifest.ID] = struct{}{} + for _, path := range config.GlobalConfig.Runtime.Paths { + err := func() error { + bnd, err := bundle.Open(path) + if err != nil { + logger.Error("failed to open bundle", + "err", err, + "src", path, + ) + return fmt.Errorf("failed to open bundle: %w", err) + } + defer bnd.Close() + + runtimes[bnd.Manifest.ID] = struct{}{} + return nil + }() + if err != nil { + return nil, err + } } if cmdFlags.DebugDontBlameOasis() && viper.IsSet(bundle.CfgDebugMockIDs) { diff --git a/go/runtime/registry/registry.go b/go/runtime/registry/registry.go index 8b164791ccb..8be3f240c4e 100644 --- a/go/runtime/registry/registry.go +++ b/go/runtime/registry/registry.go @@ -710,15 +710,17 @@ func New( consensus consensus.Backend, ias []ias.Endpoint, ) (Registry, error) { - // Create bundle registry and discovery. - bundleRegistry := bundle.NewRegistry(dataDir) + logger := logging.GetLogger("runtime/registry") // Get configured Runtime IDs. - runtimeIDs, err := getConfiguredRuntimeIDs(bundleRegistry) + runtimeIDs, err := getConfiguredRuntimeIDs(logger) if err != nil { return nil, err } + // Create bundle registry and discovery. + bundleRegistry := bundle.NewRegistry(dataDir) + bundleDiscovery := bundle.NewDiscovery(dataDir, bundleRegistry, runtimeIDs) // Create history keeper factory. @@ -747,7 +749,7 @@ func New( // Create runtime registry. r := &runtimeRegistry{ - logger: logging.GetLogger("runtime/registry"), + logger: logger, quitCh: make(chan struct{}), dataDir: dataDir, consensus: consensus,