Skip to content

Commit

Permalink
go/runtime: Reduce downtime for TEE runtime upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Feb 23, 2023
1 parent eaff1b8 commit c27ec60
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 48 deletions.
7 changes: 4 additions & 3 deletions go/oasis-test-runner/scenario/e2e/runtime/runtime_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ func (sc *runtimeUpgradeImpl) Run(childEnv *env.Env) error {
if err != nil {
return fmt.Errorf("failed to get current epoch: %w", err)
}
upgradeEpoch := epoch + 2

// Update runtime to include the new enclave identity.
sc.Logger.Info("updating runtime descriptor")
newRt := sc.Net.Runtimes()[sc.upgradedRuntimeIndex]
newRtDsc := newRt.ToRuntimeDescriptor()
newRtDsc.Deployments[1].ValidFrom = epoch + 1
newRtDsc.Deployments[1].ValidFrom = upgradeEpoch

newTxPath := filepath.Join(childEnv.Dir(), "register_update_compute_runtime.json")
if err := cli.Registry.GenerateRegisterRuntimeTx(childEnv.Dir(), newRtDsc, sc.nonce, newTxPath); err != nil {
Expand Down Expand Up @@ -245,9 +246,9 @@ func (sc *runtimeUpgradeImpl) Run(childEnv *env.Env) error {

// Wait for activation epoch.
sc.Logger.Info("waiting for runtime upgrade epoch",
"epoch", epoch+1,
"epoch", upgradeEpoch,
)
if err := sc.Net.Controller().Beacon.WaitEpoch(ctx, epoch+1); err != nil {
if err := sc.Net.Controller().Beacon.WaitEpoch(ctx, upgradeEpoch); err != nil {
return fmt.Errorf("failed to wait for epoch: %w", err)
}

Expand Down
5 changes: 5 additions & 0 deletions go/registry/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,11 @@ func verifyNodeRuntimeChanges(
// can chose not to include it in the registration.
continue
}
if vi := rtDesc.DeploymentForVersion(version); vi == nil {
// If the missing version is no longer scheduled, it is
// fine if the node does not include it.
continue
}

logger.Error("RegisterNode: trying to update runtimes, current version is misssing in new set",
"runtime_id", id,
Expand Down
11 changes: 11 additions & 0 deletions go/registry/api/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,17 @@ func (r *Runtime) ActiveDeployment(now beacon.EpochTime) *VersionInfo {
return activeDeployment
}

// NextDeployment returns the first deployment that will become active next if it exists.
func (r *Runtime) NextDeployment(now beacon.EpochTime) *VersionInfo {
for _, deployment := range r.Deployments {
// Find the first version that will become the active deployment next.
if deployment.ValidFrom > now {
return deployment
}
}
return nil
}

// DeploymentForVersion returns the deployment corresponding to the passed version if it exists.
func (r *Runtime) DeploymentForVersion(v version.Version) *VersionInfo {
for _, deployment := range r.Deployments {
Expand Down
4 changes: 4 additions & 0 deletions go/runtime/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ type Runtime interface {
// GetInfo retrieves the runtime information.
GetInfo(ctx context.Context) (*protocol.RuntimeInfoResponse, error)

// GetCapabilityTEE retrieves the CapabilityTEE of the runtime. It may be nil in case the
// runtime is not running inside a TEE.
GetCapabilityTEE(ctx context.Context) (*node.CapabilityTEE, error)

// Call sends a request message to the runtime over the Runtime Host Protocol and waits for the
// response (which may be a failure).
Call(ctx context.Context, body *protocol.Body) (*protocol.Body, error)
Expand Down
6 changes: 6 additions & 0 deletions go/runtime/host/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/errors"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/common/pubsub"
"github.com/oasisprotocol/oasis-core/go/common/version"
"github.com/oasisprotocol/oasis-core/go/roothash/api/commitment"
Expand Down Expand Up @@ -57,6 +58,11 @@ func (r *runtime) GetInfo(ctx context.Context) (rsp *protocol.RuntimeInfoRespons
}, nil
}

// Implements host.Runtime.
func (r *runtime) GetCapabilityTEE(ctx context.Context) (rsp *node.CapabilityTEE, err error) {
return nil, nil
}

// Implements host.Runtime.
func (r *runtime) Call(ctx context.Context, body *protocol.Body) (*protocol.Body, error) {
switch {
Expand Down
Loading

0 comments on commit c27ec60

Please sign in to comment.