Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit rootfs size to not trigger message rejection #163

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading