Skip to content

Commit ebdd1bd

Browse files
committed
feat(cu): skip deduped calls from hb
1 parent 7298a2a commit ebdd1bd

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,35 @@ export function evaluateWith (env) {
192192
continue
193193
}
194194

195+
const skip = message.Skip === 'true'
196+
if (skip) logger(`Skipping message "${name}" because 'Skip' tag is set to 'true'`)
197+
195198
prev = await Promise.resolve(prev)
196199
.then((prev) =>
197200
Promise.resolve(prev.Memory)
198201
/**
199202
* Where the actual evaluation is performed
200203
*/
201-
.then((Memory) => ctx.evaluator({ first, noSave, name, deepHash, cron, ordinate, isAssignment, processId: ctx.id, Memory, message, AoGlobal }))
204+
.then((Memory) => {
205+
// console.dir({ m: 'Evaluating message', message }, {depth:null})
206+
if (skip) {
207+
return {
208+
Memory,
209+
Error: undefined,
210+
Messages: [],
211+
Assignments: [],
212+
Spawns: [],
213+
Output: {
214+
data: '',
215+
prompt: '',
216+
print: false
217+
},
218+
Patches: [],
219+
GasUsed: 0
220+
}
221+
}
222+
return ctx.evaluator({ first, noSave, name, deepHash, cron, ordinate, isAssignment, processId: ctx.id, Memory, message, AoGlobal })
223+
})
202224
/**
203225
* These values are folded,
204226
* so that we can potentially update the process memory cache

servers/cu/src/domain/model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ export const messageSchema = z.object({
370370
* Whether the message is a cron generated message or not
371371
*/
372372
Cron: z.boolean(),
373+
Skip: z.string().default('false'),
373374
'Read-Only': z.boolean().default(false)
374375
}),
375376
AoGlobal: z.object({

servers/cu/src/effects/hb/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export const mapNode = (type) => pipe(
182182
Target: path(['Process']),
183183
Epoch: pipe(path(['Epoch']), parseInt),
184184
Nonce: pipe(path(['Slot'])(tags) ? path(['Slot']) : path(['Nonce']), parseInt),
185+
Skip: pathOr('false', ['Skip']),
185186
Timestamp: pipe(path(['Timestamp']), parseInt),
186187
'Block-Height': pipe(
187188
/**
@@ -453,7 +454,7 @@ export const loadMessagesWith = ({ hashChain, fetch, logger: _logger, pageSize }
453454
body.edges.length === (+to - +from + 1) &&
454455
+body.edges[0]?.node?.assignment?.Tags?.find(t => t.name === 'Nonce' || t.name === 'Slot')?.value === +from
455456
if (bodyIsValid) return body
456-
return fetchPageDataloader.load({ suUrl, processId, from, to, pageSize })
457+
throw new Error('Body is not valid: would attempt to fetch from scheduler in loadMessages')
457458
},
458459
{ maxRetries: 5, delay: 500, log: logger, name: `loadMessages(${JSON.stringify({ suUrl, processId, params: params.toString() })})` }
459460
)
@@ -605,15 +606,13 @@ export const loadMessagesWith = ({ hashChain, fetch, logger: _logger, pageSize }
605606

606607
export const loadMessageMetaWith = ({ fetch, logger }) => {
607608
return async ({ suUrl, processId, messageUid, body }) => {
608-
const params = toParams({ processId, to: messageUid, from: messageUid, pageSize: 1 })
609-
610609
return backoff(
611610
() => {
612611
const bodyIsValid = body &&
613612
body.edges.length === 1 &&
614613
+body.edges[0]?.node?.assignment?.Tags?.find(t => t.name === 'Nonce' || t.name === 'Slot')?.value === +messageUid
615614
if (bodyIsValid) return body
616-
return fetch(`${suUrl}/~scheduler@1.0/schedule?${params.toString()}`).then(okRes)
615+
throw new Error('Body is not valid: would attempt to fetch from scheduler in loadMessageMeta')
617616
},
618617
{ maxRetries: 5, delay: 500, log: logger, name: `loadMessageMeta(${JSON.stringify({ suUrl, processId, messageUid })})` }
619618
)

0 commit comments

Comments
 (0)