Skip to content

Commit

Permalink
feat(mu): put a feature flag around the boot loader #730
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceJuliano committed Sep 10, 2024
1 parent 047b57b commit 7b7a3de
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
1 change: 1 addition & 0 deletions servers/mu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ There are a few environment variables that you can set:
- `TASK_QUEUE_MAX_RETRIES`: The amount of attempts for the tasks queue to process a message.
- `TASK_QUEUE_RETRY_DELAY`: The retry in between each attempt to process a message in the task queue.
- `DISABLE_TRACE`: Whether or not the log tracer should be enabled. Set to any value to disable log tracing. (You must explicitly enable log tracing by setting - `DISABLE_TRACE` to `'false'`)
- `SPAWN_PUSH_ENABLED`: If enabled, this will make the MU attempt to push messages for a spawn as per AOP 6 Boot loader https://github.com/permaweb/ao/issues/730

> You can also use a `.env` file to set environment variables when running in
> development mode, See the `.env.example` for an example `.env`
Expand Down
9 changes: 6 additions & 3 deletions servers/mu/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const domainConfigSchema = z.object({
TRACE_DB_URL: z.string(),
TASK_QUEUE_MAX_RETRIES: z.number(),
TASK_QUEUE_RETRY_DELAY: z.number(),
DISABLE_TRACE: z.boolean()
DISABLE_TRACE: z.boolean(),
SPAWN_PUSH_ENABLED: z.boolean()
})

/**
Expand Down Expand Up @@ -100,7 +101,8 @@ const CONFIG_ENVS = {
TRACE_DB_URL: process.env.TRACE_DB_URL || 'trace',
TASK_QUEUE_MAX_RETRIES: process.env.TASK_QUEUE_MAX_RETRIES || 5,
TASK_QUEUE_RETRY_DELAY: process.env.TASK_QUEUE_RETRY_DELAY || 1000,
DISABLE_TRACE: process.env.DISABLE_TRACE !== 'false'
DISABLE_TRACE: process.env.DISABLE_TRACE !== 'false',
SPAWN_PUSH_ENABLED: process.env.SPAWN_PUSH_ENABLED === 'true'
},
production: {
MODE,
Expand All @@ -121,7 +123,8 @@ const CONFIG_ENVS = {
TRACE_DB_URL: process.env.TRACE_DB_URL || 'trace',
TASK_QUEUE_MAX_RETRIES: process.env.TASK_QUEUE_MAX_RETRIES || 5,
TASK_QUEUE_RETRY_DELAY: process.env.TASK_QUEUE_RETRY_DELAY || 1000,
DISABLE_TRACE: process.env.DISABLE_TRACE !== 'false'
DISABLE_TRACE: process.env.DISABLE_TRACE !== 'false',
SPAWN_PUSH_ENABLED: process.env.SPAWN_PUSH_ENABLED === 'true'
}
}

Expand Down
6 changes: 4 additions & 2 deletions servers/mu/src/domain/api/processSpawn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { of } from 'hyper-async'
import { of, Resolved } from 'hyper-async'

import { spawnProcessWith } from '../lib/spawn-process.js'
import { sendSpawnSuccessWith } from '../lib/send-spawn-success.js'
Expand All @@ -17,7 +17,8 @@ export function processSpawnWith ({
writeDataItem,
buildAndSign,
fetchResult,
fetchSchedulerProcess
fetchSchedulerProcess,
spawnPushEnabled
}) {
const spawnProcess = spawnProcessWith({ logger, writeDataItem, locateScheduler, locateNoRedirect, buildAndSign, fetchSchedulerProcess })
const buildSuccessTx = buildSuccessTxWith({ logger, buildAndSign })
Expand All @@ -30,6 +31,7 @@ export function processSpawnWith ({
.chain(spawnProcess)
.map(setStage('spawn-process', 'pull-initial-result'))
.chain((res) => {
if (!spawnPushEnabled) { return Resolved(res) }
/**
* Fetch the initial boot result for the process
* itself as per aop6 Boot Loader, add it to ctx
Expand Down
3 changes: 2 additions & 1 deletion servers/mu/src/domain/api/processSpawn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('processSpawnWith', () => {
{ name: 'Module', value: 'moduleid' },
{ name: 'Scheduler', value: 'sched' }
]
})
}),
spawnPushEnabled: true
})

const result = await processSpawn({
Expand Down
32 changes: 21 additions & 11 deletions servers/mu/src/domain/api/sendDataItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export function sendDataItemWith ({
crank,
logger,
fetchSchedulerProcess,
writeDataItemArweave
writeDataItemArweave,
spawnPushEnabled
}) {
const verifyParsedDataItem = verifyParsedDataItemWith()
const parseDataItem = parseDataItemWith({ createDataItem, logger })
Expand Down Expand Up @@ -107,17 +108,26 @@ export function sendDataItemWith ({
* boot loader evaluation.
*/
crank: () => of({ res })
/**
* Override the processId fields of tx and res, because parse-data-item sets it
* to the target, but on a spawn we want it to be the id of the Data Item
*
* This is so getCuAddress and pullResult both operate properly.
*/
.map(({ res }) => {
return { ...res, tx: { ...res.tx, processId: res.tx.id }, processId: res.tx.id, initialTxId: res.tx.id }
.chain(({ res }) => {
if (!spawnPushEnabled) {
return Resolved({
...res,
msgs: [],
spawns: [],
assigns: [],
initialTxId: res.initialTxId
})
}
/**
* Override the processId fields of tx and res, because parse-data-item sets it
* to the target, but on a spawn we want it to be the id of the Data Item
*
* This is so getCuAddress and pullResult both operate properly.
*/
return of({ ...res, tx: { ...res.tx, processId: res.tx.id }, processId: res.tx.id, initialTxId: res.tx.id })
.chain(getCuAddress)
.chain(pullResult)
})
.chain(getCuAddress)
.chain(pullResult)
.chain((res) => {
const hasTarget = Boolean(res.dataItem.target)
if (hasTarget) {
Expand Down
3 changes: 2 additions & 1 deletion servers/mu/src/domain/api/sendDataItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ describe('sendDataItemWith', () => {
},
logger,
fetchSchedulerProcess: (res) => res,
writeDataItemArweave: (res) => res
writeDataItemArweave: (res) => res,
spawnPushEnabled: true
})

const { crank, ...result } = await sendDataItem({
Expand Down
8 changes: 6 additions & 2 deletions servers/mu/src/domain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const createApis = async (ctx) => {
const ARWEAVE_URL = ctx.ARWEAVE_URL
const PROC_FILE_PATH = ctx.PROC_FILE_PATH
const CRON_CURSOR_DIR = ctx.CRON_CURSOR_DIR
const SPAWN_PUSH_ENABLED = ctx.SPAWN_PUSH_ENABLED

const logger = ctx.logger
const fetch = ctx.fetch
Expand Down Expand Up @@ -189,7 +190,8 @@ export const createApis = async (ctx) => {
crank,
isWallet: gatewayClient.isWalletWith({ fetch, histogram, ARWEAVE_URL, logger: sendDataItemLogger }),
logger: sendDataItemLogger,
writeDataItemArweave: uploaderClient.uploadDataItemWith({ UPLOADER_URL, logger: sendDataItemLogger, fetch, histogram })
writeDataItemArweave: uploaderClient.uploadDataItemWith({ UPLOADER_URL, logger: sendDataItemLogger, fetch, histogram }),
spawnPushEnabled: SPAWN_PUSH_ENABLED
})

const sendAssignLogger = logger.child('sendAssign')
Expand Down Expand Up @@ -297,6 +299,7 @@ export const createResultApis = async (ctx) => {
const UPLOADER_URL = ctx.UPLOADER_URL
const GRAPHQL_URL = ctx.GRAPHQL_URL
const ARWEAVE_URL = ctx.ARWEAVE_URL
const SPAWN_PUSH_ENABLED = ctx.SPAWN_PUSH_ENABLED

const logger = ctx.logger
const fetch = ctx.fetch
Expand Down Expand Up @@ -342,7 +345,8 @@ export const createResultApis = async (ctx) => {
buildAndSign: signerClient.buildAndSignWith({ MU_WALLET, logger: processMsgLogger }),
writeDataItem: schedulerClient.writeDataItemWith({ fetch, histogram, logger: processSpawnLogger }),
fetchResult: cuClient.resultWith({ fetch: fetchWithCache, histogram, CU_URL, logger: processMsgLogger }),
fetchSchedulerProcess: schedulerClient.fetchSchedulerProcessWith({ getByProcess, setByProcess, fetch, histogram, logger: processMsgLogger })
fetchSchedulerProcess: schedulerClient.fetchSchedulerProcessWith({ getByProcess, setByProcess, fetch, histogram, logger: processMsgLogger }),
spawnPushEnabled: SPAWN_PUSH_ENABLED
})

const processAssignLogger = logger.child('processAssign')
Expand Down

0 comments on commit 7b7a3de

Please sign in to comment.