diff --git a/servers/cu/src/domain/client/pouchdb.js b/servers/cu/src/domain/client/pouchdb.js index 0760f5043..ad0f2816b 100644 --- a/servers/cu/src/domain/client/pouchdb.js +++ b/servers/cu/src/domain/client/pouchdb.js @@ -194,7 +194,7 @@ export function findLatestEvaluationWith ({ pouchDb }) { .chain((doc) => doc ? Resolved(doc) : Rejected(undefined)) /** * Also retrieve the state buffer, persisted as an attachment - * and set it on the output.buffer field to match the expected output shape + * and set it on the output.Memory field to match the expected output shape */ .chain(fromPromise(async (doc) => { const buffer = await pouchDb.getAttachment(doc._id, 'memory.txt') diff --git a/servers/cu/src/domain/lib/loadMessages.js b/servers/cu/src/domain/lib/loadMessages.js index d515aba7b..4d0fd5b15 100644 --- a/servers/cu/src/domain/lib/loadMessages.js +++ b/servers/cu/src/domain/lib/loadMessages.js @@ -109,6 +109,11 @@ export const CRON_TAG_REGEX = /^Cron-Tag-(.+)$/ * matches the provided cron */ export function isBlockOnCron ({ height, originHeight, cron }) { + /** + * Don't count the origin height as a match + */ + if (height === originHeight) return false + return (height - originHeight) % cron.value === 0 } @@ -126,10 +131,15 @@ export function isTimestampOnCron ({ timestamp, originTimestamp, cron }) { */ timestamp = Math.floor(timestamp / 1000) originTimestamp = Math.floor(originTimestamp / 1000) + /** + * don't count the origin timestamp as a match + */ + if (timestamp === originTimestamp) return false return (timestamp - originTimestamp) % cron.value === 0 } export function cronMessagesBetweenWith ({ + logger, processId, owner: processOwner, tags: processTags, @@ -175,7 +185,9 @@ export function cronMessagesBetweenWith ({ */ for (let i = 0; i < blockBased.length; i++) { const cron = blockBased[i] + if (isBlockOnCron({ height: curBlock.height, originHeight: originBlock.height, cron })) { + logger('Generating Block based Cron Message for cron "%s" at block "%s"', `${i}-${cron.interval}`, curBlock.height) yield { cron: `${i}-${cron.interval}`, message: { @@ -211,6 +223,7 @@ export function cronMessagesBetweenWith ({ const cron = timeBased[i] if (isTimestampOnCron({ timestamp: curTimestamp, originTimestamp: originBlock.timestamp, cron })) { + logger('Generating Time based Cron Message for cron "%s" at timestamp "%s"', `${i}-${cron.interval}`, curTimestamp) yield { cron: `${i}-${cron.interval}`, message: { @@ -305,7 +318,7 @@ function loadCronMessagesWith ({ loadTimestamp, locateScheduler, loadBlocksMeta, logger.tap('Failed to parse crons:'), ifElse( length, - logger.tap('Crons found. Generating cron messages accoding to Crons'), + logger.tap('Crons found. Generating cron messages according to Crons'), logger.tap('No crons found. No cron messages to generate') ) ) @@ -356,6 +369,7 @@ function loadCronMessagesWith ({ loadTimestamp, locateScheduler, loadBlocksMeta, * that are between those boundaries */ genCronMessages: cronMessagesBetweenWith({ + logger, processId: ctx.id, owner: ctx.owner, tags: ctx.tags, diff --git a/servers/cu/src/domain/lib/loadMessages.test.js b/servers/cu/src/domain/lib/loadMessages.test.js index 79fb33eff..81f43d849 100644 --- a/servers/cu/src/domain/lib/loadMessages.test.js +++ b/servers/cu/src/domain/lib/loadMessages.test.js @@ -385,7 +385,7 @@ describe('loadMessages', () => { */ ] - const cronMessagesBetween = cronMessagesBetweenWith({ processId, owner, originBlock, crons, blocksMeta }) + const cronMessagesBetween = cronMessagesBetweenWith({ logger: () => {}, processId, owner, originBlock, crons, blocksMeta }) const genCronMessages = cronMessagesBetween( // left diff --git a/servers/cu/src/domain/readResult.js b/servers/cu/src/domain/readResult.js index 2278c2e7b..21e3d09e7 100644 --- a/servers/cu/src/domain/readResult.js +++ b/servers/cu/src/domain/readResult.js @@ -27,7 +27,7 @@ export function readResultWith (env) { return of({ processId, messageTxId }) .chain(loadMessageMeta) .chain(res => readState({ processId: res.processId, to: res.timestamp })) - .map(omit(['buffer'])) + .map(omit(['Memory'])) .map( env.logger.tap( 'readResult result for message with txId %s to process %s',