Skip to content

Commit

Permalink
Merge pull request #5545 from oasisprotocol/kostko/fix/observer-regis…
Browse files Browse the repository at this point in the history
…tration

go/worker/client: Fix observer node registration
  • Loading branch information
kostko authored Jan 30, 2024
2 parents df01f3e + 54813f9 commit 7900c68
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changelog/5545.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/worker/client: Fix observer node registration

Previously a node configured as an observer node would forget to
register for all of its configured runtimes, causing the registration
to fail.
6 changes: 5 additions & 1 deletion go/oasis-node/cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ func (n *Node) initRuntimeWorkers() error {
n.svcMgr.Register(n.ExecutorWorker)

// Initialize the client worker.
n.ClientWorker, err = workerClient.New(n.grpcInternal, n.CommonWorker)
n.ClientWorker, err = workerClient.New(
n.grpcInternal,
n.CommonWorker,
n.RegistrationWorker,
)
if err != nil {
return err
}
Expand Down
25 changes: 24 additions & 1 deletion go/worker/client/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@
package client

import (
"fmt"

"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/grpc"
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/config"
"github.com/oasisprotocol/oasis-core/go/runtime/client/api"
"github.com/oasisprotocol/oasis-core/go/worker/client/committee"
workerCommon "github.com/oasisprotocol/oasis-core/go/worker/common"
committeeCommon "github.com/oasisprotocol/oasis-core/go/worker/common/committee"
"github.com/oasisprotocol/oasis-core/go/worker/registration"
)

// Worker is a runtime client worker handling many runtimes.
type Worker struct {
enabled bool

commonWorker *workerCommon.Worker
registration *registration.Worker

runtimes map[common.Namespace]*committee.Node

Expand Down Expand Up @@ -124,6 +129,19 @@ func (w *Worker) registerRuntime(commonNode *committeeCommon.Node) error {
"runtime_id", id,
)

switch config.GlobalConfig.Mode {
case config.ModeClient, config.ModeStatelessClient:
// When a node is a client node and it has an entity configured, we register it with the
// observer role as this may be needed for confidential runtimes.
rp, err := w.registration.NewRuntimeRoleProvider(node.RoleObserver, id)
if err != nil {
return fmt.Errorf("failed to create role provider: %w", err)
}

rp.SetAvailable(commonNode.RegisterNodeRuntime)
default:
}

// Create committee node for the given runtime.
node, err := committee.NewNode(commonNode)
if err != nil {
Expand All @@ -146,7 +164,11 @@ func (w *Worker) registerRuntime(commonNode *committeeCommon.Node) error {
}

// New creates a new runtime client worker.
func New(grpcInternal *grpc.Server, commonWorker *workerCommon.Worker) (*Worker, error) {
func New(
grpcInternal *grpc.Server,
commonWorker *workerCommon.Worker,
registration *registration.Worker,
) (*Worker, error) {
var enabled bool
switch config.GlobalConfig.Mode {
case config.ModeValidator, config.ModeSeed, config.ModeKeyManager:
Expand All @@ -165,6 +187,7 @@ func New(grpcInternal *grpc.Server, commonWorker *workerCommon.Worker) (*Worker,
w := &Worker{
enabled: enabled,
commonWorker: commonWorker,
registration: registration,
runtimes: make(map[common.Namespace]*committee.Node),
quitCh: make(chan struct{}),
initCh: make(chan struct{}),
Expand Down
38 changes: 38 additions & 0 deletions go/worker/common/committee/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package committee

import (
"github.com/oasisprotocol/oasis-core/go/common/node"
)

// RegisterNodeRuntime adds our runtime registration to an existing node descriptor.
func (n *Node) RegisterNodeRuntime(nd *node.Node) error {
// Obtain the active runtime version.
activeVersion, err := n.GetHostedRuntimeActiveVersion()
if err != nil {
n.logger.Warn("failed to get active runtime version, skipping",
"err", err,
)
return nil
}

for _, version := range n.Runtime.HostVersions() {
// Skip sending any old versions that will never be active again.
if version.ToU64() < activeVersion.ToU64() {
continue
}

// Obtain CapabilityTEE for the given runtime version.
capabilityTEE, err := n.GetHostedRuntimeCapabilityTEEForVersion(version)
if err != nil {
n.logger.Warn("failed to get CapabilityTEE for hosted runtime, skipping",
"err", err,
"version", version,
)
continue
}

rt := nd.AddOrUpdateRuntime(n.Runtime.ID(), version)
rt.Capabilities.TEE = capabilityTEE
}
return nil
}
27 changes: 1 addition & 26 deletions go/worker/compute/executor/committee/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/crash"
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/common/pubsub"
"github.com/oasisprotocol/oasis-core/go/common/version"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
p2p "github.com/oasisprotocol/oasis-core/go/p2p/api"
p2pProtocol "github.com/oasisprotocol/oasis-core/go/p2p/protocol"
Expand Down Expand Up @@ -52,7 +50,6 @@ const executeBatchTimeoutFactor = 3
// Node is a committee node.
type Node struct { // nolint: maligned
runtimeReady bool
runtimeVersion version.Version
runtimeTrustSynced bool
runtimeTrustSyncCncl context.CancelFunc

Expand Down Expand Up @@ -1121,28 +1118,7 @@ func (n *Node) nudgeAvailabilityLocked(force bool) {
break
}

n.roleProvider.SetAvailable(func(nd *node.Node) error {
for _, version := range n.commonNode.Runtime.HostVersions() {
// Skip sending any old versions that will never be active again.
if version.ToU64() < n.runtimeVersion.ToU64() {
continue
}

// Obtain CapabilityTEE for the given runtime version.
capabilityTEE, err := n.commonNode.GetHostedRuntimeCapabilityTEEForVersion(version)
if err != nil {
n.logger.Warn("failed to get CapabilityTEE for hosted runtime, skipping",
"err", err,
"version", version,
)
continue
}

rt := nd.AddOrUpdateRuntime(n.commonNode.Runtime.ID(), version)
rt.Capabilities.TEE = capabilityTEE
}
return nil
})
n.roleProvider.SetAvailable(n.commonNode.RegisterNodeRuntime)
default:
// Executor is not ready to process requests.
if !n.roleProvider.IsAvailable() && !force {
Expand Down Expand Up @@ -1183,7 +1159,6 @@ func (n *Node) HandleRuntimeHostEventLocked(ev *host.Event) {

// We are now able to service requests for this runtime.
n.runtimeReady = true
n.runtimeVersion = ev.Started.Version
case ev.Updated != nil:
// Update runtime capabilities.
n.runtimeReady = true
Expand Down
12 changes: 0 additions & 12 deletions go/worker/registration/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,18 +1098,6 @@ func New(
rp.SetAvailable(func(*node.Node) error { return nil })
}

// When a node is a client node and it has an entity configured, we register it with the
// observer role as this may be needed for confidential runtimes.
if config.GlobalConfig.Mode == config.ModeClient {
rp, err := w.NewRoleProvider(node.RoleObserver)
if err != nil {
return nil, err
}

// The observer role is available immediately.
rp.SetAvailable(func(*node.Node) error { return nil })
}

return w, nil
}

Expand Down

0 comments on commit 7900c68

Please sign in to comment.