Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"cors": "2.8.5",
"dotenv": "16.5.0",
"express": "5.1.0",
"mongodb": "6.15.0",
"mongoose": "8.13.2",
"mongodb": "6.17.0",
"mongoose": "8.16.2",
"threads": "1.7.0",
"winston": "3.17.0"
},
Expand Down
10 changes: 5 additions & 5 deletions src/RoundManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ export class RoundManager {
throw error;
}

// Add leaves to the SMT tree
if (smtLeaves.length > 0) {
await this.smt.addLeaves(smtLeaves);
}

try {
await Promise.all([recordStoragePromise, smtLeafStoragePromise]);
} catch (error) {
loggerWithMetadata.error('Failed to store records and SMT leaves:', error);
throw error;
}
Comment on lines 82 to 87
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The recordStoragePromise and smtLeafStoragePromise are executed in parallel but not within a database transaction. If one of these operations succeeds and the other fails, the database will be left in an inconsistent state. For example, the aggregator records might be saved, but the corresponding SMT leaves might not be. To ensure atomicity, these two putBatch operations should be wrapped in a single transaction.

try {
  await withTransaction(async (session) => {
    const p1 = aggregatorRecords.length > 0 ? this.recordStorage.putBatch(aggregatorRecords, session) : Promise.resolve(true);
    const p2 = smtLeafStoragePromise = smtLeaves.length > 0 ? this.smtStorage.putBatch(smtLeaves, session) : Promise.resolve(true);
    await Promise.all([p1, p2]);
  });
} catch (error) {
  loggerWithMetadata.error('Failed to store records and SMT leaves transactionally:', error);
  throw error;
}


// Add leaves to the SMT tree
if (smtLeaves.length > 0) {
await this.smt.addLeaves(smtLeaves);
}

let submitHashResponse;
const rootHash = this.smt.rootHash;
try {
Expand Down
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"isolatedModules": true,
"baseUrl": ".",
"paths": {
"threads": ["./node_modules/threads/dist/index.d.ts"],
"threads/worker": ["./node_modules/threads/dist/worker/index.d.ts"],
"threads/*": ["./node_modules/threads/dist/*"]
}
"baseUrl": "."
},
"exclude": [
"node_modules",
Expand Down