Skip to content

Commit 51012d6

Browse files
committed
fix(cu): in findresult, check for exact eval by message id
1 parent 859af1e commit 51012d6

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

servers/cu/src/domain/lib/chainEvaluation.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ function loadLatestEvaluationWith ({ findEvaluation, findLatestProcessMemory, lo
2121

2222
return findEvaluation({
2323
processId: ctx.id,
24-
to: ctx.to,
25-
ordinate: ctx.ordinate,
26-
cron: ctx.cron
24+
messageId: ctx.messageId
2725
})
2826
.map((evaluation) => {
2927
logger(

servers/cu/src/domain/lib/loadProcess.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ function loadLatestEvaluationWith ({ findEvaluation, findLatestProcessMemory, sa
6565

6666
return findEvaluation({
6767
processId: ctx.id,
68-
to: ctx.to,
69-
ordinate: ctx.ordinate,
70-
cron: ctx.cron
68+
messageId: ctx.messageId
7169
})
7270
.map((evaluation) => {
7371
logger(

servers/cu/src/effects/ao-evaluation.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,27 @@ const fromEvaluationDoc = pipe(
7070
toEvaluation
7171
)
7272

73+
// TODO: Change the query to use process Id, message Id, order by id
7374
export function findEvaluationWith ({ db }) {
74-
function createQuery ({ processId, timestamp, ordinate, cron }) {
75+
function createQuery ({ processId, messageId }) {
7576
return {
7677
sql: `
7778
SELECT
7879
id, "processId", "messageId", "deepHash", nonce, epoch, timestamp,
7980
ordinate, "blockHeight", cron, "evaluatedAt", output
8081
FROM ${EVALUATIONS_TABLE}
8182
WHERE
82-
id = ?;
83+
id > ? AND id <= ?
84+
messageId = ?
85+
ORDER BY
86+
id ASC
87+
LIMIT 1;
8388
`,
84-
parameters: [createEvaluationId({ processId, timestamp, ordinate, cron })]
89+
parameters: [
90+
createEvaluationId({ processId, timestamp: '' }),
91+
createEvaluationId({ processId, timestamp: COLLATION_SEQUENCE_MAX_CHAR }),
92+
messageId
93+
]
8594
}
8695
}
8796

servers/cu/src/effects/sqlite.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ const createCheckpointFilesIndexes = async (db) => db.prepare(
109109
(processId, timestamp);`
110110
).run()
111111

112+
const createEvaluationsIndexes = async (db) => db.prepare(
113+
`CREATE INDEX IF NOT EXISTS idx_${EVALUATIONS_TABLE}_id_messageId
114+
ON ${EVALUATIONS_TABLE}
115+
(id, messageId);`
116+
).run()
117+
112118
let internalSqliteDb
113119
export async function createSqliteClient ({ url, bootstrap = false, walLimit = bytes.parse('100mb') }) {
114120
if (internalSqliteDb) return internalSqliteDb
@@ -138,6 +144,7 @@ export async function createSqliteClient ({ url, bootstrap = false, walLimit = b
138144
.then(() => createMessagesIndexes(db))
139145
.then(() => createCheckpointsIndexes(db))
140146
.then(() => createCheckpointFilesIndexes(db))
147+
.then(() => createEvaluationsIndexes(db))
141148
}
142149

143150
return {

0 commit comments

Comments
 (0)