From 86d7fa921aa660f94f9ea6dbebf627b19480887b Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Sun, 5 May 2024 12:30:24 -0500 Subject: [PATCH 1/2] fixup batch items record keeping --- backend/src/event-handlers/rollup/index.js | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/backend/src/event-handlers/rollup/index.js b/backend/src/event-handlers/rollup/index.js index 5c2023a..74ec882 100644 --- a/backend/src/event-handlers/rollup/index.js +++ b/backend/src/event-handlers/rollup/index.js @@ -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: From 29087d37bd82308a6297f1f9db23abec57e33b4a Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Tue, 7 May 2024 15:04:48 -0500 Subject: [PATCH 2/2] fix typo in filename --- ...mpute-autor-weights.test.js => compute-author-weights.test.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename backend/src/event-handlers/rollup/{compute-autor-weights.test.js => compute-author-weights.test.js} (100%) diff --git a/backend/src/event-handlers/rollup/compute-autor-weights.test.js b/backend/src/event-handlers/rollup/compute-author-weights.test.js similarity index 100% rename from backend/src/event-handlers/rollup/compute-autor-weights.test.js rename to backend/src/event-handlers/rollup/compute-author-weights.test.js