Skip to content

Commit

Permalink
feat(cu): add config to enable/disable evaluation cache
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Dec 23, 2024
1 parent 8433252 commit a04b954
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
3 changes: 2 additions & 1 deletion servers/cu/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export const createApis = async (ctx) => {
id: workerId,
MODE: ctx.MODE,
LOG_CONFIG_PATH: ctx.LOG_CONFIG_PATH,
DEFAULT_LOG_LEVEL: ctx.DEFAULT_LOG_LEVEL
DEFAULT_LOG_LEVEL: ctx.DEFAULT_LOG_LEVEL,
DISABLE_PROCESS_EVALUATION_CACHE: ctx.DISABLE_PROCESS_EVALUATION_CACHE
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions servers/cu/src/domain/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export const domainConfigSchema = z.object({
* Whether to disable File Process Checkpoint creation entirely.
*/
DISABLE_PROCESS_FILE_CHECKPOINT_CREATION: z.preprocess((val) => !!val, z.boolean()),
/**
* Whether to disable caching process evaluations, useful when operating as
* a RU
*/
DISABLE_PROCESS_EVALUATION_CACHE: z.preprocess((val) => !!val, z.boolean()),
/**
* If a process uses this amount of
* gas, then it will immediately create a Checkpoint at the end of the
Expand Down
12 changes: 7 additions & 5 deletions servers/cu/src/effects/ao-evaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function findEvaluationWith ({ db }) {
}
}

export function saveEvaluationWith ({ db, logger: _logger }) {
export function saveEvaluationWith ({ DISABLE_PROCESS_EVALUATION_CACHE, db, logger: _logger }) {
const toEvaluationDoc = pipe(
converge(
unapply(mergeAll),
Expand Down Expand Up @@ -138,8 +138,10 @@ export function saveEvaluationWith ({ db, logger: _logger }) {

function createQuery (evaluation) {
const evalDoc = toEvaluationDoc(evaluation)
const statements = [
{
const statements = []

if (!DISABLE_PROCESS_EVALUATION_CACHE) {
statements.push({
sql: `
INSERT OR IGNORE INTO ${EVALUATIONS_TABLE}
(id, "processId", "messageId", "deepHash", nonce, epoch, timestamp, ordinate, "blockHeight", cron, "evaluatedAt", output)
Expand All @@ -160,8 +162,8 @@ export function saveEvaluationWith ({ db, logger: _logger }) {
evalDoc.evaluatedAt.getTime(),
JSON.stringify(evalDoc.output)
]
}
]
})
}

/**
* Cron messages are not needed to be saved in the messages table
Expand Down
32 changes: 32 additions & 0 deletions servers/cu/src/effects/ao-evaluation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,38 @@ describe('ao-evaluation', () => {
evaluatedAt
})
})

test('noop insert evaluation if DISABLE_PROCESS_EVALUATION_CACHE', async () => {
const saveEvaluation = saveEvaluationSchema.implement(
saveEvaluationWith({
DISABLE_PROCESS_EVALUATION_CACHE: true,
db: {
transaction: async (statements) => {
assert.equal(statements.length, 1)
const [{ sql: messageDocSql }] = statements
assert.ok(messageDocSql.trim().startsWith(`INSERT OR IGNORE INTO ${MESSAGES_TABLE}`))

return Promise.resolve('process-123,1702677252111,1')
}
},
logger
})
)

await saveEvaluation({
isAssignment: false,
deepHash: 'deepHash-123',
timestamp: 1702677252111,
nonce: '1',
epoch: 0,
ordinate: 1,
blockHeight: 1234,
processId: 'process-123',
messageId: 'message-123',
output: { Messages: [{ foo: 'bar' }], Memory: 'foo' },
evaluatedAt
})
})
})

describe('findEvaluations', () => {
Expand Down
6 changes: 5 additions & 1 deletion servers/cu/src/effects/worker/evaluator/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export const createApis = async (ctx) => {
CHECKPOINT_GRAPHQL_URL: ctx.CHECKPOINT_GRAPHQL_URL
}),
bootstrapWasmInstance: WasmClient.bootstrapWasmInstanceWith(),
saveEvaluation: AoEvaluationClient.saveEvaluationWith({ db, logger: ctx.logger }),
saveEvaluation: AoEvaluationClient.saveEvaluationWith({
DISABLE_PROCESS_EVALUATION_CACHE: ctx.DISABLE_PROCESS_EVALUATION_CACHE,
db,
logger: ctx.logger
}),
ARWEAVE_URL: ctx.ARWEAVE_URL,
logger: ctx.logger
})
Expand Down

0 comments on commit a04b954

Please sign in to comment.