From a0f07d1ff2656916efa4648dda4b05b05e7f4986 Mon Sep 17 00:00:00 2001 From: Gerard Molina <47140788+gmolki@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:04:18 +0200 Subject: [PATCH] feat: implement hypervisor field (default to qemu) (#180) * Implemented Hypervisor field and trusted_execution field for instances. --------- Co-authored-by: Andres D. Molins --- packages/message/src/instance/impl.ts | 4 +-- packages/message/src/instance/types.ts | 4 +-- packages/message/src/types/execution.ts | 38 ++++++++++++++++++++++++- packages/message/src/utils/constants.ts | 10 ++++++- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/packages/message/src/instance/impl.ts b/packages/message/src/instance/impl.ts index b4e88ff5..f03d01d9 100644 --- a/packages/message/src/instance/impl.ts +++ b/packages/message/src/instance/impl.ts @@ -1,5 +1,5 @@ import { Blockchain, DEFAULT_API_V2, stripTrailingSlash } from '@aleph-sdk/core' -import { defaultResources, defaultExecutionEnvironment, MAXIMUM_DISK_SIZE } from '../utils/constants' +import { defaultResources, MAXIMUM_DISK_SIZE, defaultInstanceExecutionEnvironment } from '../utils/constants' import { buildInstanceMessage } from '../utils/messageBuilder' import { prepareAlephMessage } from '../utils/publish' import { broadcast } from '../utils/signature' @@ -44,7 +44,7 @@ export class InstanceMessageClient { } const mergedEnvironment = { - ...defaultExecutionEnvironment, + ...defaultInstanceExecutionEnvironment, ...environment, } diff --git a/packages/message/src/instance/types.ts b/packages/message/src/instance/types.ts index a4fb02d1..8bdeb46f 100644 --- a/packages/message/src/instance/types.ts +++ b/packages/message/src/instance/types.ts @@ -2,7 +2,7 @@ import { Account } from '@aleph-sdk/account' import { MachineVolume, ParentVolume, VolumePersistence } from '../types/volumes' import { BaseExecutableContent, - FunctionEnvironment, + InstanceEnvironment, HostRequirements, MachineResources, Payment, @@ -38,7 +38,7 @@ export type InstancePublishConfiguration = { authorized_keys?: string[] resources?: Partial requirements?: HostRequirements - environment?: Partial + environment?: Partial image?: string volumes?: MachineVolume[] storageEngine?: ItemType.ipfs | ItemType.storage diff --git a/packages/message/src/types/execution.ts b/packages/message/src/types/execution.ts index 6e855242..14851f72 100644 --- a/packages/message/src/types/execution.ts +++ b/packages/message/src/types/execution.ts @@ -3,7 +3,7 @@ import { MachineVolume } from './volumes' import { BaseContent, PaymentType } from './base' /** - * Properties of the execution environment + * Properties of the execution function environment * * reproducible: The function is deterministic (not available yet) * internet: Allow internet access @@ -17,6 +17,37 @@ export type FunctionEnvironment = { shared_cache: boolean } +/** + * Properties of the trusted execution environment + * + * firmware: Firmware to use for the trusted execution + * policy: Policy to use for trusted execution + */ +export type TrustedExecutionEnvironment = { + firmware: string + policy: number +} + +/** + * Properties of the execution instance environment + * + * reproducible: The function is deterministic (not available yet) + * internet: Allow internet access + * aleph_api: Allow access to the Aleph API + * shared_cache: Allow access to the shared redis cache + * hypervisor: Hypervisor to use for the execution, can be Firecracker or Qemu + * trusted_execution: Sets the execution as confidential + */ +export type InstanceEnvironment = { + internet: boolean + aleph_api: boolean + hypervisor?: HypervisorType + trusted_execution?: Partial + // The following fields are kept for retro-compatibility. + shared_cache: boolean + reproducible: false +} + /** * System resources required * @@ -102,3 +133,8 @@ export enum MachineType { vm_function = 'vm-function', vm_instance = 'vm-instance', } + +export enum HypervisorType { + qemu = 'qemu', + firecracker = 'firecracker', +} diff --git a/packages/message/src/utils/constants.ts b/packages/message/src/utils/constants.ts index 297b8db6..00391c87 100644 --- a/packages/message/src/utils/constants.ts +++ b/packages/message/src/utils/constants.ts @@ -1,4 +1,4 @@ -import { FunctionEnvironment, MachineResources } from '../types' +import { FunctionEnvironment, HypervisorType, InstanceEnvironment, MachineResources } from '../types' import { gigabyteToMebibyte } from '@aleph-sdk/core' export const defaultExecutionEnvironment: FunctionEnvironment = { @@ -8,6 +8,14 @@ export const defaultExecutionEnvironment: FunctionEnvironment = { shared_cache: false, } +export const defaultInstanceExecutionEnvironment: InstanceEnvironment = { + reproducible: false, + internet: true, + aleph_api: true, + shared_cache: false, + hypervisor: HypervisorType.qemu, +} + export const defaultResources: MachineResources = { memory: 128, vcpus: 1,