Skip to content

Commit

Permalink
Limit rootfs size to not trigger message rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
MHHukiewitz committed Mar 25, 2024
1 parent b25efc1 commit b1a2e3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ export type JSExecutionEnvironment = 'node' | 'browser'
export function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms))
}

export function gigabyteToMebibyte(n: number): number {
const mebibyte = 2 ** 20
const gigabyte = 10 ** 9
return Math.ceil((n * gigabyte) / mebibyte)
}
6 changes: 4 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 } from '../utils/constants'
import { defaultResources, defaultExecutionEnvironment, MAXIMUM_DISK_SIZE } from '../utils/constants'
import { buildInstanceMessage } from '../utils/messageBuilder'
import { prepareAlephMessage } from '../utils/publish'
import { broadcast } from '../utils/signature'
Expand Down Expand Up @@ -46,13 +46,15 @@ export class InstanceMessageClient {
...environment,
}

const size_mib = mergedResources.memory * 10 > MAXIMUM_DISK_SIZE ? MAXIMUM_DISK_SIZE : mergedResources.memory * 10

const rootfs = {
parent: {
ref: image as string,
use_latest: true,
},
persistence: VolumePersistence.host,
size_mib: mergedResources.memory * 10,
size_mib,
}

const instanceContent: InstanceContent = {
Expand Down
3 changes: 3 additions & 0 deletions packages/message/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FunctionEnvironment, MachineResources } from '../types'
import { gigabyteToMebibyte } from '@aleph-sdk/core'

export const defaultExecutionEnvironment: FunctionEnvironment = {
reproducible: false,
Expand All @@ -12,3 +13,5 @@ export const defaultResources: MachineResources = {
vcpus: 1,
seconds: 30,
}

export const MAXIMUM_DISK_SIZE = gigabyteToMebibyte(100)

0 comments on commit b1a2e3d

Please sign in to comment.