fix batch items record keeping
This commit is contained in:
commit
33b7111b2c
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue