Compare commits

..

No commits in common. "2190ac3aaf20c145f17c93797a143ddb72855fbf" and "4d8889e1af8fd84107b180a7e544da58e609696e" have entirely different histories.

2 changed files with 19 additions and 6 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 } = require('../../util/db');
const { matrixPools, matrixUserToAuthorAddress, applicationData } = require('../../util/db');
const {
rollup, wallet,
} = require('../../util/contracts');
@ -12,12 +12,14 @@ const {
stakeRollupAvailability, authorsMatch, validatePost,
} = require('./utils');
const computeMatrixPoolResult = require('./matrix-pools/compute-result');
const { initializeBatchItems, addBatchItem, clearBatchItems } = require('./batch-items');
const { initializeBatchItems } = 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) => {
@ -160,19 +162,30 @@ const start = async () => {
}
matrixPool.result = result;
await matrixPools.put(postId, matrixPool);
await addBatchItem(postId);
batchItems.push(postId);
await applicationData.put('batchItems', batchItems);
break;
}
case 'io.dgov.rollup.submit': {
// This should include the identifier of the on-chain validation pool
const { batchPostId, batchItems, authors } = event.content;
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);
// 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
await clearBatchItems(batchItems);
const nextBatchItems = batchItems.filter((postId) => !batchPostIds.includes(postId));
batchItems = nextBatchItems;
await applicationData.put('batchItems', batchItems);
break;
}
default: