Skip to content

Commit

Permalink
Fix getConfiguredRuntimeIDs function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martintomazic committed Jan 14, 2025
1 parent ea17998 commit dbddfa5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go/runtime/bundle/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
23 changes: 20 additions & 3 deletions go/runtime/registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions go/runtime/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dbddfa5

Please sign in to comment.