Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prosopo error simplification #930

Merged
merged 44 commits into from
Jan 16, 2024
Merged

Prosopo error simplification #930

merged 44 commits into from
Jan 16, 2024

Conversation

HughParry
Copy link
Contributor

No description provided.

Copy link

Pull Request Review

Hey there! 👋 I've summarized the previous results for your pull request review. Take a look:

Changes

  1. Added import statement for ProsopoEnvError and getLoggerDefault in app.ts
  2. Added logger variable declaration in main() function in app.ts
  3. Added conditional check for REACT_APP_SERVER_MNEMONIC in main() function in app.ts
  4. Added error logging for missing REACT_APP_SERVER_MNEMONIC in main() function in app.ts
  5. Added error logging for invalid package directory in getPackageDir() function in dependencies.ts
  6. Added error logging for invalid package directory in getDependencies() function in dependencies.ts
  7. Added error logging for low balance in sendFunds() function in funds.ts
  8. Added error logging for funding failure in sendFunds() function in funds.ts
  9. Added error logging for missing mnemonic or seed in registerProvider() function in provider.ts
  10. Added error logging for missing provider pair in setupProvider() function in provider.ts
  11. Added error logging for invalid log level in validateValue() function in validators.ts
  12. Added error logging for invalid package directory in en.json
  13. Added error logging for dataset load failure in ProsopoDatabase class in mongo.ts
  14. Added error logging for commitment flag failure in ProsopoDatabase class in mongo.ts
  15. Added error logging for error in populateStep() function in populateDatabase.ts

Suggestions

  1. In dependencies.ts, line 15, suggest using a more descriptive variable name.
  2. Add comments to explain complex logic.
  3. Consider using a logger library instead of console.error.

Bugs

  1. Line 47 in an unspecified file: The condition if (typeof this.cause != ZodError && this.cause?.message && this.cause.message.length > MAX_ERROR_LENGTH) should be if (typeof this.cause !== 'undefined' && !(this.cause instanceof ZodError) && this.cause?.message && this.cause.message.length > MAX_ERROR_LENGTH).
  2. Line 68 in an unspecified file: super(isError ? (error.message as TranslationKey) : error) should be super(isError ? (error.message as TranslationKey) : translateOrFallback(error, options)).

Improvements

  1. Line 140 in an unspecified file: Added a condition to check if parsed.maxVerifiedTime exists before executing the code block.
  2. Lines 142-146 in an unspecified file: Added new logic to calculate timeSinceCompletion based on currentBlockNumber and blockTimeMs.
  3. File: captcha.ts
    • Line 140: The condition if (parsed.maxVerifiedTime) should be checked before accessing solution.completedAt to avoid potential errors.
    • Line 144: The calculation of timeSinceCompletion may result in unexpected behavior if currentBlockNumber or blockTimeMs is not available.
  4. File: tasks.ts
    • Line 553: The return type of getBlockNumber is not specified. Ensure it returns a Promise<number> to avoid potential type errors.
  5. One place in the code that could be refactored for better readability is in the prosopoRouter function in captcha.ts. Instead of calculating timeSinceCompletion inline, it can be extracted into a separate function for better organization and reusability. Here's a possible refactoring:
function calculateTimeSinceCompletion(currentBlockNumber: number, completedAt: number, blockTimeMs: number): number {
  return (currentBlockNumber - completedAt) * blockTimeMs;
}

export function prosopoRouter(env: ProviderEnvironment): Router {
  // ...
  if (parsed.maxVerifiedTime) {
    const currentBlockNumber = await tasks.getCurrentBlockNumber();
    const blockTimeMs = await tasks.getBlockTimeMs();
    const timeSinceCompletion = calculateTimeSinceCompletion(currentBlockNumber, solution.completedAt, blockTimeMs);

    if (timeSinceCompletion > parsed.maxVerifiedTime) {
      return res.json({ status: req.t('API.USER_NOT_VERIFIED'), solutionApproved: false });
    }
  }
  // ...
}

This refactoring separates the calculation of timeSinceCompletion into a dedicated function, making the code more modular and easier to understand.

Rating

Overall rating: 7.5/10
Criteria: Readability, Performance, Security

Please note that the security rating is difficult to assess without more context on the overall system architecture and security measures in place.

That's it! Let me know if you need anything else. 😉

Copy link
Member

@forgetso forgetso left a comment

Choose a reason for hiding this comment

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

Really tidies things up. A few small changes required.

@HughParry HughParry marked this pull request as ready for review January 15, 2024 12:04
forgetso
forgetso previously approved these changes Jan 15, 2024
@HughParry HughParry enabled auto-merge (squash) January 15, 2024 16:45
goastler
goastler previously approved these changes Jan 16, 2024
Copy link

netlify bot commented Jan 16, 2024

Deploy Preview for provider-gui failed.

Name Link
🔨 Latest commit 9a75c9d
🔍 Latest deploy log https://app.netlify.com/sites/provider-gui/deploys/65a65edbb292ff0008aab815

@HughParry HughParry merged commit 742a4f7 into main Jan 16, 2024
11 checks passed
@HughParry HughParry deleted the Prosopo-Error-simplification branch January 16, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants