Compare commits

...

4 Commits

Author SHA1 Message Date
Ladd Hoffman 2190ac3aaf fix typo in filename
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 36s Details
2024-05-07 15:08:11 -05:00
Ladd Hoffman 33b7111b2c fix batch items record keeping 2024-05-07 15:07:45 -05:00
Ladd Hoffman 29087d37bd fix typo in filename 2024-05-07 15:04:48 -05:00
Ladd Hoffman 86d7fa921a fixup batch items record keeping 2024-05-05 12:30:24 -05:00
2 changed files with 6 additions and 19 deletions

View File

@ -2,7 +2,7 @@ const { isEqual } = require('lodash');
const { registerDecider } = require('../validation-pools');
const { registerMatrixEventHandler, sendMatrixText, sendMatrixEvent } = require('../../matrix-bot');
const { matrixPools, matrixUserToAuthorAddress, applicationData } = require('../../util/db');
const { matrixPools, matrixUserToAuthorAddress } = require('../../util/db');
const {
rollup, wallet,
} = require('../../util/contracts');
@ -12,14 +12,12 @@ const {
stakeRollupAvailability, authorsMatch, validatePost,
} = require('./utils');
const computeMatrixPoolResult = require('./matrix-pools/compute-result');
const { initializeBatchItems } = require('./batch-items');
const { initializeBatchItems, addBatchItem, clearBatchItems } = require('./batch-items');
const { getCurrentBatchWorker, initializeBatchWorker } = require('./batch-worker');
const initiateMatrixPool = require('./matrix-pools/initiate');
const { initiateMatrixPools } = require('./matrix-pools/initiate-matrix-pools');
const computeAuthorWeights = require('./compute-author-weights');
let batchItems;
const start = async () => {
console.log('registering validation pool decider for rollup');
registerDecider(async (pool, post) => {
@ -162,30 +160,19 @@ const start = async () => {
}
matrixPool.result = result;
await matrixPools.put(postId, matrixPool);
batchItems.push(postId);
await applicationData.put('batchItems', batchItems);
await addBatchItem(postId);
break;
}
case 'io.dgov.rollup.submit': {
// This should include the identifier of the on-chain validation pool
const { batchPostId, batchItems: batchItems_, authors } = event.content;
let batchPostIds;
try {
batchPostIds = await applicationData.get('batchPostIds');
} catch (e) {
batchPostIds = [];
}
batchPostIds.push(batchPostId);
await applicationData.put('batchPostIds', batchPostIds);
const { batchPostId, batchItems, authors } = event.content;
// Compare batch worker's result with ours to verify
const expectedAuthors = await computeAuthorWeights(batchItems_);
const expectedAuthors = await computeAuthorWeights(batchItems);
if (!authorsMatch(authors, expectedAuthors)) {
sendMatrixText(`Unexpected result for batch post ${batchPostId}`);
}
// Reset batchItems in preparation for next batch
const nextBatchItems = batchItems.filter((postId) => !batchPostIds.includes(postId));
batchItems = nextBatchItems;
await applicationData.put('batchItems', batchItems);
await clearBatchItems(batchItems);
break;
}
default: