Skip to content

Commit

Permalink
Merge pull request #6012 from oasisprotocol/peternose/feature/rofl-up…
Browse files Browse the repository at this point in the history
…grade

go/control/api: Support ROFL upgrades
  • Loading branch information
peternose authored Jan 31, 2025
2 parents 77a3175 + 7ea7ec0 commit 00b64bb
Show file tree
Hide file tree
Showing 52 changed files with 1,648 additions and 1,434 deletions.
2 changes: 2 additions & 0 deletions .buildkite/benchmarks.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ steps:
- buildkite-agent artifact upload simple-keyvalue-upgrade.sgxs
- buildkite-agent artifact upload simple-keymanager-upgrade.sgxs
- buildkite-agent artifact upload simple-rofl.sgxs
- buildkite-agent artifact upload simple-rofl-upgrade.sgxs
- cd /var/tmp/artifacts/default/release
- buildkite-agent artifact upload simple-keymanager
- buildkite-agent artifact upload simple-keyvalue
- buildkite-agent artifact upload simple-keyvalue-upgrade
- buildkite-agent artifact upload simple-keymanager-upgrade
- buildkite-agent artifact upload simple-rofl
- buildkite-agent artifact upload simple-rofl-upgrade
plugins:
<<: *docker_plugin

Expand Down
2 changes: 2 additions & 0 deletions .buildkite/code.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,14 @@ steps:
- buildkite-agent artifact upload simple-keyvalue-upgrade.sgxs
- buildkite-agent artifact upload simple-keymanager-upgrade.sgxs
- buildkite-agent artifact upload simple-rofl.sgxs
- buildkite-agent artifact upload simple-rofl-upgrade.sgxs
- cd /var/tmp/artifacts/default/release
- buildkite-agent artifact upload simple-keymanager
- buildkite-agent artifact upload simple-keyvalue
- buildkite-agent artifact upload simple-keyvalue-upgrade
- buildkite-agent artifact upload simple-keymanager-upgrade
- buildkite-agent artifact upload simple-rofl
- buildkite-agent artifact upload simple-rofl-upgrade

# Build for mock SGX.
- cd /workdir
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/longtests.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ steps:
- buildkite-agent artifact upload simple-keyvalue-upgrade.sgxs
- buildkite-agent artifact upload simple-keymanager-upgrade.sgxs
- buildkite-agent artifact upload simple-rofl.sgxs
- buildkite-agent artifact upload simple-rofl-upgrade.sgxs
- cd /var/tmp/artifacts/default/release
- buildkite-agent artifact upload simple-keymanager
- buildkite-agent artifact upload simple-keyvalue
- buildkite-agent artifact upload simple-keyvalue-upgrade
- buildkite-agent artifact upload simple-keymanager-upgrade
- buildkite-agent artifact upload simple-rofl
- buildkite-agent artifact upload simple-rofl-upgrade
plugins:
<<: *docker_plugin

Expand Down
2 changes: 2 additions & 0 deletions .buildkite/scripts/download_e2e_test_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ download_artifact simple-keyvalue-upgrade target/default/release 755
# Test ROFL runtime.
download_artifact simple-rofl.sgxs target/sgx/x86_64-fortanix-unknown-sgx/release 755
download_artifact simple-rofl target/default/release 755
download_artifact simple-rofl-upgrade.sgxs target/sgx/x86_64-fortanix-unknown-sgx/release 755
download_artifact simple-rofl-upgrade target/default/release 755
6 changes: 6 additions & 0 deletions .changelog/6012.feature.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go/runtime/host: Support individual component upgrades

A new field `components` has been added to the `oasis-node control status`
output under the runtime status section. This field displays the statuses
of runtime components, including their kind, name, version, and whether
they are detached or disabled by default.
6 changes: 6 additions & 0 deletions .changelog/6012.feature.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go/oasis-node/cmd: Support ROFL upgrades

To upgrade ROFL runtime components, you can use the newly added
`oasis-node control add-bundle <path>` command, where `<path>`
is the location of the bundle containing the latest version
of the components you want to upgrade.
20 changes: 7 additions & 13 deletions go/control/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ type NodeController interface {

// GetStatus returns the current status overview of the node.
GetStatus(ctx context.Context) (*Status, error)

// AddBundle adds bundle from the given path.
//
// If the bundle upgrades an existing ROFL component, the latter will
// be upgraded to the new version.
AddBundle(ctx context.Context, path string) error
}

// Status is the current status overview.
Expand All @@ -87,9 +93,6 @@ type Status struct {
// Runtimes is the status overview for each runtime supported by the node.
Runtimes map[common.Namespace]RuntimeStatus `json:"runtimes,omitempty"`

// Bundles is the status overview of known runtime bundles.
Bundles []BundleStatus `json:"bundles,omitempty"`

// Registration is the node's registration status.
Registration *RegistrationStatus `json:"registration,omitempty"`

Expand Down Expand Up @@ -191,21 +194,12 @@ type RuntimeStatus struct {

// Provisioner is the name of the runtime provisioner.
Provisioner string `json:"provisioner,omitempty"`
}

// BundleStatus is the per-runtime bundle status overview.
type BundleStatus struct {
// Name is the optional human readable runtime name.
Name string `json:"name,omitempty"`

// ID is the runtime identifier.
ID common.Namespace `json:"id"`

// Components contains statuses of the runtime components.
Components []ComponentStatus `json:"components,omitempty"`
}

// ComponentStatus is the component status overview.
// ComponentStatus is the runtime component status overview.
type ComponentStatus struct {
// Kind is the component kind.
Kind component.Kind `json:"kind"`
Expand Down
37 changes: 37 additions & 0 deletions go/control/api/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
methodCancelUpgrade = serviceName.NewMethod("CancelUpgrade", nil)
// methodGetStatus is the GetStatus method.
methodGetStatus = serviceName.NewMethod("GetStatus", nil)
// methodAddBundle is the AddBundle method.
methodAddBundle = serviceName.NewMethod("AddBundle", nil)

// serviceDesc is the gRPC service descriptor.
serviceDesc = grpc.ServiceDesc{
Expand Down Expand Up @@ -67,6 +69,10 @@ var (
MethodName: methodGetStatus.ShortName(),
Handler: handlerGetStatus,
},
{
MethodName: methodAddBundle.ShortName(),
Handler: handlerAddBundle,
},
},
Streams: []grpc.StreamDesc{},
}
Expand Down Expand Up @@ -236,6 +242,29 @@ func handlerGetStatus(
return interceptor(ctx, nil, info, handler)
}

func handlerAddBundle(
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var path string
if err := dec(&path); err != nil {
return nil, err
}
if interceptor == nil {
return nil, srv.(NodeController).AddBundle(ctx, path)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodAddBundle.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return nil, srv.(NodeController).AddBundle(ctx, *req.(*string))
}
return interceptor(ctx, &path, info, handler)
}

// RegisterService registers a new node controller service with the given gRPC server.
func RegisterService(server *grpc.Server, service NodeController) {
server.RegisterService(&serviceDesc, service)
Expand Down Expand Up @@ -289,6 +318,14 @@ func (c *nodeControllerClient) GetStatus(ctx context.Context) (*Status, error) {
return &rsp, nil
}

func (c *nodeControllerClient) AddBundle(ctx context.Context, path string) error {
var rsp Status
if err := c.conn.Invoke(ctx, methodAddBundle.FullName(), path, &rsp); err != nil {
return err
}
return nil
}

// NewNodeControllerClient creates a new gRPC node controller client service.
func NewNodeControllerClient(c *grpc.ClientConn) NodeController {
return &nodeControllerClient{c}
Expand Down
24 changes: 24 additions & 0 deletions go/oasis-node/cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ var (
Deprecated: "use the `oasis` CLI instead.",
}

controlAddBundleCmd = &cobra.Command{
Use: "add-bundle <path>",
Short: "adds runtime components from the bundle",
Run: doAddBundle,
}

logger = logging.GetLogger("cmd/control")
)

Expand Down Expand Up @@ -297,6 +303,23 @@ func doStatus(cmd *cobra.Command, _ []string) {
fmt.Println(string(prettyStatus))
}

func doAddBundle(cmd *cobra.Command, args []string) {
if len(args) != 1 {
logger.Error("expected bundle path")
os.Exit(1)
}

conn, client := DoConnect(cmd)
defer conn.Close()

if err := client.AddBundle(context.Background(), args[0]); err != nil {
logger.Error("failed to add bundle",
"err", err,
)
os.Exit(1)
}
}

// Register registers the client sub-command and all of it's children.
func Register(parentCmd *cobra.Command) {
controlCmd.PersistentFlags().AddFlagSet(cmdGrpc.ClientFlags)
Expand All @@ -311,5 +334,6 @@ func Register(parentCmd *cobra.Command) {
controlCmd.AddCommand(controlCancelUpgradeCmd)
controlCmd.AddCommand(controlStatusCmd)
controlCmd.AddCommand(controlRuntimeStatsCmd)
controlCmd.AddCommand(controlAddBundleCmd)
parentCmd.AddCommand(controlCmd)
}
54 changes: 12 additions & 42 deletions go/oasis-node/cmd/node/node_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
p2p "github.com/oasisprotocol/oasis-core/go/p2p/api"
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
storage "github.com/oasisprotocol/oasis-core/go/storage/api"
upgrade "github.com/oasisprotocol/oasis-core/go/upgrade/api"
keymanagerWorker "github.com/oasisprotocol/oasis-core/go/worker/keymanager/api"
Expand Down Expand Up @@ -136,11 +135,6 @@ func (n *Node) GetStatus(ctx context.Context) (*control.Status, error) {
return nil, fmt.Errorf("failed to get runtime status: %w", err)
}

bundles, err := n.getBundleStatus()
if err != nil {
return nil, fmt.Errorf("failed to get bundle status: %w", err)
}

kms, err := n.getKeymanagerStatus()
if err != nil {
return nil, fmt.Errorf("failed to get key manager worker status: %w", err)
Expand Down Expand Up @@ -171,14 +165,18 @@ func (n *Node) GetStatus(ctx context.Context) (*control.Status, error) {
Consensus: cs,
LightClient: lcs,
Runtimes: runtimes,
Bundles: bundles,
Keymanager: kms,
Registration: rs,
PendingUpgrades: pendingUpgrades,
P2P: p2p,
}, nil
}

// AddBundle implements control.NodeController.
func (n *Node) AddBundle(_ context.Context, path string) error {
return n.RuntimeRegistry.GetBundleManager().Add(path)
}

func (n *Node) getIdentityStatus() control.IdentityStatus {
return control.IdentityStatus{
Node: n.Identity.NodeSigner.Public(),
Expand Down Expand Up @@ -349,49 +347,21 @@ func (n *Node) getRuntimeStatus(ctx context.Context) (map[common.Namespace]contr
status.Provisioner = provisioner.Name()
}

runtimes[rt.ID()] = status
}
return runtimes, nil
}

func (n *Node) getBundleStatus() ([]control.BundleStatus, error) {
bundleRegistry := n.RuntimeRegistry.GetBundleRegistry()
manifests := bundleRegistry.GetManifests()
bundles := make([]control.BundleStatus, 0, len(manifests))

for _, manifest := range manifests {
ronl := manifest.GetComponentByID(component.ID_RONL)
if ronl == nil {
continue
}

explodedComponents, err := bundleRegistry.GetComponents(manifest.ID, ronl.Version)
if err != nil {
return nil, err
}

components := make([]control.ComponentStatus, 0, len(explodedComponents))
for _, comp := range explodedComponents {
component := control.ComponentStatus{
// Fetch the status of all components associated with the runtime.
for _, comp := range n.RuntimeRegistry.GetBundleRegistry().Components(rt.ID()) {
status.Components = append(status.Components, control.ComponentStatus{
Kind: comp.Kind,
Name: comp.Name,
Version: comp.Version,
Detached: comp.Detached,
Disabled: comp.Disabled,
}
components = append(components, component)
})
}

bundle := control.BundleStatus{
Name: manifest.Name,
ID: manifest.ID,
Components: components,
}

bundles = append(bundles, bundle)
// Store the runtime status.
runtimes[rt.ID()] = status
}

return bundles, nil
return runtimes, nil
}

func (n *Node) getKeymanagerStatus() (*keymanagerWorker.Status, error) {
Expand Down
7 changes: 6 additions & 1 deletion go/oasis-node/cmd/node/seed_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (n *SeedNode) CancelUpgrade(context.Context, *upgrade.Descriptor) error {
}

// GetStatus implements control.NodeController.
func (n *SeedNode) GetStatus(_ context.Context) (*control.Status, error) {
func (n *SeedNode) GetStatus(context.Context) (*control.Status, error) {
tmAddresses, err := n.cometbftSeed.GetAddresses()
if err != nil {
return nil, err
Expand Down Expand Up @@ -81,3 +81,8 @@ func (n *SeedNode) GetStatus(_ context.Context) (*control.Status, error) {
Seed: &seedStatus,
}, nil
}

// AddBundle implements control.NodeController.
func (n *SeedNode) AddBundle(context.Context, string) error {
return control.ErrNotImplemented
}
Loading

0 comments on commit 00b64bb

Please sign in to comment.