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

Reusable server module #1637

Merged
merged 31 commits into from
Sep 24, 2024
Merged

Reusable server module #1637

merged 31 commits into from
Sep 24, 2024

Conversation

RaoulSchaffranek
Copy link
Contributor

@RaoulSchaffranek RaoulSchaffranek commented Sep 17, 2024

Overview

This PR aims to make the sourcify-server module available as a library that can be distributed via package registries like npm.

Background

We are developing a Solidity debugger that utilizes Sourcify as a source-code repository. Our goal is to leverage Sourcify for debugging public transactions on mainnet and testnets, as well as on local testnets such as Anvil. Given the complexity of installing Sourcify, we plan to bundle a Sourcify server within our VSCode extension and manage the server process ourselves for local development.

Changes Summary

To achieve this, the following changes have been made:

  1. Modularization of the Server Module:

    • The server module has been divided into two parts to avoid side effects like reading configuration files upon import:
      • A declarative module that exports the server class (this is the original server module).
      • A CLI module that handles configuration file reading and server startup.
  2. Splitting the sourcify-chains Module:

    • Similarly, the sourcify-chains module has been split into:
      • A declarative module named sourcify-chain-repository.
      • An imperative module called sourcify-chains.
  3. Decoupling from node-config:

    • All cross-references to node-config have been removed. Configuration files are now read exclusively by the CLI module. All other modules explicitly pass down their configuration options.

This modular approach allows us to integrate Sourcify more seamlessly into our project. We tried to keep the changes at a minimum and barely modified the existing code. The biggest diffs stem from moving imperative code to the cli module.

Summary by CodeRabbit

  • New Features
    • Introduced a new ChainRepository class for managing blockchain networks and validating chain IDs.
    • Added a command-line interface for running the server.
  • Improvements
    • Refactored session management for enhanced flexibility.
    • Updated server configuration to streamline options and improve maintainability.
    • Enhanced Solidity compiler interactions by passing instances directly to functions.
  • Bug Fixes
    • Corrected storage configuration in the README for clarity.
  • Chores
    • Removed unused imports and simplified code across various files.

@kuzdogan kuzdogan self-requested a review September 18, 2024 13:01
@kuzdogan kuzdogan self-assigned this Sep 18, 2024
Copy link
Member

@kuzdogan kuzdogan left a comment

Choose a reason for hiding this comment

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

Couple small things, otherwise lgtm! Thanks a lot.

Tbh I didn't know you could do app.get('var') so this makes things a lot easier.

I made some changes directly myself mainly:

  • getting rid of injecting req.services after learning app.get('services')
  • Renaming repoPath to solcRepoPath and also adding missing solcJsonRepoPaths

Added couple comments for your review. I still need to look at the tests if they'll work fine, let's see.

services/server/src/server/server.ts Outdated Show resolved Hide resolved
services/server/src/server/cli.ts Outdated Show resolved Hide resolved
services/server/src/server/server.ts Show resolved Hide resolved
@kuzdogan
Copy link
Member

Tests are passing if you want to check the comments @RaoulSchaffranek

I'll handle the conflicts and the rest

Copy link
Member

@marcocastignoli marcocastignoli left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks @RaoulSchaffranek for the big PR! I have only one doubt regarding the compiler.

Also, I moved process.env.LOGGING_TOKEN and hideIpInLogs into Server's options, see 339cc7e and 4d77f98

@kuzdogan
Copy link
Member

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes involve significant refactoring and updates across multiple files in the codebase. Key modifications include the introduction of a new ChainRepository class for managing blockchain networks, updates to how services and dependencies are accessed within various handlers, and adjustments to the session management logic. Additionally, several methods and interfaces have been modified to streamline the handling of Solidity compiler paths and repository URLs. The overall structure has been enhanced for better clarity and maintainability.

Changes

File Path Change Summary
.vscode/launch.json Changed entry point from server.js to cli.js.
packages/lib-sourcify/test/compiler/solidityCompiler.ts Renamed variable repoPath to compilersPath.
serverless/compiler-lambda/index.js Renamed variable repoPath to compilersPath.
services/server/README.md Updated storage configuration: added writeOrWarn and corrected writeOrErr.
services/server/package.json Removed private field; added main, types, bin; updated start script to cli.js.
services/server/src/common/errors/GenericErrorHandler.ts Added comment about _next parameter for Express error handling.
services/server/src/server/cli.ts New file implementing server CLI with various configurations and initializations.
services/server/src/server/common.ts Removed validateSourcifyChainIds function.
services/server/src/server/controllers/controllers.common.ts Updated service retrieval method to use req.app.get("services").
services/server/src/server/controllers/repository/repository.handlers.ts Refactored service retrieval to use req.app.get("services").
services/server/src/server/controllers/verification/etherscan/etherscan.common.ts Updated getMetadataFromCompiler function to include solc parameter.
services/server/src/server/controllers/verification/etherscan/session/etherscan.session.handlers.ts Enhanced service retrieval and validation logic.
services/server/src/server/controllers/verification/etherscan/stateless/etherscan.stateless.handlers.ts Integrated ChainRepository and ISolidityCompiler for verification.
services/server/src/server/controllers/verification/session-state/session-state.handlers.ts Updated session handling logic with new dependencies.
services/server/src/server/controllers/verification/solc-json/session/solc-json.session.handlers.ts Added ISolidityCompiler dependency.
services/server/src/server/controllers/verification/solc-json/stateless/solc-json.stateless.handlers.ts Updated service access patterns using new dependencies.
services/server/src/server/controllers/verification/verification.common.ts Streamlined handling of Solidity compiler parameters.
services/server/src/server/controllers/verification/verify/session/verify.session.handlers.ts Enhanced modularity by retrieving services from req.app.get.
services/server/src/server/controllers/verification/verify/stateless/verify.stateless.handlers.ts Updated service retrieval to use req.app.get.
services/server/src/server/controllers/verification/verify/stateless/verify.stateless.routes.ts Modified route handling for /verify-deprecated.
services/server/src/server/routes.ts Added ChainRepository import and updated route handler for chains.
services/server/src/server/server.ts Refactored configuration management; introduced ServerOptions interface.
services/server/src/server/services/StorageService.ts Updated SourcifyDatabaseService instantiation to include repositoryServerUrl.
services/server/src/server/services/VerificationService.ts Updated VerificationServiceOptions and constructor parameters.
services/server/src/server/services/compiler/lambda-with-fallback/SolcLambdaWithLocalFallback.ts Constructor now accepts parameters for AWS credentials and paths.
services/server/src/server/services/compiler/lambda/SolcLambda.ts Constructor updated to accept AWS parameters directly.
services/server/src/server/services/compiler/local/SolcLocal.ts Constructor added to accept repository paths.
services/server/src/server/services/compiler/local/compilerWorker.ts Updated runUseCompiler to accept solJsonRepoPath.
services/server/src/server/services/compiler/local/solidityCompiler.ts Updated functions to accept repository paths as parameters.
services/server/src/server/services/storageServices/AbstractDatabaseService.ts Removed unused import for Transformation.
services/server/src/server/services/storageServices/RepositoryV1Service.ts Added repositoryServerUrl property; updated URL construction logic.
services/server/src/server/services/storageServices/RepositoryV2Service.ts Removed unused imports for MatchLevel and RepositoryTag.
services/server/src/server/services/storageServices/SourcifyDatabaseService.ts Added repositoryV1ServerUrl property; updated URL logic.
services/server/src/server/session.ts Refactored session management logic to simplify middleware setup.
services/server/src/sourcify-chain-repository.ts Introduced ChainRepository class for managing blockchain networks.
services/server/src/sourcify-chains.ts Reduced exports and removed unused functions for chain verification.
services/server/test/helpers/ServerFixture.ts Enhanced configuration and session management in test fixtures.
services/server/test/integration/etherscan.spec.ts Removed unused waitSecs import.
services/server/test/integration/path-sanitization.spec.ts Updated repository path handling in tests.
services/server/test/integration/verification-handlers/verify.session.spec.ts Updated file path references in tests.
services/server/test/integration/verification-handlers/verify.stateless.spec.ts Modified file paths in test cases.
services/server/test/unit/VerificationService.spec.ts Updated initialization of VerificationService with new parameters.
services/server/test/unit/utils/contract-creation-util.spec.ts Replaced sourcifyChainsArray with sourcifyChainsMap using ChainRepository.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant ChainRepository
    participant VerificationService

    Client->>Server: Request verification
    Server->>ChainRepository: Check supported chain ID
    ChainRepository-->>Server: Return validation result
    Server->>VerificationService: Verify contracts
    VerificationService-->>Server: Return verification result
    Server-->>Client: Respond with verification result
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 16

Outside diff range and nitpick comments (11)
services/server/src/server/services/compiler/lambda-with-fallback/SolcLambdaWithLocalFallback.ts (1)

14-29: Constructor looks good. Minor suggestion.

The new constructor enhances flexibility. Consider using object destructuring for cleaner parameter handling.

 constructor(
-  awsRegion: string,
-  awsAccessKeyId: string,
-  awsSecretAccessKey: string,
-  lambdaCompilerFunctionName: string = "compile",
-  solcRepoPath: string,
-  solJsonRepoPath: string,
+  {
+    awsRegion,
+    awsAccessKeyId,
+    awsSecretAccessKey,
+    lambdaCompilerFunctionName = "compile",
+    solcRepoPath,
+    solJsonRepoPath,
+  }: {
+    awsRegion: string;
+    awsAccessKeyId: string;
+    awsSecretAccessKey: string;
+    lambdaCompilerFunctionName?: string;
+    solcRepoPath: string;
+    solJsonRepoPath: string;
+  }
 ) {
   // ... rest of the constructor
 }
services/server/src/server/controllers/controllers.common.ts (1)

56-60: Good refactor, but add a safety check.

Centralizing service access is good. Add a null check for services to prevent potential runtime errors.

Consider this change:

-  const services = req.app.get("services") as Services;
+  const services = req.app.get("services") as Services;
+  if (!services) {
+    return next(new InternalServerError("Services not initialized"));
+  }
services/server/src/server/routes.ts (1)

36-37: LGTM: ChainRepository usage implemented correctly.

Consider adding a type assertion for app.get("chainRepository") to ensure type safety.

-  const chainRepository = _req.app.get("chainRepository") as ChainRepository;
+  const chainRepository = _req.app.get("chainRepository");
+  if (!(chainRepository instanceof ChainRepository)) {
+    throw new Error("ChainRepository not found in app context");
+  }
services/server/src/server/controllers/verification/etherscan/etherscan.common.ts (1)

Line range hint 234-238: Function signature update looks good.

The new solc parameter improves flexibility. Consider adding a null check for solc to prevent runtime errors.

services/server/src/server/services/StorageService.ts (1)

145-145: LGTM. Consider extracting the URL.

The addition of repositoryServerUrl is good. For clarity, consider extracting it to a variable before passing.

+const { repositoryServerUrl } = options.repositoryV1ServiceOptions;
 const sourcifyDatabase = new SourcifyDatabaseService(
   this,
   options.sourcifyDatabaseServiceOptions,
-  options.repositoryV1ServiceOptions.repositoryServerUrl,
+  repositoryServerUrl,
 );
services/server/src/server/controllers/verification/etherscan/session/etherscan.session.handlers.ts (1)

Line range hint 74-74: Unreachable code after throw statement

The return; statement after the throw at line 74 is unreachable and can be safely removed.

services/server/src/sourcify-chain-repository.ts (2)

29-29: Typo in comment: 'netorks' should be 'networks'

There's a small typo in the comment on line 29. Correcting it improves readability.

Apply this diff to fix the typo:

-      // Use long form name for Ethereum netorks e.g. "Ethereum Testnet Goerli" instead of "Goerli"
+      // Use long form name for Ethereum networks e.g. "Ethereum Testnet Goerli" instead of "Goerli"

95-95: Grammar correction in comment

In the comment on line 95, consider changing "different that" to "different from" for grammatical accuracy.

Apply this diff to correct the grammar:

-   * This is different that checking for verification support i.e. supported: true or monitoring support i.e. monitored: true
+   * This is different from checking for verification support i.e. supported: true or monitoring support i.e. monitored: true
services/server/src/server/cli.ts (1)

258-258: Set 'saveUninitialized' to false

Setting saveUninitialized to false prevents storing uninitialized sessions, enhancing security and compliance.

services/server/src/server/server.ts (1)

Line range hint 224-257: Handle undefined rateLimit properties to prevent runtime errors

The rateLimit configuration properties windowMs, max, and whitelist are optional in ServerOptions, but they are accessed without checks. If any of these are undefined, it may cause unexpected behavior or runtime errors.

Ensure default values are provided for these properties or validate them before use. For example:

const hideIpInLogs = options.rateLimit.hideIpInLogs;
+ const windowMs = options.rateLimit.windowMs || 15 * 60 * 1000; // default 15 minutes
+ const max = options.rateLimit.max || 100; // default 100 requests
- windowMs: options.rateLimit.windowMs,
- max: options.rateLimit.max,
+ windowMs: windowMs,
+ max: max,

const whitelist = options.rateLimit.whitelist as string[];
+ if (!whitelist) {
+   whitelist = [];
+ }
services/server/src/server/controllers/verification/verification.common.ts (1)

Missing solc Parameter in createCheckedContract Calls

Several invocations of createCheckedContract are missing the required solc parameter, which could lead to runtime errors.

Affected files:

  • services/server/src/server/controllers/verification/verification.common.ts
  • services/server/src/server/controllers/verification/etherscan/stateless/etherscan.stateless.handlers.ts
Analysis chain

Line range hint 27-33: Ensure all calls to 'createCheckedContract' include the new 'solc' parameter

The function createCheckedContract now requires solc as a parameter. Please verify that all invocations of this function have been updated to pass the solc compiler instance to prevent runtime errors.

Run the following script to locate calls to createCheckedContract that may need updating:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to 'createCheckedContract' in the codebase.
rg --type ts $'createCheckedContract('

Length of output: 143


Script:

#!/bin/bash
# Description: Find all calls to 'createCheckedContract' in the codebase.
rg -F --type ts 'createCheckedContract('

Length of output: 610

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 63eb5fb and c356803.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (43)
  • .vscode/launch.json (1 hunks)
  • packages/lib-sourcify/test/compiler/solidityCompiler.ts (1 hunks)
  • serverless/compiler-lambda/index.js (1 hunks)
  • services/server/README.md (1 hunks)
  • services/server/package.json (1 hunks)
  • services/server/src/common/errors/GenericErrorHandler.ts (1 hunks)
  • services/server/src/server/cli.ts (1 hunks)
  • services/server/src/server/common.ts (0 hunks)
  • services/server/src/server/controllers/controllers.common.ts (2 hunks)
  • services/server/src/server/controllers/repository/repository.handlers.ts (6 hunks)
  • services/server/src/server/controllers/verification/etherscan/etherscan.common.ts (2 hunks)
  • services/server/src/server/controllers/verification/etherscan/session/etherscan.session.handlers.ts (3 hunks)
  • services/server/src/server/controllers/verification/etherscan/stateless/etherscan.stateless.handlers.ts (1 hunks)
  • services/server/src/server/controllers/verification/session-state/session-state.handlers.ts (4 hunks)
  • services/server/src/server/controllers/verification/solc-json/session/solc-json.session.handlers.ts (3 hunks)
  • services/server/src/server/controllers/verification/solc-json/stateless/solc-json.stateless.handlers.ts (5 hunks)
  • services/server/src/server/controllers/verification/verification.common.ts (7 hunks)
  • services/server/src/server/controllers/verification/verify/session/verify.session.handlers.ts (2 hunks)
  • services/server/src/server/controllers/verification/verify/stateless/verify.stateless.handlers.ts (7 hunks)
  • services/server/src/server/controllers/verification/verify/stateless/verify.stateless.routes.ts (1 hunks)
  • services/server/src/server/routes.ts (2 hunks)
  • services/server/src/server/server.ts (9 hunks)
  • services/server/src/server/services/StorageService.ts (1 hunks)
  • services/server/src/server/services/VerificationService.ts (4 hunks)
  • services/server/src/server/services/compiler/lambda-with-fallback/SolcLambdaWithLocalFallback.ts (1 hunks)
  • services/server/src/server/services/compiler/lambda/SolcLambda.ts (2 hunks)
  • services/server/src/server/services/compiler/local/SolcLocal.ts (1 hunks)
  • services/server/src/server/services/compiler/local/compilerWorker.ts (1 hunks)
  • services/server/src/server/services/compiler/local/solidityCompiler.ts (8 hunks)
  • services/server/src/server/services/storageServices/AbstractDatabaseService.ts (1 hunks)
  • services/server/src/server/services/storageServices/RepositoryV1Service.ts (2 hunks)
  • services/server/src/server/services/storageServices/RepositoryV2Service.ts (1 hunks)
  • services/server/src/server/services/storageServices/SourcifyDatabaseService.ts (4 hunks)
  • services/server/src/server/session.ts (1 hunks)
  • services/server/src/sourcify-chain-repository.ts (1 hunks)
  • services/server/src/sourcify-chains.ts (2 hunks)
  • services/server/test/helpers/ServerFixture.ts (6 hunks)
  • services/server/test/integration/etherscan.spec.ts (0 hunks)
  • services/server/test/integration/path-sanitization.spec.ts (4 hunks)
  • services/server/test/integration/verification-handlers/verify.session.spec.ts (4 hunks)
  • services/server/test/integration/verification-handlers/verify.stateless.spec.ts (2 hunks)
  • services/server/test/unit/VerificationService.spec.ts (1 hunks)
  • services/server/test/unit/utils/contract-creation-util.spec.ts (7 hunks)
Files not reviewed due to no reviewable changes (2)
  • services/server/src/server/common.ts
  • services/server/test/integration/etherscan.spec.ts
Files skipped from review due to trivial changes (1)
  • serverless/compiler-lambda/index.js
Additional context used
Biome
services/server/src/sourcify-chain-repository.ts

[error] 51-51: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (72)
services/server/src/server/services/compiler/local/compilerWorker.ts (1)

4-21: Changes look good. Watch for downstream effects.

The new solJsonRepoPath parameter allows for more flexible compiler initialization. Ensure all call sites are updated.

services/server/src/server/services/compiler/local/SolcLocal.ts (2)

9-12: Constructor looks good.


19-25: Compile method updated correctly.

services/server/src/common/errors/GenericErrorHandler.ts (1)

9-10: Good comment addition.

Explains the _next parameter's purpose. Nice touch with the ESLint directive.

services/server/src/server/controllers/verification/verify/stateless/verify.stateless.routes.ts (1)

14-26: Middleware added for verifyDeprecated check.

New middleware checks app context for verifyDeprecated setting. Looks good, but ensure verifyDeprecated is set correctly in the app context.

Verification successful

verifyDeprecated is correctly set and retrieved from app context. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify `verifyDeprecated` setting in app context
rg --type typescript 'app\.set\("verifyDeprecated"'

Length of output: 88


Script:

#!/bin/bash
# Verify `verifyDeprecated` setting in app context by searching .ts and .tsx files
rg 'app\.set\("verifyDeprecated"' --glob '*.ts' --glob '*.tsx'

Length of output: 165

services/server/src/server/controllers/verification/solc-json/session/solc-json.session.handlers.ts (3)

9-12: New imports look good.


20-21: Changes align with modularization goals.

Also applies to: 35-37


50-50: Consistent change in function call.

services/server/src/server/controllers/verification/verify/session/verify.session.handlers.ts (4)

9-9: New imports look good.

Also applies to: 12-13


19-22: Service retrieval from app context: Nice!


59-64: Updated params for verifyContractsInSession: Good to go!


Line range hint 1-68: Overall changes look solid.

The refactoring improves modularity without introducing bugs. Nice work!

services/server/src/server/controllers/controllers.common.ts (1)

7-7: New import looks good.

The Services type import enhances type safety.

services/server/src/server/routes.ts (1)

9-9: LGTM: Import added for ChainRepository.

services/server/test/unit/VerificationService.spec.ts (1)

66-67: New params for VerificationService. Check impact.

The changes look good, aligning with the PR objectives. Ensure these new params are properly handled in the VerificationService implementation.

services/server/src/server/services/compiler/lambda/SolcLambda.ts (1)

50-50: LGTM: Function name now configurable.

Change aligns with new constructor, allowing dynamic function name setting.

services/server/package.json (4)

5-5: Main entry point added. Good.


6-6: TypeScript types added. Nice.


7-7: Executable file specified. Looks good.


15-15: Start script updated to use CLI. Consistent with other changes.

Verification successful

Start script correctly updated to use CLI. Consistent with other changes.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistency of main, bin, and start script
grep -E '"main"|"bin"|"start"' package.json

Length of output: 45


Script:

#!/bin/bash
# Verify the "start" script in services/server/package.json
grep -E '"start"' services/server/package.json

Length of output: 90

services/server/test/unit/utils/contract-creation-util.spec.ts (7)

3-4: LGTM: Import changes look good.


8-9: LGTM: ChainRepository initialization looks good.


47-48: LGTM: Consistent ChainRepository initialization.


67-68: LGTM: Consistent ChainRepository initialization.


87-88: LGTM: Consistent ChainRepository initialization.


107-108: LGTM: Consistent ChainRepository initialization.


132-133: LGTM: Consistent ChainRepository initialization in remaining test cases.

Also applies to: 152-153

.vscode/launch.json (1)

11-11: LGTM. Aligns with modularization goal.

Path update reflects server module split into declarative and CLI parts.

services/server/src/server/controllers/repository/repository.handlers.ts (6)

40-40: LGTM. Service retrieval standardized.

Also applies to: 44-44


64-64: Looks good. Consistent with previous changes.

Also applies to: 67-67


82-82: Approved. Maintains consistency with other changes.

Also applies to: 86-86


111-111: Approved, but verify performServiceOperation.
Ensure this method exists and accepts the given parameters.

Also applies to: 119-122


165-166: LGTM. Double-check performServiceOperation.
Confirm method existence and parameter compatibility.


182-182: Approved. Verify performServiceOperation usage.
Ensure method exists and accepts given parameters.

Also applies to: 190-193

services/server/src/server/services/storageServices/RepositoryV2Service.ts (1)

16-16: Verify unused imports removal.

Imports for MatchLevel and RepositoryTag were removed. Ensure they're not used elsewhere in the file to avoid compilation errors.

Verification successful

Unused imports successfully removed. No references to MatchLevel or RepositoryTag found in the file.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining usage of MatchLevel or RepositoryTag
rg --type typescript 'MatchLevel|RepositoryTag' services/server/src/server/services/storageServices/RepositoryV2Service.ts

Length of output: 159


Script:

#!/bin/bash
# Check for any remaining usage of MatchLevel or RepositoryTag without specifying file type
rg 'MatchLevel|RepositoryTag' services/server/src/server/services/storageServices/RepositoryV2Service.ts

Length of output: 217

services/server/src/server/controllers/verification/etherscan/etherscan.common.ts (1)

3-7: New import looks good.

The addition of ISolidityCompiler aligns with the function signature update.

services/server/test/integration/path-sanitization.spec.ts (4)

14-15: New imports look good.

The added imports align with the changes in the underlying storage service logic.


70-73: Path update looks good.

The change from serverFixture.server.repository to serverFixture.repositoryV1Path is consistent with the refactoring.


141-143: Path update looks good.

The change from serverFixture.server.repository to serverFixture.repositoryV1Path is consistent with the refactoring.


236-238: Path update looks good.

The change from serverFixture.server.repository to serverFixture.repositoryV1Path is consistent with the refactoring.

services/server/src/server/controllers/verification/verify/stateless/verify.stateless.handlers.ts (4)

9-9: New imports look good.

Also applies to: 19-20


26-29: Service access improved, but check chain existence.

The new way of accessing services is good. But ensure sourcifyChainMap[req.body.chain] always exists.

Also applies to: 76-78, 90-92


100-100: Storage access looks good.

Also applies to: 109-109


118-119: Service access good, but why comment out creationLinkReferences?

New service access is fine. But why remove creationLinkReferences? Might it break something?

Also applies to: 190-190

services/server/README.md (1)

29-37: Storage config updated. Check if it aligns with current implementation.

The writeOrWarn is now an empty array, and writeOrErr structure is corrected. Ensure this matches the current server behavior.

packages/lib-sourcify/test/compiler/solidityCompiler.ts (1)

179-180: LGTM! Improved variable naming.

The change from repoPath to compilersPath enhances code clarity.

services/server/src/server/services/storageServices/RepositoryV1Service.ts (3)

36-36: LGTM: New property added

The repositoryServerUrl property is correctly added and typed.


40-40: LGTM: Constructor updated

The constructor now correctly initializes the new repositoryServerUrl property from the options.


73-73: LGTM: Updated to use instance property

The method now correctly uses this.repositoryServerUrl. Note the TODO about using a relative URL in the future.

services/server/src/server/services/storageServices/SourcifyDatabaseService.ts (4)

25-25: LGTM: Import statement updated.

The removal of the config import aligns with the refactoring goal.


39-39: New property added for server URL.

The repositoryV1ServerUrl property centralizes the server URL management.


46-46: Constructor updated to accept server URL.

The constructor now takes repositoryV1ServerUrl as a parameter and assigns it to the class property.

Also applies to: 50-50


425-425: Server URL usage updated in methods.

The getTree and getContent methods now use this.repositoryV1ServerUrl instead of config.get("repositoryV1.serverUrl").

Also applies to: 435-435

services/server/src/server/services/storageServices/AbstractDatabaseService.ts (1)

1-1: Unused import removed. Good job!

services/server/test/integration/verification-handlers/verify.session.spec.ts (2)

345-345: Simplified promise chain.

Removed unused parameter in the promise chain. Good cleanup.


Line range hint 376-380: Updated file path references.

File path references now use serverFixture.repositoryV1Path instead of serverFixture.server.repository. Ensure this change is consistent with the new structure.

Also applies to: 394-398

services/server/test/integration/verification-handlers/verify.stateless.spec.ts (1)

572-572: LGTM! Consistent path updates.

The changes look good. Repository path consistently updated.

Also applies to: 850-850

services/server/src/server/session.ts (1)

5-7: LGTM!

The function now accepts sessionOptions, simplifying the session middleware configuration.

services/server/src/server/controllers/verification/etherscan/stateless/etherscan.stateless.handlers.ts (3)

15-19: Initialization of services, chainRepository, and solc

The retrieval and initialization of services, chainRepository, and solc from req.app are correctly implemented.


47-47: Verify compatibility of storeMatch with updated parameters

Ensure that services.storage.storeMatch correctly handles checkedContract and match with the new changes.

Run the following script to confirm the parameters of storeMatch:

#!/bin/bash
# Description: Check the definition of storeMatch and its expected arguments.

# Test: Search for the method definition. Expect: It accepts checkedContract and match as parameters.
fd --type f "storage.ts" | xargs rg "storeMatch"

# Alternatively, use ast-grep to find the function signature.
ast-grep --lang typescript --pattern 'storeMatch($_$)'

43-43: Confirm verifyDeployed accepts sourcifyChain

Ensure that the verifyDeployed method accepts sourcifyChain as an argument. If it previously expected a chain ID string, this change might require adjustments.

Run the following script to verify the parameters of verifyDeployed:

services/server/src/server/controllers/verification/solc-json/stateless/solc-json.stateless.handlers.ts (1)

15-17: Verify that services are properly initialized.

Ensure that services, solc, and chainRepository are available in req.app to prevent possible undefined errors.

services/server/src/server/controllers/verification/session-state/session-state.handlers.ts (1)

23-24: Verify correctness of import paths

Ensure that the relative paths for importing Services and ChainRepository are accurate. Incorrect paths could lead to module resolution errors during runtime.

services/server/test/helpers/ServerFixture.ts (1)

56-56: Verify all references to 'fixtureOptions_'

The constructor parameter has been renamed to fixtureOptions_. Please ensure that all references to the old parameter name options_ within the class have been updated to prevent any undefined variable errors.

services/server/src/server/server.ts (1)

341-343: [Duplicate Comment] Entry point consideration already addressed

A previous review comment discussed consolidating entry points to reduce confusion. Since this has been addressed, no further action is needed here.

services/server/src/server/services/compiler/local/solidityCompiler.ts (5)

10-10: Import of ISolidityCompiler added.

The addition of ISolidityCompiler to the imports improves type safety and code clarity.


Line range hint 98-129: Updated useCompiler function to accept repository paths.

The useCompiler function now includes solcRepoPath and solJsonRepoPath parameters, enhancing flexibility in specifying compiler locations.


179-200: Refactored getAllMetadataAndSourcesFromSolcJson to use ISolidityCompiler.

The function signature now accepts solc: ISolidityCompiler, which streamlines the compilation process and promotes modularity.


224-229: Modified getSolcExecutable to include solcRepoPath.

The function now accepts solcRepoPath as a parameter, allowing dynamic specification of the compiler executable's repository path.


331-354: Enhanced getSolcJs to accept solJsonRepoPath.

By adding the solJsonRepoPath parameter, the function gains increased flexibility in locating the Solidity JSON files.

services/server/src/server/controllers/verification/verification.common.ts (2)

213-216: Update 'checkContractsInSession' calls with the new 'solc' parameter

The function checkContractsInSession now accepts solc as a parameter. Ensure all calls to this function pass the solc instance to maintain proper functionality.

Run the following script to find usages of checkContractsInSession:

#!/bin/bash
# Description: Find all calls to 'checkContractsInSession' in the codebase.
rg --type ts $'checkContractsInSession('

331-338: Verify 'verifyContractsInSession' invocations include 'solc' and 'chainRepository'

The function verifyContractsInSession now requires solc and chainRepository as parameters. Please check that all invocations have been updated accordingly to prevent potential issues.

Run the following script to identify calls to verifyContractsInSession:

#!/bin/bash
# Description: Find all calls to 'verifyContractsInSession' in the codebase.
rg --type ts $'verifyContractsInSession('

@RaoulSchaffranek
Copy link
Contributor Author

Tests are passing if you want to check the comments @RaoulSchaffranek

Thanks for pushing this forward. I gave this PR another pass, and I believe I addressed all the comments you had for me. Could you let me know if I missed something?

@kuzdogan
Copy link
Member

@RaoulSchaffranek all good from your side, thanks. Just working out the final details and that everyone in the team becomes aware of the changes. Thankyou!

@kuzdogan
Copy link
Member

@marcocastignoli need approval here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: COMPLETED
Development

Successfully merging this pull request may close these issues.

3 participants