Skip to content

Commit

Permalink
feat: implement hypervisor field (default to qemu) (#180)
Browse files Browse the repository at this point in the history
* Implemented Hypervisor field and trusted_execution field for instances.

---------

Co-authored-by: Andres D. Molins <[email protected]>
  • Loading branch information
gmolki and nesitor committed Aug 26, 2024
1 parent 6514c3a commit a0f07d1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/message/src/instance/impl.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -44,7 +44,7 @@ export class InstanceMessageClient {
}

const mergedEnvironment = {
...defaultExecutionEnvironment,
...defaultInstanceExecutionEnvironment,
...environment,
}

Expand Down
4 changes: 2 additions & 2 deletions packages/message/src/instance/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Account } from '@aleph-sdk/account'
import { MachineVolume, ParentVolume, VolumePersistence } from '../types/volumes'
import {
BaseExecutableContent,
FunctionEnvironment,
InstanceEnvironment,
HostRequirements,
MachineResources,
Payment,
Expand Down Expand Up @@ -38,7 +38,7 @@ export type InstancePublishConfiguration = {
authorized_keys?: string[]
resources?: Partial<MachineResources>
requirements?: HostRequirements
environment?: Partial<FunctionEnvironment>
environment?: Partial<InstanceEnvironment>
image?: string
volumes?: MachineVolume[]
storageEngine?: ItemType.ipfs | ItemType.storage
Expand Down
38 changes: 37 additions & 1 deletion packages/message/src/types/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<TrustedExecutionEnvironment>
// The following fields are kept for retro-compatibility.
shared_cache: boolean
reproducible: false
}

/**
* System resources required
*
Expand Down Expand Up @@ -102,3 +133,8 @@ export enum MachineType {
vm_function = 'vm-function',
vm_instance = 'vm-instance',
}

export enum HypervisorType {
qemu = 'qemu',
firecracker = 'firecracker',
}
10 changes: 9 additions & 1 deletion packages/message/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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,
Expand Down

0 comments on commit a0f07d1

Please sign in to comment.