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

feat(dev-cli): auto-set memory-limit flag based on module requirements #983

Merged
merged 3 commits into from
Sep 26, 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
36 changes: 18 additions & 18 deletions dev-cli/container/src/ao_module_lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ def mb_to_bytes(megabytes):

presets = {
'xs': {
'stack_size': mb_to_bytes(8),
'initial_memory': mb_to_bytes(16),
'maximum_memory': mb_to_bytes(64)
'stack_size': mb_to_bytes(16),
'initial_memory': mb_to_bytes(20),
'maximum_memory': mb_to_bytes(128)
},
'sm': {
'stack_size': mb_to_bytes(16),
'initial_memory': mb_to_bytes(32),
'maximum_memory': mb_to_bytes(128)
'stack_size': mb_to_bytes(32),
'initial_memory': mb_to_bytes(36),
'maximum_memory': mb_to_bytes(256)
},
'md': {
'stack_size': mb_to_bytes(32),
'initial_memory': mb_to_bytes(48),
'maximum_memory': mb_to_bytes(256)
'stack_size': mb_to_bytes(64),
'initial_memory': mb_to_bytes(68),
'maximum_memory': mb_to_bytes(512)
},
'lg': {
'stack_size': mb_to_bytes(48),
'initial_memory': mb_to_bytes(64),
'maximum_memory': mb_to_bytes(256)
'stack_size': mb_to_bytes(96),
'initial_memory': mb_to_bytes(100),
'maximum_memory': mb_to_bytes(1024)
},
'xl': {
'stack_size': mb_to_bytes(64),
'initial_memory': mb_to_bytes(96),
'maximum_memory': mb_to_bytes(512)
'stack_size': mb_to_bytes(128),
'initial_memory': mb_to_bytes(132),
'maximum_memory': mb_to_bytes(8192)
},
'xxl': {
'stack_size': mb_to_bytes(96),
'initial_memory': mb_to_bytes(128),
'maximum_memory': mb_to_bytes(4096)
'stack_size': mb_to_bytes(512),
'initial_memory': mb_to_bytes(518),
'maximum_memory': mb_to_bytes(16384)
},
}

Expand Down
53 changes: 51 additions & 2 deletions dev-cli/src/commands/publish.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global Deno */

import { Command, basename, resolve } from '../deps.js'
import { bundlerArgs, tagsArg } from '../utils.js'
import { Command, basename, resolve, parse } from '../deps.js'
import { hostArgs, bundlerArgs, tagsArg } from '../utils.js'
import { VERSION } from '../versions.js'

function walletArgs (wallet) {
Expand Down Expand Up @@ -42,14 +42,63 @@ function contractSourceArgs (contractWasmPath) {
]
}

/**
* Retrieves the memory limit based on the configuration preset or custom memory limit.
* @returns {string} The memory limit
*/
async function GetMemoryLimit () {
let memoryLimit = '256-mb'

const configPath = `${Deno.cwd()}/config.yml`
let config = null
try {
config = parse(await Deno.readTextFile(configPath))
} catch {
return memoryLimit
}

if (config) {
switch (config.preset) {
case 'xs':
memoryLimit = '128-mb'
break
case 'sm':
memoryLimit = '256-mb'
break
case 'md':
memoryLimit = '512-mb'
break
case 'lg':
memoryLimit = '1024-mb'
break
case 'xl':
memoryLimit = '8192-mb'
break
case 'xxl':
memoryLimit = '16384-mb'
break
default:
memoryLimit = '512-mb'
break
}
}
if (config?.memory_limit) {
memoryLimit = `${config.memoryLimit}-b`
}
return memoryLimit
}

/**
* TODO:
* - Validate existence of wallet
* - Validate existence of contract wasm
* - allow using environment variables to set things like path to wallet
* - require confirmation and bypass with --yes
*/

export async function publish ({ wallet, bundler, tag, value }, contractWasmPath) {
tag.push('Memory-Limit')
value.push(await GetMemoryLimit())
const cmdArgs = [
...walletArgs(wallet),
...bundlerArgs(bundler),
Expand Down
1 change: 1 addition & 0 deletions dev-cli/src/deps.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { Command } from 'https://deno.land/x/[email protected]/command/mod.ts'
export { basename, resolve } from 'https://deno.land/[email protected]/path/mod.ts'
export { copy } from 'https://deno.land/[email protected]/fs/copy.ts'
export { parse } from 'jsr:@std/yaml'