From f7bc29b88c01ef615abef6a28c83d73406429bc2 Mon Sep 17 00:00:00 2001 From: Peter Nose Date: Fri, 14 Feb 2025 22:46:24 +0100 Subject: [PATCH 1/4] go/runtime/registry/host: Decouple runtime host notifier --- go/runtime/registry/handler.go | 3 --- go/runtime/registry/host.go | 9 --------- go/worker/common/committee/node.go | 18 +++++++++++------- go/worker/common/committee/runtime_host.go | 6 ------ go/worker/keymanager/handler.go | 6 ------ go/worker/keymanager/init.go | 3 +++ go/worker/keymanager/worker.go | 10 +++++----- 7 files changed, 19 insertions(+), 36 deletions(-) diff --git a/go/runtime/registry/handler.go b/go/runtime/registry/handler.go index df484245a2c..4522b42a28a 100644 --- a/go/runtime/registry/handler.go +++ b/go/runtime/registry/handler.go @@ -49,9 +49,6 @@ type RuntimeHostHandlerFactory interface { // NewRuntimeHostHandler creates a new runtime host handler. NewRuntimeHostHandler() host.RuntimeHandler - - // NewRuntimeHostNotifier creates a new runtime host notifier. - NewRuntimeHostNotifier(host host.Runtime) protocol.Notifier } // RuntimeHostHandler is a runtime host handler suitable for compute runtimes. It provides the diff --git a/go/runtime/registry/host.go b/go/runtime/registry/host.go index 7ce7091563f..ad2e3220bce 100644 --- a/go/runtime/registry/host.go +++ b/go/runtime/registry/host.go @@ -12,7 +12,6 @@ import ( "github.com/oasisprotocol/oasis-core/go/runtime/host" "github.com/oasisprotocol/oasis-core/go/runtime/host/composite" "github.com/oasisprotocol/oasis-core/go/runtime/host/multi" - "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol" ) // RuntimeHostNode provides methods for nodes that need to host runtimes. @@ -23,7 +22,6 @@ type RuntimeHostNode struct { rr host.RichRuntime runtime Runtime - notifier protocol.Notifier handler host.RuntimeHandler provisioner host.Provisioner @@ -36,7 +34,6 @@ func NewRuntimeHostNode(factory RuntimeHostHandlerFactory) (*RuntimeHostNode, er h := composite.NewHost(runtime.ID()) rr := host.NewRichRuntime(h) - notifier := factory.NewRuntimeHostNotifier(h) handler := factory.NewRuntimeHostHandler() provisioner := runtime.HostProvisioner() @@ -44,7 +41,6 @@ func NewRuntimeHostNode(factory RuntimeHostHandlerFactory) (*RuntimeHostNode, er host: h, rr: rr, runtime: runtime, - notifier: notifier, handler: handler, provisioner: provisioner, rofls: make(map[component.ID]version.Version), @@ -100,11 +96,6 @@ func (n *RuntimeHostNode) GetHostedRuntime() host.RichRuntime { return n.rr } -// GetRuntimeHostNotifier returns the runtime host notifier. -func (n *RuntimeHostNode) GetRuntimeHostNotifier() protocol.Notifier { - return n.notifier -} - // GetHostedRuntimeActiveVersion returns the version of the active runtime. func (n *RuntimeHostNode) GetHostedRuntimeActiveVersion() (*version.Version, error) { return n.host.GetActiveVersion() diff --git a/go/worker/common/committee/node.go b/go/worker/common/committee/node.go index 1c2ff71c010..1615090e0fc 100644 --- a/go/worker/common/committee/node.go +++ b/go/worker/common/committee/node.go @@ -20,12 +20,13 @@ import ( keymanager "github.com/oasisprotocol/oasis-core/go/keymanager/api" cmmetrics "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics" p2pAPI "github.com/oasisprotocol/oasis-core/go/p2p/api" - "github.com/oasisprotocol/oasis-core/go/p2p/protocol" + p2pProtocol "github.com/oasisprotocol/oasis-core/go/p2p/protocol" registry "github.com/oasisprotocol/oasis-core/go/registry/api" roothash "github.com/oasisprotocol/oasis-core/go/roothash/api" "github.com/oasisprotocol/oasis-core/go/roothash/api/block" runtime "github.com/oasisprotocol/oasis-core/go/runtime/api" "github.com/oasisprotocol/oasis-core/go/runtime/host" + "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" "github.com/oasisprotocol/oasis-core/go/runtime/txpool" tpConfig "github.com/oasisprotocol/oasis-core/go/runtime/txpool/config" @@ -158,6 +159,7 @@ type Node struct { Group *Group P2P p2pAPI.Service TxPool txpool.TransactionPool + notifier protocol.Notifier txTopic string @@ -704,18 +706,17 @@ func (n *Node) worker() { n.updateHostedRuntimeVersionLocked() n.CrossNode.Unlock() - // Start the runtime and its notifier. + // Start the runtime. hrt := n.GetHostedRuntime() - hrtNotifier := n.GetRuntimeHostNotifier() - hrtEventCh, hrtSub := hrt.WatchEvents() defer hrtSub.Close() hrt.Start() defer hrt.Stop() - hrtNotifier.Start() - defer hrtNotifier.Stop() + // Start the runtime's notifier. + n.notifier.Start() + defer n.notifier.Stop() // Enter the main processing loop. initialized := false @@ -879,7 +880,7 @@ func NewNode( return nil, err } - txTopic := protocol.NewTopicKindTxID(chainContext, runtime.ID()) + txTopic := p2pProtocol.NewTopicKindTxID(chainContext, runtime.ID()) n := &Node{ ChainContext: chainContext, @@ -911,6 +912,9 @@ func NewNode( } n.RuntimeHostNode = rhn + // Prepare the runtime host notifier. + n.notifier = runtimeRegistry.NewRuntimeHostNotifier(runtime, rhn.GetHostedRuntime(), consensus) + // Prepare transaction pool. n.TxPool = txpool.New(runtime.ID(), txPoolCfg, rhn.GetHostedRuntime(), runtime.History(), n) diff --git a/go/worker/common/committee/runtime_host.go b/go/worker/common/committee/runtime_host.go index 7ae642dfd20..5bc53bbfe76 100644 --- a/go/worker/common/committee/runtime_host.go +++ b/go/worker/common/committee/runtime_host.go @@ -4,7 +4,6 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/identity" consensusAPI "github.com/oasisprotocol/oasis-core/go/consensus/api" "github.com/oasisprotocol/oasis-core/go/runtime/host" - "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol" runtimeKeymanager "github.com/oasisprotocol/oasis-core/go/runtime/keymanager/api" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" "github.com/oasisprotocol/oasis-core/go/runtime/txpool" @@ -20,11 +19,6 @@ func (n *Node) NewRuntimeHostHandler() host.RuntimeHandler { return runtimeRegistry.NewRuntimeHostHandler(&nodeEnvironment{n}, n.Runtime, n.Consensus) } -// NewRuntimeHostNotifier implements RuntimeHostHandlerFactory. -func (n *Node) NewRuntimeHostNotifier(host host.Runtime) protocol.Notifier { - return runtimeRegistry.NewRuntimeHostNotifier(n.Runtime, host, n.Consensus) -} - type nodeEnvironment struct { n *Node } diff --git a/go/worker/keymanager/handler.go b/go/worker/keymanager/handler.go index 77d18544775..f5191cc1640 100644 --- a/go/worker/keymanager/handler.go +++ b/go/worker/keymanager/handler.go @@ -6,7 +6,6 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/identity" consensusAPI "github.com/oasisprotocol/oasis-core/go/consensus/api" "github.com/oasisprotocol/oasis-core/go/runtime/host" - "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol" runtimeKeymanager "github.com/oasisprotocol/oasis-core/go/runtime/keymanager/api" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" "github.com/oasisprotocol/oasis-core/go/runtime/txpool" @@ -30,11 +29,6 @@ func (w *Worker) NewRuntimeHostHandler() host.RuntimeHandler { }, w.runtime, w.commonWorker.Consensus) } -// NewRuntimeHostNotifier implements workerCommon.RuntimeHostHandlerFactory. -func (w *Worker) NewRuntimeHostNotifier(host host.Runtime) protocol.Notifier { - return runtimeRegistry.NewRuntimeHostNotifier(w.runtime, host, w.commonWorker.Consensus) -} - type workerEnvironment struct { w *Worker diff --git a/go/worker/keymanager/init.go b/go/worker/keymanager/init.go index 175d081ab27..11040becfd4 100644 --- a/go/worker/keymanager/init.go +++ b/go/worker/keymanager/init.go @@ -76,6 +76,9 @@ func New( return nil, fmt.Errorf("worker/keymanager: failed to create runtime host helpers: %w", err) } + // Prepare the runtime host notifier. + w.notifier = runtimeRegistry.NewRuntimeHostNotifier(w.runtime, w.RuntimeHostNode.GetHostedRuntime(), commonWorker.Consensus) + // Prepare watchers. w.kmNodeWatcher = newKmNodeWatcher(w.runtimeID, commonWorker.Consensus, w.peerMap, w.accessList, w.commonWorker.P2P.PeerManager().PeerTagger()) w.kmRuntimeWatcher = newKmRuntimeWatcher(w.runtimeID, commonWorker.Consensus, w.accessList) diff --git a/go/worker/keymanager/worker.go b/go/worker/keymanager/worker.go index 61fd9d88e93..924b5fae917 100644 --- a/go/worker/keymanager/worker.go +++ b/go/worker/keymanager/worker.go @@ -76,6 +76,7 @@ type Worker struct { // nolint: maligned commonWorker *workerCommon.Worker roleProvider registration.RoleProvider backend api.Backend + notifier protocol.Notifier enabled bool } @@ -453,18 +454,17 @@ func (w *Worker) worker() { // Set the runtime to the specified version. w.SetHostedRuntimeVersion(&comp.Version, nil) - // Start the runtime and its notifier. + // Start the runtime. hrt := w.GetHostedRuntime() - hrtNotifier := w.GetRuntimeHostNotifier() - hrtEventCh, hrtSub := hrt.WatchEvents() defer hrtSub.Close() hrt.Start() defer hrt.Stop() - hrtNotifier.Start() - defer hrtNotifier.Stop() + // Start the runtime host notifier. + w.notifier.Start() + defer w.notifier.Stop() // Ensure that the runtime version is active. if _, err := w.GetHostedRuntimeActiveVersion(); err != nil { From bbd6449465be3174e6936904c6749fea834fb39d Mon Sep 17 00:00:00 2001 From: Peter Nose Date: Fri, 14 Feb 2025 22:51:12 +0100 Subject: [PATCH 2/4] go/runtime/registry/handler: Remove runtime from handler factory --- go/runtime/registry/handler.go | 3 --- go/runtime/registry/host.go | 3 +-- go/worker/common/committee/node.go | 2 +- go/worker/common/committee/runtime_host.go | 5 ----- go/worker/keymanager/handler.go | 5 ----- go/worker/keymanager/init.go | 2 +- 6 files changed, 3 insertions(+), 17 deletions(-) diff --git a/go/runtime/registry/handler.go b/go/runtime/registry/handler.go index 4522b42a28a..cb991255043 100644 --- a/go/runtime/registry/handler.go +++ b/go/runtime/registry/handler.go @@ -44,9 +44,6 @@ type RuntimeHostHandlerEnvironment interface { // RuntimeHostHandlerFactory is an interface that can be used to create new runtime handlers and // notifiers when provisioning hosted runtimes. type RuntimeHostHandlerFactory interface { - // GetRuntime returns the registered runtime for which a runtime host handler is to be created. - GetRuntime() Runtime - // NewRuntimeHostHandler creates a new runtime host handler. NewRuntimeHostHandler() host.RuntimeHandler } diff --git a/go/runtime/registry/host.go b/go/runtime/registry/host.go index ad2e3220bce..90cd42023e1 100644 --- a/go/runtime/registry/host.go +++ b/go/runtime/registry/host.go @@ -29,8 +29,7 @@ type RuntimeHostNode struct { } // NewRuntimeHostNode creates a new runtime host node. -func NewRuntimeHostNode(factory RuntimeHostHandlerFactory) (*RuntimeHostNode, error) { - runtime := factory.GetRuntime() +func NewRuntimeHostNode(runtime Runtime, factory RuntimeHostHandlerFactory) (*RuntimeHostNode, error) { h := composite.NewHost(runtime.ID()) rr := host.NewRichRuntime(h) diff --git a/go/worker/common/committee/node.go b/go/worker/common/committee/node.go index 1615090e0fc..14053962f4b 100644 --- a/go/worker/common/committee/node.go +++ b/go/worker/common/committee/node.go @@ -906,7 +906,7 @@ func NewNode( n.KeyManagerClient = NewKeyManagerClientWrapper(p2pHost, consensus, chainContext, n.logger) // Prepare the runtime host node helpers. - rhn, err := runtimeRegistry.NewRuntimeHostNode(n) + rhn, err := runtimeRegistry.NewRuntimeHostNode(runtime, n) if err != nil { return nil, err } diff --git a/go/worker/common/committee/runtime_host.go b/go/worker/common/committee/runtime_host.go index 5bc53bbfe76..a8d25d424df 100644 --- a/go/worker/common/committee/runtime_host.go +++ b/go/worker/common/committee/runtime_host.go @@ -9,11 +9,6 @@ import ( "github.com/oasisprotocol/oasis-core/go/runtime/txpool" ) -// GetRuntime implements RuntimeHostHandlerFactory. -func (n *Node) GetRuntime() runtimeRegistry.Runtime { - return n.Runtime -} - // NewRuntimeHostHandler implements RuntimeHostHandlerFactory. func (n *Node) NewRuntimeHostHandler() host.RuntimeHandler { return runtimeRegistry.NewRuntimeHostHandler(&nodeEnvironment{n}, n.Runtime, n.Consensus) diff --git a/go/worker/keymanager/handler.go b/go/worker/keymanager/handler.go index f5191cc1640..985da8fd28b 100644 --- a/go/worker/keymanager/handler.go +++ b/go/worker/keymanager/handler.go @@ -12,11 +12,6 @@ import ( committeeCommon "github.com/oasisprotocol/oasis-core/go/worker/common/committee" ) -// GetRuntime implements workerCommon.RuntimeHostHandlerFactory. -func (w *Worker) GetRuntime() runtimeRegistry.Runtime { - return w.runtime -} - // NewRuntimeHostHandler implements workerCommon.RuntimeHostHandlerFactory. func (w *Worker) NewRuntimeHostHandler() host.RuntimeHandler { kmCli := committeeCommon.NewKeyManagerClientWrapper(w.commonWorker.P2P, w.commonWorker.Consensus, w.commonWorker.ChainContext, w.logger) diff --git a/go/worker/keymanager/init.go b/go/worker/keymanager/init.go index 11040becfd4..aaacd73d7b0 100644 --- a/go/worker/keymanager/init.go +++ b/go/worker/keymanager/init.go @@ -71,7 +71,7 @@ func New( } // Prepare the runtime host node helpers. - w.RuntimeHostNode, err = runtimeRegistry.NewRuntimeHostNode(w) + w.RuntimeHostNode, err = runtimeRegistry.NewRuntimeHostNode(w.runtime, w) if err != nil { return nil, fmt.Errorf("worker/keymanager: failed to create runtime host helpers: %w", err) } From 3a6f27a11a9ce14ed39d2c2a9427114b8a688ee1 Mon Sep 17 00:00:00 2001 From: Peter Nose Date: Fri, 14 Feb 2025 23:05:30 +0100 Subject: [PATCH 3/4] go/worker/common/committee/node: Decouple runtime host handler --- go/runtime/registry/handler.go | 7 ------- go/runtime/registry/host.go | 3 +-- go/worker/common/committee/node.go | 5 ++++- go/worker/common/committee/runtime_host.go | 6 ------ go/worker/keymanager/handler.go | 18 +----------------- go/worker/keymanager/init.go | 10 +++++++++- go/worker/keymanager/worker.go | 10 ++++++---- 7 files changed, 21 insertions(+), 38 deletions(-) diff --git a/go/runtime/registry/handler.go b/go/runtime/registry/handler.go index cb991255043..514989f701f 100644 --- a/go/runtime/registry/handler.go +++ b/go/runtime/registry/handler.go @@ -41,13 +41,6 @@ type RuntimeHostHandlerEnvironment interface { GetRuntimeRegistry() Registry } -// RuntimeHostHandlerFactory is an interface that can be used to create new runtime handlers and -// notifiers when provisioning hosted runtimes. -type RuntimeHostHandlerFactory interface { - // NewRuntimeHostHandler creates a new runtime host handler. - NewRuntimeHostHandler() host.RuntimeHandler -} - // RuntimeHostHandler is a runtime host handler suitable for compute runtimes. It provides the // required set of methods for interacting with the outside world. type runtimeHostHandler struct { diff --git a/go/runtime/registry/host.go b/go/runtime/registry/host.go index 90cd42023e1..1efb3ecf370 100644 --- a/go/runtime/registry/host.go +++ b/go/runtime/registry/host.go @@ -29,11 +29,10 @@ type RuntimeHostNode struct { } // NewRuntimeHostNode creates a new runtime host node. -func NewRuntimeHostNode(runtime Runtime, factory RuntimeHostHandlerFactory) (*RuntimeHostNode, error) { +func NewRuntimeHostNode(runtime Runtime, handler host.RuntimeHandler) (*RuntimeHostNode, error) { h := composite.NewHost(runtime.ID()) rr := host.NewRichRuntime(h) - handler := factory.NewRuntimeHostHandler() provisioner := runtime.HostProvisioner() return &RuntimeHostNode{ diff --git a/go/worker/common/committee/node.go b/go/worker/common/committee/node.go index 14053962f4b..a1a4a12fd20 100644 --- a/go/worker/common/committee/node.go +++ b/go/worker/common/committee/node.go @@ -905,8 +905,11 @@ func NewNode( // Prepare the key manager client wrapper. n.KeyManagerClient = NewKeyManagerClientWrapper(p2pHost, consensus, chainContext, n.logger) + // Prepare the runtime host handler. + handler := runtimeRegistry.NewRuntimeHostHandler(&nodeEnvironment{n}, n.Runtime, n.Consensus) + // Prepare the runtime host node helpers. - rhn, err := runtimeRegistry.NewRuntimeHostNode(runtime, n) + rhn, err := runtimeRegistry.NewRuntimeHostNode(runtime, handler) if err != nil { return nil, err } diff --git a/go/worker/common/committee/runtime_host.go b/go/worker/common/committee/runtime_host.go index a8d25d424df..a3ed9b900df 100644 --- a/go/worker/common/committee/runtime_host.go +++ b/go/worker/common/committee/runtime_host.go @@ -3,17 +3,11 @@ package committee import ( "github.com/oasisprotocol/oasis-core/go/common/identity" consensusAPI "github.com/oasisprotocol/oasis-core/go/consensus/api" - "github.com/oasisprotocol/oasis-core/go/runtime/host" runtimeKeymanager "github.com/oasisprotocol/oasis-core/go/runtime/keymanager/api" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" "github.com/oasisprotocol/oasis-core/go/runtime/txpool" ) -// NewRuntimeHostHandler implements RuntimeHostHandlerFactory. -func (n *Node) NewRuntimeHostHandler() host.RuntimeHandler { - return runtimeRegistry.NewRuntimeHostHandler(&nodeEnvironment{n}, n.Runtime, n.Consensus) -} - type nodeEnvironment struct { n *Node } diff --git a/go/worker/keymanager/handler.go b/go/worker/keymanager/handler.go index 985da8fd28b..ab9e095b138 100644 --- a/go/worker/keymanager/handler.go +++ b/go/worker/keymanager/handler.go @@ -5,34 +5,18 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/identity" consensusAPI "github.com/oasisprotocol/oasis-core/go/consensus/api" - "github.com/oasisprotocol/oasis-core/go/runtime/host" runtimeKeymanager "github.com/oasisprotocol/oasis-core/go/runtime/keymanager/api" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" "github.com/oasisprotocol/oasis-core/go/runtime/txpool" - committeeCommon "github.com/oasisprotocol/oasis-core/go/worker/common/committee" ) -// NewRuntimeHostHandler implements workerCommon.RuntimeHostHandlerFactory. -func (w *Worker) NewRuntimeHostHandler() host.RuntimeHandler { - kmCli := committeeCommon.NewKeyManagerClientWrapper(w.commonWorker.P2P, w.commonWorker.Consensus, w.commonWorker.ChainContext, w.logger) - runtimeID := w.runtime.ID() - kmCli.SetKeyManagerID(&runtimeID) - - return runtimeRegistry.NewRuntimeHostHandler(&workerEnvironment{ - w: w, - kmCli: kmCli, - }, w.runtime, w.commonWorker.Consensus) -} - type workerEnvironment struct { w *Worker - - kmCli *committeeCommon.KeyManagerClientWrapper } // GetKeyManagerClient implements RuntimeHostHandlerEnvironment. func (env *workerEnvironment) GetKeyManagerClient() (runtimeKeymanager.Client, error) { - return env.kmCli, nil + return env.w.keyManagerClient, nil } // GetTxPool implements RuntimeHostHandlerEnvironment. diff --git a/go/worker/keymanager/init.go b/go/worker/keymanager/init.go index aaacd73d7b0..10c2a0f5555 100644 --- a/go/worker/keymanager/init.go +++ b/go/worker/keymanager/init.go @@ -11,6 +11,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/keymanager/api" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" workerCommon "github.com/oasisprotocol/oasis-core/go/worker/common" + committeeCommon "github.com/oasisprotocol/oasis-core/go/worker/common/committee" workerKeymanager "github.com/oasisprotocol/oasis-core/go/worker/keymanager/api" "github.com/oasisprotocol/oasis-core/go/worker/keymanager/p2p" "github.com/oasisprotocol/oasis-core/go/worker/registration" @@ -70,8 +71,15 @@ func New( return nil, fmt.Errorf("worker/keymanager: failed to get runtime: %w", err) } + // Prepare key manager client. + w.keyManagerClient = committeeCommon.NewKeyManagerClientWrapper(w.commonWorker.P2P, w.commonWorker.Consensus, w.commonWorker.ChainContext, w.logger) + w.keyManagerClient.SetKeyManagerID(&w.runtimeID) + + // Prepare the runtime host handler. + handler := runtimeRegistry.NewRuntimeHostHandler(&workerEnvironment{w}, w.runtime, w.commonWorker.Consensus) + // Prepare the runtime host node helpers. - w.RuntimeHostNode, err = runtimeRegistry.NewRuntimeHostNode(w.runtime, w) + w.RuntimeHostNode, err = runtimeRegistry.NewRuntimeHostNode(w.runtime, handler) if err != nil { return nil, fmt.Errorf("worker/keymanager: failed to create runtime host helpers: %w", err) } diff --git a/go/worker/keymanager/worker.go b/go/worker/keymanager/worker.go index 924b5fae917..c8ccd7c6a1a 100644 --- a/go/worker/keymanager/worker.go +++ b/go/worker/keymanager/worker.go @@ -29,6 +29,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" workerCommon "github.com/oasisprotocol/oasis-core/go/worker/common" + commonCommittee "github.com/oasisprotocol/oasis-core/go/worker/common/committee" workerKeymanager "github.com/oasisprotocol/oasis-core/go/worker/keymanager/api" "github.com/oasisprotocol/oasis-core/go/worker/registration" ) @@ -73,10 +74,11 @@ type Worker struct { // nolint: maligned peerMap *PeerMap accessList *AccessList - commonWorker *workerCommon.Worker - roleProvider registration.RoleProvider - backend api.Backend - notifier protocol.Notifier + commonWorker *workerCommon.Worker + roleProvider registration.RoleProvider + backend api.Backend + notifier protocol.Notifier + keyManagerClient *commonCommittee.KeyManagerClientWrapper enabled bool } From bf142b9d3e2ff682172bbd4fd9b4d17ddd423213 Mon Sep 17 00:00:00 2001 From: Peter Nose Date: Sat, 15 Feb 2025 18:52:06 +0100 Subject: [PATCH 4/4] go/runtime/registry: Decouple host provisioner from runtime registry --- .changelog/6073.trivial.md | 0 go/oasis-node/cmd/node/node.go | 17 +- go/oasis-node/cmd/node/node_control.go | 5 +- go/runtime/host/provisioner/provisioner.go | 203 +++++++++++++++++++++ go/runtime/registry/config.go | 160 ---------------- go/runtime/registry/host.go | 6 +- go/runtime/registry/registry.go | 41 +---- go/worker/common/committee/node.go | 3 +- go/worker/common/worker.go | 5 + go/worker/keymanager/init.go | 4 +- 10 files changed, 225 insertions(+), 219 deletions(-) create mode 100644 .changelog/6073.trivial.md create mode 100644 go/runtime/host/provisioner/provisioner.go diff --git a/.changelog/6073.trivial.md b/.changelog/6073.trivial.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/go/oasis-node/cmd/node/node.go b/go/oasis-node/cmd/node/node.go index 677389cffa8..3f09a42dafb 100644 --- a/go/oasis-node/cmd/node/node.go +++ b/go/oasis-node/cmd/node/node.go @@ -22,8 +22,6 @@ import ( controlAPI "github.com/oasisprotocol/oasis-core/go/control/api" genesisAPI "github.com/oasisprotocol/oasis-core/go/genesis/api" governanceAPI "github.com/oasisprotocol/oasis-core/go/governance/api" - "github.com/oasisprotocol/oasis-core/go/ias" - iasAPI "github.com/oasisprotocol/oasis-core/go/ias/api" keymanagerAPI "github.com/oasisprotocol/oasis-core/go/keymanager/api" cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/background" @@ -33,6 +31,8 @@ import ( p2pAPI "github.com/oasisprotocol/oasis-core/go/p2p/api" registryAPI "github.com/oasisprotocol/oasis-core/go/registry/api" roothashAPI "github.com/oasisprotocol/oasis-core/go/roothash/api" + "github.com/oasisprotocol/oasis-core/go/runtime/host" + "github.com/oasisprotocol/oasis-core/go/runtime/host/provisioner" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" scheduler "github.com/oasisprotocol/oasis-core/go/scheduler/api" "github.com/oasisprotocol/oasis-core/go/sentry" @@ -76,9 +76,9 @@ type Node struct { Genesis genesisAPI.Provider Identity *identity.Identity Sentry sentryAPI.Backend - IAS []iasAPI.Endpoint RuntimeRegistry runtimeRegistry.Registry + Provisioner host.Provisioner CommonWorker *workerCommon.Worker ExecutorWorker *executor.Worker @@ -218,17 +218,14 @@ func (n *Node) initRuntimeWorkers() error { return err } - // Initialize the IAS proxy client. - n.IAS, err = ias.New(n.Identity) + // Initialize runtime provisioner. + n.Provisioner, err = provisioner.New(n.dataDir, n.commonStore, n.Identity, n.Consensus) if err != nil { - n.logger.Error("failed to initialize IAS proxy client", - "err", err, - ) return err } // Initialize the node's runtime registry. - n.RuntimeRegistry, err = runtimeRegistry.New(n.svcMgr.Ctx, n.dataDir, n.commonStore, n.Identity, n.Consensus, n.IAS) + n.RuntimeRegistry, err = runtimeRegistry.New(n.svcMgr.Ctx, n.dataDir, n.Consensus) if err != nil { return err } @@ -245,6 +242,7 @@ func (n *Node) initRuntimeWorkers() error { n.P2P, n.Consensus.KeyManager(), n.RuntimeRegistry, + n.Provisioner, ) if err != nil { n.logger.Error("failed to initialize common worker", @@ -306,6 +304,7 @@ func (n *Node) initRuntimeWorkers() error { n.CommonWorker, n.RegistrationWorker, n.Consensus.KeyManager(), + n.Provisioner, ) if err != nil { return err diff --git a/go/oasis-node/cmd/node/node_control.go b/go/oasis-node/cmd/node/node_control.go index 00bb8280515..bbd8383fdc0 100644 --- a/go/oasis-node/cmd/node/node_control.go +++ b/go/oasis-node/cmd/node/node_control.go @@ -342,10 +342,7 @@ func (n *Node) getRuntimeStatus(ctx context.Context) (map[common.Namespace]contr } // Fetch provisioner type. - status.Provisioner = "none" - if provisioner := rt.HostProvisioner(); provisioner != nil { - status.Provisioner = provisioner.Name() - } + status.Provisioner = n.Provisioner.Name() // Fetch the status of all components associated with the runtime. for _, comp := range n.RuntimeRegistry.GetBundleRegistry().Components(rt.ID()) { diff --git a/go/runtime/host/provisioner/provisioner.go b/go/runtime/host/provisioner/provisioner.go new file mode 100644 index 00000000000..2c4b44dd49b --- /dev/null +++ b/go/runtime/host/provisioner/provisioner.go @@ -0,0 +1,203 @@ +package provisioner + +import ( + "context" + "fmt" + "path/filepath" + + "github.com/oasisprotocol/oasis-core/go/common/identity" + "github.com/oasisprotocol/oasis-core/go/common/persistent" + "github.com/oasisprotocol/oasis-core/go/common/sgx/pcs" + "github.com/oasisprotocol/oasis-core/go/config" + consensus "github.com/oasisprotocol/oasis-core/go/consensus/api" + "github.com/oasisprotocol/oasis-core/go/ias" + iasAPI "github.com/oasisprotocol/oasis-core/go/ias/api" + cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" + "github.com/oasisprotocol/oasis-core/go/runtime/bundle/component" + rtConfig "github.com/oasisprotocol/oasis-core/go/runtime/config" + runtimeHost "github.com/oasisprotocol/oasis-core/go/runtime/host" + hostComposite "github.com/oasisprotocol/oasis-core/go/runtime/host/composite" + hostLoadBalance "github.com/oasisprotocol/oasis-core/go/runtime/host/loadbalance" + hostMock "github.com/oasisprotocol/oasis-core/go/runtime/host/mock" + hostProtocol "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol" + hostSandbox "github.com/oasisprotocol/oasis-core/go/runtime/host/sandbox" + hostSgx "github.com/oasisprotocol/oasis-core/go/runtime/host/sgx" + hostTdx "github.com/oasisprotocol/oasis-core/go/runtime/host/tdx" + "github.com/oasisprotocol/oasis-core/go/runtime/registry" +) + +// New creates a new runtime provisioner. +// +// This helper function creates a provisioner capable of provisioning runtimes +// with or without a Trusted Execution Environment (TEE), such as Intel SGX +// or TDX. If the debug mock flag is enabled, the TEE will be mocked. +func New( + dataDir string, + commonStore *persistent.CommonStore, + identity *identity.Identity, + consensus consensus.Backend, +) (runtimeHost.Provisioner, error) { + // Initialize the IAS proxy client. + ias, err := ias.New(identity) + if err != nil { + return nil, fmt.Errorf("failed to initialize IAS proxy client: %w", err) + } + + // Configure host environment information. + hostInfo, err := createHostInfo(consensus) + if err != nil { + return nil, err + } + + // Create the PCS client and quote service. + qs, err := createCachingQuoteService(commonStore) + if err != nil { + return nil, err + } + + // Create runtime provisioner. + return createProvisioner(dataDir, commonStore, identity, consensus, hostInfo, ias, qs) +} + +func createHostInfo(consensus consensus.Backend) (*hostProtocol.HostInfo, error) { + cs, err := consensus.GetStatus(context.Background()) + if err != nil { + return nil, fmt.Errorf("failed to get consensus layer status: %w", err) + } + + chainCtx, err := consensus.GetChainContext(context.Background()) + if err != nil { + return nil, fmt.Errorf("failed to get chain context: %w", err) + } + + return &hostProtocol.HostInfo{ + ConsensusBackend: cs.Backend, + ConsensusProtocolVersion: cs.Version, + ConsensusChainContext: chainCtx, + }, nil +} + +func createCachingQuoteService(commonStore *persistent.CommonStore) (pcs.QuoteService, error) { + pc, err := pcs.NewHTTPClient(&pcs.HTTPClientConfig{ + // TODO: Support configuring the API key. + }) + if err != nil { + return nil, fmt.Errorf("failed to create PCS HTTP client: %w", err) + } + + qs := pcs.NewCachingQuoteService(pc, commonStore) + + return qs, nil +} + +func createProvisioner( + dataDir string, + commonStore *persistent.CommonStore, + identity *identity.Identity, + consensus consensus.Backend, + hostInfo *hostProtocol.HostInfo, + ias []iasAPI.Endpoint, + qs pcs.QuoteService, +) (runtimeHost.Provisioner, error) { + var err error + var insecureNoSandbox bool + + attestInterval := config.GlobalConfig.Runtime.AttestInterval + sandboxBinary := config.GlobalConfig.Runtime.SandboxBinary + sgxLoader := config.GlobalConfig.Runtime.SGXLoader + insecureMock := config.GlobalConfig.Runtime.DebugMockTEE + + // Support legacy configuration where the runtime environment determines + // whether the TEE should be mocked. + if config.GlobalConfig.Runtime.Environment == rtConfig.RuntimeEnvironmentSGXMock { + insecureMock = true + } + + // Register provisioners based on the configured provisioner. + provisioners := make(map[component.TEEKind]runtimeHost.Provisioner) + switch p := config.GlobalConfig.Runtime.Provisioner; p { + case rtConfig.RuntimeProvisionerMock: + // Mock provisioner, only supported when the runtime requires no TEE hardware. + if !cmdFlags.DebugDontBlameOasis() { + return nil, fmt.Errorf("mock provisioner requires use of unsafe debug flags") + } + + provisioners[component.TEEKindNone] = hostMock.NewProvisioner() + case rtConfig.RuntimeProvisionerUnconfined: + // Unconfined provisioner, can be used with no TEE or with Intel SGX. + if !cmdFlags.DebugDontBlameOasis() { + return nil, fmt.Errorf("unconfined provisioner requires use of unsafe debug flags") + } + + insecureNoSandbox = true + + fallthrough + case rtConfig.RuntimeProvisionerSandboxed: + // Sandboxed provisioner, can be used with no TEE or with Intel SGX. + + // Configure the non-TEE provisioner. + provisioners[component.TEEKindNone], err = hostSandbox.NewProvisioner(hostSandbox.Config{ + HostInfo: hostInfo, + InsecureNoSandbox: insecureNoSandbox, + SandboxBinaryPath: sandboxBinary, + }) + if err != nil { + return nil, fmt.Errorf("failed to create runtime provisioner: %w", err) + } + + // Configure the Intel SGX provisioner. + if insecureMock && !cmdFlags.DebugDontBlameOasis() { + return nil, fmt.Errorf("mock SGX requires use of unsafe debug flags") + } + + if !insecureMock && sgxLoader == "" { + // SGX may be needed, but we don't have a loader configured. + break + } + + provisioners[component.TEEKindSGX], err = hostSgx.NewProvisioner(hostSgx.Config{ + HostInfo: hostInfo, + CommonStore: commonStore, + LoaderPath: sgxLoader, + IAS: ias, + PCS: qs, + Consensus: consensus, + Identity: identity, + SandboxBinaryPath: sandboxBinary, + InsecureNoSandbox: insecureNoSandbox, + InsecureMock: insecureMock, + RuntimeAttestInterval: attestInterval, + }) + if err != nil { + return nil, fmt.Errorf("failed to create SGX runtime provisioner: %w", err) + } + default: + return nil, fmt.Errorf("unsupported runtime provisioner: %s", p) + } + + // Configure TDX provisioner. + // TODO: Allow provisioner selection in the future, currently we only have QEMU. + provisioners[component.TEEKindTDX], err = hostTdx.NewQemuProvisioner(hostTdx.QemuConfig{ + DataDir: filepath.Join(dataDir, registry.RuntimesDir), + HostInfo: hostInfo, + CommonStore: commonStore, + PCS: qs, + Consensus: consensus, + Identity: identity, + RuntimeAttestInterval: attestInterval, + }) + if err != nil { + return nil, fmt.Errorf("failed to create TDX runtime provisioner: %w", err) + } + + // Configure optional load balancing. + for tee, rp := range provisioners { + numInstances := int(config.GlobalConfig.Runtime.LoadBalancer.NumInstances) + provisioners[tee] = hostLoadBalance.NewProvisioner(rp, numInstances) + } + + // Create a composite provisioner to provision the individual components. + provisioner := hostComposite.NewProvisioner(provisioners) + + return provisioner, nil +} diff --git a/go/runtime/registry/config.go b/go/runtime/registry/config.go index d7330464224..3e607cadb6c 100644 --- a/go/runtime/registry/config.go +++ b/go/runtime/registry/config.go @@ -1,10 +1,8 @@ package registry import ( - "context" "fmt" "maps" - "path/filepath" "slices" "strings" "time" @@ -12,25 +10,10 @@ import ( "github.com/spf13/viper" "github.com/oasisprotocol/oasis-core/go/common" - "github.com/oasisprotocol/oasis-core/go/common/identity" - "github.com/oasisprotocol/oasis-core/go/common/persistent" - "github.com/oasisprotocol/oasis-core/go/common/sgx/pcs" "github.com/oasisprotocol/oasis-core/go/config" - consensus "github.com/oasisprotocol/oasis-core/go/consensus/api" - ias "github.com/oasisprotocol/oasis-core/go/ias/api" cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" "github.com/oasisprotocol/oasis-core/go/runtime/bundle" - "github.com/oasisprotocol/oasis-core/go/runtime/bundle/component" - rtConfig "github.com/oasisprotocol/oasis-core/go/runtime/config" "github.com/oasisprotocol/oasis-core/go/runtime/history" - runtimeHost "github.com/oasisprotocol/oasis-core/go/runtime/host" - hostComposite "github.com/oasisprotocol/oasis-core/go/runtime/host/composite" - hostLoadBalance "github.com/oasisprotocol/oasis-core/go/runtime/host/loadbalance" - hostMock "github.com/oasisprotocol/oasis-core/go/runtime/host/mock" - hostProtocol "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol" - hostSandbox "github.com/oasisprotocol/oasis-core/go/runtime/host/sandbox" - hostSgx "github.com/oasisprotocol/oasis-core/go/runtime/host/sgx" - hostTdx "github.com/oasisprotocol/oasis-core/go/runtime/host/tdx" ) func getLocalConfig(runtimeID common.Namespace) map[string]interface{} { @@ -95,149 +78,6 @@ func getConfiguredRuntimeIDs() ([]common.Namespace, error) { return slices.Collect(maps.Keys(runtimes)), nil } -func createHostInfo(consensus consensus.Backend) (*hostProtocol.HostInfo, error) { - cs, err := consensus.GetStatus(context.Background()) - if err != nil { - return nil, fmt.Errorf("failed to get consensus layer status: %w", err) - } - - chainCtx, err := consensus.GetChainContext(context.Background()) - if err != nil { - return nil, fmt.Errorf("failed to get chain context: %w", err) - } - - return &hostProtocol.HostInfo{ - ConsensusBackend: cs.Backend, - ConsensusProtocolVersion: cs.Version, - ConsensusChainContext: chainCtx, - }, nil -} - -func createProvisioner( - dataDir string, - commonStore *persistent.CommonStore, - identity *identity.Identity, - consensus consensus.Backend, - hostInfo *hostProtocol.HostInfo, - ias []ias.Endpoint, - qs pcs.QuoteService, -) (runtimeHost.Provisioner, error) { - var err error - var insecureNoSandbox bool - - attestInterval := config.GlobalConfig.Runtime.AttestInterval - sandboxBinary := config.GlobalConfig.Runtime.SandboxBinary - sgxLoader := config.GlobalConfig.Runtime.SGXLoader - insecureMock := config.GlobalConfig.Runtime.DebugMockTEE - - // Support legacy configuration where the runtime environment determines - // whether the TEE should be mocked. - if config.GlobalConfig.Runtime.Environment == rtConfig.RuntimeEnvironmentSGXMock { - insecureMock = true - } - - // Register provisioners based on the configured provisioner. - provisioners := make(map[component.TEEKind]runtimeHost.Provisioner) - switch p := config.GlobalConfig.Runtime.Provisioner; p { - case rtConfig.RuntimeProvisionerMock: - // Mock provisioner, only supported when the runtime requires no TEE hardware. - if !cmdFlags.DebugDontBlameOasis() { - return nil, fmt.Errorf("mock provisioner requires use of unsafe debug flags") - } - - provisioners[component.TEEKindNone] = hostMock.NewProvisioner() - case rtConfig.RuntimeProvisionerUnconfined: - // Unconfined provisioner, can be used with no TEE or with Intel SGX. - if !cmdFlags.DebugDontBlameOasis() { - return nil, fmt.Errorf("unconfined provisioner requires use of unsafe debug flags") - } - - insecureNoSandbox = true - - fallthrough - case rtConfig.RuntimeProvisionerSandboxed: - // Sandboxed provisioner, can be used with no TEE or with Intel SGX. - - // Configure the non-TEE provisioner. - provisioners[component.TEEKindNone], err = hostSandbox.NewProvisioner(hostSandbox.Config{ - HostInfo: hostInfo, - InsecureNoSandbox: insecureNoSandbox, - SandboxBinaryPath: sandboxBinary, - }) - if err != nil { - return nil, fmt.Errorf("failed to create runtime provisioner: %w", err) - } - - // Configure the Intel SGX provisioner. - if insecureMock && !cmdFlags.DebugDontBlameOasis() { - return nil, fmt.Errorf("mock SGX requires use of unsafe debug flags") - } - - if !insecureMock && sgxLoader == "" { - // SGX may be needed, but we don't have a loader configured. - break - } - - provisioners[component.TEEKindSGX], err = hostSgx.NewProvisioner(hostSgx.Config{ - HostInfo: hostInfo, - CommonStore: commonStore, - LoaderPath: sgxLoader, - IAS: ias, - PCS: qs, - Consensus: consensus, - Identity: identity, - SandboxBinaryPath: sandboxBinary, - InsecureNoSandbox: insecureNoSandbox, - InsecureMock: insecureMock, - RuntimeAttestInterval: attestInterval, - }) - if err != nil { - return nil, fmt.Errorf("failed to create SGX runtime provisioner: %w", err) - } - default: - return nil, fmt.Errorf("unsupported runtime provisioner: %s", p) - } - - // Configure TDX provisioner. - // TODO: Allow provisioner selection in the future, currently we only have QEMU. - provisioners[component.TEEKindTDX], err = hostTdx.NewQemuProvisioner(hostTdx.QemuConfig{ - DataDir: filepath.Join(dataDir, RuntimesDir), - HostInfo: hostInfo, - CommonStore: commonStore, - PCS: qs, - Consensus: consensus, - Identity: identity, - RuntimeAttestInterval: attestInterval, - }) - if err != nil { - return nil, fmt.Errorf("failed to create TDX runtime provisioner: %w", err) - } - - // Configure optional load balancing. - for tee, rp := range provisioners { - numInstances := int(config.GlobalConfig.Runtime.LoadBalancer.NumInstances) - provisioners[tee] = hostLoadBalance.NewProvisioner(rp, numInstances) - } - - // Create a composite provisioner to provision the individual components. - provisioner := hostComposite.NewProvisioner(provisioners) - - return provisioner, nil -} - -func createCachingQuoteService(commonStore *persistent.CommonStore) (pcs.QuoteService, error) { - pc, err := pcs.NewHTTPClient(&pcs.HTTPClientConfig{ - // TODO: Support configuring the API key. - }) - if err != nil { - return nil, fmt.Errorf("failed to create PCS HTTP client: %w", err) - } - - qs := pcs.NewCachingQuoteService(pc, commonStore) - - return qs, nil -} - func createHistoryFactory() (history.Factory, error) { var pruneFactory history.PrunerFactory strategy := config.GlobalConfig.Runtime.Prune.Strategy diff --git a/go/runtime/registry/host.go b/go/runtime/registry/host.go index 1efb3ecf370..9ab73c2443e 100644 --- a/go/runtime/registry/host.go +++ b/go/runtime/registry/host.go @@ -22,19 +22,17 @@ type RuntimeHostNode struct { rr host.RichRuntime runtime Runtime - handler host.RuntimeHandler provisioner host.Provisioner + handler host.RuntimeHandler rofls map[component.ID]version.Version } // NewRuntimeHostNode creates a new runtime host node. -func NewRuntimeHostNode(runtime Runtime, handler host.RuntimeHandler) (*RuntimeHostNode, error) { +func NewRuntimeHostNode(runtime Runtime, provisioner host.Provisioner, handler host.RuntimeHandler) (*RuntimeHostNode, error) { h := composite.NewHost(runtime.ID()) rr := host.NewRichRuntime(h) - provisioner := runtime.HostProvisioner() - return &RuntimeHostNode{ host: h, rr: rr, diff --git a/go/runtime/registry/registry.go b/go/runtime/registry/registry.go index be4e2257ea1..91d0d2f4000 100644 --- a/go/runtime/registry/registry.go +++ b/go/runtime/registry/registry.go @@ -11,21 +11,17 @@ import ( "github.com/oasisprotocol/oasis-core/go/common" "github.com/oasisprotocol/oasis-core/go/common/crypto/hash" - "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/pubsub" "github.com/oasisprotocol/oasis-core/go/common/service" cmSync "github.com/oasisprotocol/oasis-core/go/common/sync" "github.com/oasisprotocol/oasis-core/go/config" consensus "github.com/oasisprotocol/oasis-core/go/consensus/api" - ias "github.com/oasisprotocol/oasis-core/go/ias/api" registry "github.com/oasisprotocol/oasis-core/go/registry/api" roothash "github.com/oasisprotocol/oasis-core/go/roothash/api" "github.com/oasisprotocol/oasis-core/go/runtime/bundle" runtimeClient "github.com/oasisprotocol/oasis-core/go/runtime/client/api" "github.com/oasisprotocol/oasis-core/go/runtime/history" - runtimeHost "github.com/oasisprotocol/oasis-core/go/runtime/host" "github.com/oasisprotocol/oasis-core/go/runtime/localstorage" storageAPI "github.com/oasisprotocol/oasis-core/go/storage/api" ) @@ -110,9 +106,6 @@ type Runtime interface { // LocalStorage returns the per-runtime local storage. LocalStorage() localstorage.LocalStorage - - // HostProvisioner returns the runtime host provisioner when available. Otherwise returns nil. - HostProvisioner() runtimeHost.Provisioner } type runtime struct { // nolint: maligned @@ -137,8 +130,6 @@ type runtime struct { // nolint: maligned activeDescriptorCh chan struct{} activeDescriptorNotifier *pubsub.Broker - hostProvisioner runtimeHost.Provisioner - bundleRegistry *bundle.Registry bundleManager *bundle.Manager @@ -150,7 +141,6 @@ func newRuntime( managed bool, dataDir string, consensus consensus.Backend, - provisioner runtimeHost.Provisioner, bundleRegistry *bundle.Registry, bundleManager *bundle.Manager, ) (*runtime, error) { @@ -179,7 +169,6 @@ func newRuntime( registryDescriptorNotifier: pubsub.NewBroker(true), activeDescriptorCh: make(chan struct{}), activeDescriptorNotifier: pubsub.NewBroker(true), - hostProvisioner: provisioner, bundleRegistry: bundleRegistry, bundleManager: bundleManager, logger: logger, @@ -281,11 +270,6 @@ func (r *runtime) LocalStorage() localstorage.LocalStorage { return r.localStorage } -// HostProvisioner implements Runtime. -func (r *runtime) HostProvisioner() runtimeHost.Provisioner { - return r.hostProvisioner -} - // start starts the runtime worker. func (r *runtime) start() { r.startOne.TryStart(r.run) @@ -485,7 +469,6 @@ type runtimeRegistry struct { runtimes map[common.Namespace]*runtime - provisioner runtimeHost.Provisioner historyFactory history.Factory bundleRegistry *bundle.Registry @@ -534,7 +517,7 @@ func (r *runtimeRegistry) NewRuntime(ctx context.Context, runtimeID common.Names return nil, fmt.Errorf("runtime/registry: runtime already registered: %s", runtimeID) } - rt, err := newRuntime(runtimeID, managed, r.dataDir, r.consensus, r.provisioner, r.bundleRegistry, r.bundleManager) + rt, err := newRuntime(runtimeID, managed, r.dataDir, r.consensus, r.bundleRegistry, r.bundleManager) if err != nil { return nil, err } @@ -665,10 +648,7 @@ func (r *runtimeRegistry) Init(ctx context.Context, runtimeIDs []common.Namespac func New( ctx context.Context, dataDir string, - commonStore *persistent.CommonStore, - identity *identity.Identity, consensus consensus.Backend, - ias []ias.Endpoint, ) (Registry, error) { // Get configured runtime IDs. runtimeIDs, err := getConfiguredRuntimeIDs() @@ -689,24 +669,6 @@ func New( return nil, err } - // Configure host environment information. - hostInfo, err := createHostInfo(consensus) - if err != nil { - return nil, err - } - - // Create the PCS client and quote service. - qs, err := createCachingQuoteService(commonStore) - if err != nil { - return nil, err - } - - // Create runtime provisioner. - provisioner, err := createProvisioner(dataDir, commonStore, identity, consensus, hostInfo, ias, qs) - if err != nil { - return nil, err - } - // Create runtime registry. r := &runtimeRegistry{ logger: logging.GetLogger("runtime/registry"), @@ -714,7 +676,6 @@ func New( dataDir: dataDir, consensus: consensus, runtimes: make(map[common.Namespace]*runtime), - provisioner: provisioner, historyFactory: historyFactory, bundleRegistry: bundleRegistry, bundleManager: bundleManager, diff --git a/go/worker/common/committee/node.go b/go/worker/common/committee/node.go index a1a4a12fd20..7f21c2082ab 100644 --- a/go/worker/common/committee/node.go +++ b/go/worker/common/committee/node.go @@ -859,6 +859,7 @@ func NewNode( chainContext string, hostNode control.NodeController, runtime runtimeRegistry.Runtime, + provisioner host.Provisioner, rtRegistry runtimeRegistry.Registry, identity *identity.Identity, keymanager keymanager.Backend, @@ -909,7 +910,7 @@ func NewNode( handler := runtimeRegistry.NewRuntimeHostHandler(&nodeEnvironment{n}, n.Runtime, n.Consensus) // Prepare the runtime host node helpers. - rhn, err := runtimeRegistry.NewRuntimeHostNode(runtime, handler) + rhn, err := runtimeRegistry.NewRuntimeHostNode(runtime, provisioner, handler) if err != nil { return nil, err } diff --git a/go/worker/common/worker.go b/go/worker/common/worker.go index 39917f46fb2..1a8a10c5a51 100644 --- a/go/worker/common/worker.go +++ b/go/worker/common/worker.go @@ -12,6 +12,7 @@ import ( control "github.com/oasisprotocol/oasis-core/go/control/api" keymanagerApi "github.com/oasisprotocol/oasis-core/go/keymanager/api" p2p "github.com/oasisprotocol/oasis-core/go/p2p/api" + "github.com/oasisprotocol/oasis-core/go/runtime/host" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" "github.com/oasisprotocol/oasis-core/go/worker/common/committee" ) @@ -30,6 +31,7 @@ type Worker struct { P2P p2p.Service KeyManager keymanagerApi.Backend RuntimeRegistry runtimeRegistry.Registry + Provisioner host.Provisioner runtimes map[common.Namespace]*committee.Node @@ -161,6 +163,7 @@ func (w *Worker) registerRuntime(runtime runtimeRegistry.Runtime) error { w.ChainContext, w.HostNode, runtime, + w.Provisioner, w.RuntimeRegistry, w.Identity, w.KeyManager, @@ -192,6 +195,7 @@ func New( p2p p2p.Service, keyManager keymanagerApi.Backend, runtimeRegistry runtimeRegistry.Registry, + provisioner host.Provisioner, ) (*Worker, error) { var enabled bool switch config.GlobalConfig.Mode { @@ -223,6 +227,7 @@ func New( P2P: p2p, KeyManager: keyManager, RuntimeRegistry: runtimeRegistry, + Provisioner: provisioner, runtimes: make(map[common.Namespace]*committee.Node), ctx: ctx, cancelCtx: cancelCtx, diff --git a/go/worker/keymanager/init.go b/go/worker/keymanager/init.go index 10c2a0f5555..448896b0b57 100644 --- a/go/worker/keymanager/init.go +++ b/go/worker/keymanager/init.go @@ -9,6 +9,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/node" "github.com/oasisprotocol/oasis-core/go/config" "github.com/oasisprotocol/oasis-core/go/keymanager/api" + "github.com/oasisprotocol/oasis-core/go/runtime/host" runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry" workerCommon "github.com/oasisprotocol/oasis-core/go/worker/common" committeeCommon "github.com/oasisprotocol/oasis-core/go/worker/common/committee" @@ -22,6 +23,7 @@ func New( commonWorker *workerCommon.Worker, r *registration.Worker, backend api.Backend, + provisioner host.Provisioner, ) (*Worker, error) { var enabled bool switch config.GlobalConfig.Mode { @@ -79,7 +81,7 @@ func New( handler := runtimeRegistry.NewRuntimeHostHandler(&workerEnvironment{w}, w.runtime, w.commonWorker.Consensus) // Prepare the runtime host node helpers. - w.RuntimeHostNode, err = runtimeRegistry.NewRuntimeHostNode(w.runtime, handler) + w.RuntimeHostNode, err = runtimeRegistry.NewRuntimeHostNode(w.runtime, provisioner, handler) if err != nil { return nil, fmt.Errorf("worker/keymanager: failed to create runtime host helpers: %w", err) }