Skip to content

Commit

Permalink
fix(cu): in findresult, check for exact eval by message id
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrain99 committed Jan 7, 2025
1 parent 859af1e commit 51012d6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 1 addition & 3 deletions servers/cu/src/domain/lib/chainEvaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ function loadLatestEvaluationWith ({ findEvaluation, findLatestProcessMemory, lo

return findEvaluation({
processId: ctx.id,
to: ctx.to,
ordinate: ctx.ordinate,
cron: ctx.cron
messageId: ctx.messageId
})
.map((evaluation) => {
logger(
Expand Down
4 changes: 1 addition & 3 deletions servers/cu/src/domain/lib/loadProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ function loadLatestEvaluationWith ({ findEvaluation, findLatestProcessMemory, sa

return findEvaluation({
processId: ctx.id,
to: ctx.to,
ordinate: ctx.ordinate,
cron: ctx.cron
messageId: ctx.messageId
})
.map((evaluation) => {
logger(
Expand Down
15 changes: 12 additions & 3 deletions servers/cu/src/effects/ao-evaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,27 @@ const fromEvaluationDoc = pipe(
toEvaluation
)

// TODO: Change the query to use process Id, message Id, order by id
export function findEvaluationWith ({ db }) {
function createQuery ({ processId, timestamp, ordinate, cron }) {
function createQuery ({ processId, messageId }) {
return {
sql: `
SELECT
id, "processId", "messageId", "deepHash", nonce, epoch, timestamp,
ordinate, "blockHeight", cron, "evaluatedAt", output
FROM ${EVALUATIONS_TABLE}
WHERE
id = ?;
id > ? AND id <= ?
messageId = ?
ORDER BY
id ASC
LIMIT 1;
`,
parameters: [createEvaluationId({ processId, timestamp, ordinate, cron })]
parameters: [
createEvaluationId({ processId, timestamp: '' }),
createEvaluationId({ processId, timestamp: COLLATION_SEQUENCE_MAX_CHAR }),
messageId
]
}
}

Expand Down
7 changes: 7 additions & 0 deletions servers/cu/src/effects/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ const createCheckpointFilesIndexes = async (db) => db.prepare(
(processId, timestamp);`
).run()

const createEvaluationsIndexes = async (db) => db.prepare(
`CREATE INDEX IF NOT EXISTS idx_${EVALUATIONS_TABLE}_id_messageId
ON ${EVALUATIONS_TABLE}
(id, messageId);`
).run()

let internalSqliteDb
export async function createSqliteClient ({ url, bootstrap = false, walLimit = bytes.parse('100mb') }) {
if (internalSqliteDb) return internalSqliteDb
Expand Down Expand Up @@ -138,6 +144,7 @@ export async function createSqliteClient ({ url, bootstrap = false, walLimit = b
.then(() => createMessagesIndexes(db))
.then(() => createCheckpointsIndexes(db))
.then(() => createCheckpointFilesIndexes(db))
.then(() => createEvaluationsIndexes(db))
}

return {
Expand Down

0 comments on commit 51012d6

Please sign in to comment.