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

Simplifying chain expansion #32

Merged
merged 1 commit into from
Sep 27, 2024
Merged

Simplifying chain expansion #32

merged 1 commit into from
Sep 27, 2024

Conversation

Inkvi
Copy link
Collaborator

@Inkvi Inkvi commented Sep 20, 2024

Creating a new processor for each file is no longer required. The processor can be fully controlled via env vars and a config file.

Summary by CodeRabbit

  • New Features

    • Repository renamed to evm-indexer, reflecting broader functionality.
    • Updated quickstart section with simplified commands for processing Optimism and Base chains.
    • Streamlined setup instructions for new chains, enhancing configurability.
  • Bug Fixes

    • Improved handling of environment variables for better clarity and functionality.
  • Refactor

    • Consolidated multiple processor commands into a single, generic command structure.
    • Removed redundant processor files, simplifying the codebase.
  • Documentation

    • Enhanced README with detailed explanations of new configurations and commands.

@Inkvi Inkvi requested review from dshiell and mvpoyatt September 20, 2024 18:58
Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

The pull request introduces significant changes to the repository, including a renaming from multichain-transfers-example to evm-indexer, reflecting an expanded functionality beyond USDC transfers. Modifications include a streamlined command structure for processing various blockchain transactions, enhancements to configuration options, and the removal of specific processor files. The updates aim to simplify the setup and execution of multichain transfers, improving overall flexibility and ease of use.

Changes

File(s) Change Summary
README.md Removed initial project description and USDC Transfer references; updated quickstart section for new repository name; simplified commands for Optimism and Base chains; streamlined setup instructions and environment variables.
commands.json Consolidated individual processor commands into a general "process" command; updated command entries to point to a single processor file; simplified production command structure.
squid.yaml Simplified command arguments for processors; replaced specific RPC endpoint variables with a unified PROCESSOR_NAME variable for both processors.
src/chains/backfill.ts, Deleted file responsible for backfill processing; removed invocation of runProcessor for backfill tasks.
src/chains/optimism.ts, Deleted file for processing Optimism transactions; removed invocation of runProcessor.
src/chains/wallets/base.ts, Deleted file for processing base wallet transactions; removed invocation of runProcessor.
src/chains/wallets/eth.ts, Deleted file for processing Ethereum transactions; removed invocation of runProcessor.
src/chains/wallets/optimism.ts Deleted file for processing Optimism wallet transactions; removed invocation of runProcessor.
src/chains/processor.ts Updated runProcessor invocation to remove the first parameter, simplifying the call.
src/utils/ibc-processor.ts Enhanced ConfigSchema with optional parameters; updated IbcProcessor and runProcessor function signatures for improved configurability and error handling.

Possibly related PRs

  • Connect fee entities with their relevant sources (send packet and open channel) #18: This PR involves modifications to the command configurations for processors related to fee management, which aligns with the main PR's updates on configuration structures and command simplifications for multichain transfers.
  • Track wallet txs in OP and Base  #23: This PR focuses on tracking wallet transactions in the Optimism and Base networks, which is relevant to the main PR's updates on processing commands for these specific chains.
  • Simplify chain expansion #31: The refactoring of the IBC processor setup in this PR complements the main PR's changes to streamline the configuration and execution processes for multichain transfers, enhancing overall usability and integration.

Suggested reviewers

  • dshiell
  • mvpoyatt

Poem

🐇 In the meadow where bunnies play,
Changes hop in a joyful sway.
Transfers now across the chain,
Simplified paths, no more strain.
With every leap, a new command,
Together we build, oh so grand! 🌼


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

@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: 6

Outside diff range and nitpick comments (3)
README.md (1)

73-124: Excellent work on streamlining the process for adding new chains!

The instructions are clear, well-structured, and provide a comprehensive guide for setting up indexing for new chains. The use of a configuration file and environment variables allows for great flexibility and customization.

A few suggestions:

  • Consider adding a note about the precedence order of environment variables and configuration values to clarify which takes priority when both are specified.
  • It might be helpful to provide some example configuration files or environment variable setups for common chains to serve as a starting point for users.

Do you want me to generate some example configuration files or environment variable setups for popular EVM-based chains to include in the documentation?

Tools
LanguageTool

[uncategorized] ~96-~96: Loose punctuation mark.
Context: ...or the new chain: - PROCESSOR_NAME: Set this to your chosen processor name ...

(UNLIKELY_OPENING_PUNCTUATION)

src/utils/ibc-processor.ts (2)

25-33: Clarify Error Message for Missing Processor Name

The error message when processorName is missing could be more informative by indicating both the missing function argument and the environment variable.

Apply this diff to improve the error message:

if (!processorName) {
  throw new Error(
-   'PROCESSOR_NAME environment variable is not set'
+   'Processor name is not provided and PROCESSOR_NAME environment variable is not set'
  )
}

50-52: Ensure Complete Environment Variable Interpolation

While transactions and contracts are interpolated with environment variables, consider applying interpolation to all string values within the config to maintain consistency and prevent potential misconfigurations.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b216cf3 and 12193f9.

Files selected for processing (10)
  • README.md (3 hunks)
  • commands.json (1 hunks)
  • squid.yaml (1 hunks)
  • src/chains/backfill.ts (0 hunks)
  • src/chains/optimism.ts (0 hunks)
  • src/chains/processor.ts (1 hunks)
  • src/chains/wallets/base.ts (0 hunks)
  • src/chains/wallets/eth.ts (0 hunks)
  • src/chains/wallets/optimism.ts (0 hunks)
  • src/utils/ibc-processor.ts (4 hunks)
Files not reviewed due to no reviewable changes (5)
  • src/chains/backfill.ts
  • src/chains/optimism.ts
  • src/chains/wallets/base.ts
  • src/chains/wallets/eth.ts
  • src/chains/wallets/optimism.ts
Additional context used
LanguageTool
README.md

[uncategorized] ~96-~96: Loose punctuation mark.
Context: ...or the new chain: - PROCESSOR_NAME: Set this to your chosen processor name ...

(UNLIKELY_OPENING_PUNCTUATION)

Biome
src/utils/ibc-processor.ts

[error] 98-98: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 108-108: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

Additional comments not posted (10)
src/chains/processor.ts (1)

4-4: Verify that removing the 'base' argument doesn't break existing functionality.

The change to the runProcessor function call aligns with the PR objective of simplifying the file processing workflow. However, please ensure that removing the 'base' argument doesn't break any existing functionality or dependencies in the codebase.

Run the following script to verify the impact of this change:

Verification successful

Removal of 'base' argument from runProcessor is verified and consistent

The change to runProcessor(handler) in src/chains/processor.ts has been verified and found to be consistent with the rest of the codebase. Here are the key findings:

  1. The runProcessor function is defined in src/utils/ibc-processor.ts and only expects a single argument (handler).
  2. No other instances of runProcessor being called with 'base' as the first argument were found in the codebase.
  3. The change aligns with the function's definition and usage across the project.

Based on this analysis, the removal of the 'base' argument appears to be a deliberate API simplification that doesn't break existing functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that removing the 'base' argument from runProcessor doesn't break existing functionality.

# Test 1: Search for usage of the 'base' argument in the runProcessor function. Expect: No occurrences.
rg --type typescript $'runProcessor\(\'base\'' 

# Test 2: Search for the runProcessor function usage. Expect: Only occurrences with a single argument.
rg --type typescript -A 5 $'runProcessor\('

Length of output: 166


Script:

#!/bin/bash
# Description: Verify the usage of runProcessor function after the removal of 'base' argument

# Find TypeScript and JavaScript files
fd '\.(ts|js)$' | xargs grep -n -A 5 "runProcessor(" | grep -v "^--$"

# Search for any remaining instances of 'base' as the first argument
fd '\.(ts|js)$' | xargs grep -n "runProcessor('base'" 
fd '\.(ts|js)$' | xargs grep -n 'runProcessor("base"' 

Length of output: 708

squid.yaml (4)

13-13: LGTM!

The simplification of the command argument for the optimism-processor aligns with the PR objective of streamlining the processing workflow. This change allows for more flexible control over the processor's behavior through external configurations.


15-15: LGTM!

The update to the environment variable for the optimism-processor aligns with the PR objective of centralizing control over the processor's behavior through external configurations. Setting PROCESSOR_NAME to optimism clearly indicates the intended chain for this processor.


19-19: LGTM!

The simplification of the command argument for the base-processor aligns with the PR objective of streamlining the processing workflow. This change allows for more flexible control over the processor's behavior through external configurations.


21-21: LGTM!

The update to the environment variable for the base-processor aligns with the PR objective of centralizing control over the processor's behavior through external configurations. Setting PROCESSOR_NAME to base clearly indicates the intended chain for this processor.

commands.json (2)

47-50: Simplified command structure and improved configuration flexibility.

The changes to the "process" command definition are a great improvement:

  • Consolidating multiple processor commands into a single generic command simplifies the overall command structure and reduces duplication.
  • Using the "--require=dotenv/config" flag to load environment variables from a .env file provides flexibility in configuring the processor without modifying the code.
  • Keeping the "build" and "migration:apply" dependencies ensures that the project is properly set up before running the processor.

Well done!


52-55: Simplified production command and improved environment handling.

The changes to the "process:prod" command definition are appropriate for a production environment:

  • Consolidating multiple production processor commands into a single generic command simplifies the overall command structure and reduces duplication.
  • Removing the "--require=dotenv/config" flag indicates that the production environment should be configured through other means, such as system environment variables. This is a good practice for production environments.
  • Removing the "build" dependency suggests that the production command assumes the project is already built, which is a reasonable assumption for a production setup.
  • Keeping the command hidden from the user is appropriate for a production command.

Just ensure that the production environment is properly configured with the necessary environment variables and that the project is pre-built before running this command.

README.md (2)

8-9: LGTM!

The repository URL and name have been updated correctly to reflect the project's expanded scope.


30-31: LGTM!

The commands to run the Optimism and Base processors separately are correct and consistent with the project's focus on EVM-based chains.

src/utils/ibc-processor.ts (1)

14-20: ConfigSchema Enhancement Looks Good

The addition of optional configuration parameters enhances flexibility. The schema changes are appropriate and well-defined.

Comment on lines +92 to 86
let rpcRateLimit = config[processorName]?.rpcRateLimit ?? Number(process.env.RPC_RATE_LIMIT)
if (rpcRateLimit === undefined) {
throw new Error(`Missing RPC rate limit`)
}
Copy link

Choose a reason for hiding this comment

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

Validate Numeric Configuration to Handle NaN Values

When parsing numeric environment variables, Number(...) can return NaN if the value is invalid or undefined. Checking rpcRateLimit === undefined won't catch NaN. Use Number.isNaN to ensure the value is a valid number.

Apply this diff to fix the issue:

let rpcRateLimit = config[processorName]?.rpcRateLimit ?? Number(process.env.RPC_RATE_LIMIT)
- if (rpcRateLimit === undefined) {
+ if (Number.isNaN(rpcRateLimit)) {
    throw new Error(`Missing or invalid RPC rate limit`)
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let rpcRateLimit = config[processorName]?.rpcRateLimit ?? Number(process.env.RPC_RATE_LIMIT)
if (rpcRateLimit === undefined) {
throw new Error(`Missing RPC rate limit`)
}
let rpcRateLimit = config[processorName]?.rpcRateLimit ?? Number(process.env.RPC_RATE_LIMIT)
if (Number.isNaN(rpcRateLimit)) {
throw new Error(`Missing or invalid RPC rate limit`)
}

Comment on lines +107 to 101
let customMaxBatchCallSize = Number(process.env[`${capProcessorName}_MAX_BATCH_CALL_SIZE`])
if (!isNaN(customMaxBatchCallSize)) {
maxBatchCallSize = customMaxBatchCallSize
}
Copy link

Choose a reason for hiding this comment

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

Use Number.isNaN Instead of isNaN for Type-Safe Checks

Consistent with the previous recommendation, replace isNaN with Number.isNaN to avoid type coercion issues.

Apply this diff to fix the issue:

let customMaxBatchCallSize = Number(process.env[`${capProcessorName}_MAX_BATCH_CALL_SIZE`])
- if (!isNaN(customMaxBatchCallSize)) {
+ if (!Number.isNaN(customMaxBatchCallSize)) {
    maxBatchCallSize = customMaxBatchCallSize
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let customMaxBatchCallSize = Number(process.env[`${capProcessorName}_MAX_BATCH_CALL_SIZE`])
if (!isNaN(customMaxBatchCallSize)) {
maxBatchCallSize = customMaxBatchCallSize
}
let customMaxBatchCallSize = Number(process.env[`${capProcessorName}_MAX_BATCH_CALL_SIZE`])
if (!Number.isNaN(customMaxBatchCallSize)) {
maxBatchCallSize = customMaxBatchCallSize
}
Tools
Biome

[error] 108-108: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

Comment on lines +97 to 91
let customRateLimit = Number(process.env[`${capProcessorName}_RPC_RATE_LIMIT`])
if (!isNaN(customRateLimit)) {
rpcRateLimit = customRateLimit
}
Copy link

Choose a reason for hiding this comment

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

Use Number.isNaN Instead of isNaN for Type-Safe Checks

The use of isNaN can lead to unexpected results due to type coercion. It's safer to use Number.isNaN, which doesn't coerce the argument.

Apply this diff to fix the issue:

let customRateLimit = Number(process.env[`${capProcessorName}_RPC_RATE_LIMIT`])
- if (!isNaN(customRateLimit)) {
+ if (!Number.isNaN(customRateLimit)) {
    rpcRateLimit = customRateLimit
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let customRateLimit = Number(process.env[`${capProcessorName}_RPC_RATE_LIMIT`])
if (!isNaN(customRateLimit)) {
rpcRateLimit = customRateLimit
}
let customRateLimit = Number(process.env[`${capProcessorName}_RPC_RATE_LIMIT`])
if (!Number.isNaN(customRateLimit)) {
rpcRateLimit = customRateLimit
}
Tools
Biome

[error] 98-98: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

Comment on lines +102 to +95
let maxBatchCallSize = config[processorName]?.maxBatchCallSize ?? Number(process.env.MAX_BATCH_CALL_SIZE ?? "100")
if (maxBatchCallSize === undefined) {
throw new Error(`Missing max batch call size`)
Copy link

Choose a reason for hiding this comment

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

Validate Numeric Configuration to Handle NaN Values

Similar to rpcRateLimit, ensure that maxBatchCallSize is a valid number and not NaN.

Apply this diff to fix the issue:

let maxBatchCallSize = config[processorName]?.maxBatchCallSize ?? Number(process.env.MAX_BATCH_CALL_SIZE ?? "100")
- if (maxBatchCallSize === undefined) {
+ if (Number.isNaN(maxBatchCallSize)) {
    throw new Error(`Missing or invalid max batch call size`)
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let maxBatchCallSize = config[processorName]?.maxBatchCallSize ?? Number(process.env.MAX_BATCH_CALL_SIZE ?? "100")
if (maxBatchCallSize === undefined) {
throw new Error(`Missing max batch call size`)
let maxBatchCallSize = config[processorName]?.maxBatchCallSize ?? Number(process.env.MAX_BATCH_CALL_SIZE ?? "100")
if (Number.isNaN(maxBatchCallSize)) {
throw new Error(`Missing or invalid max batch call size`)

Comment on lines +130 to +123
let finalityConfirmation = config[processorName]?.finalityConfirmation ?? Number(process.env.FINALITY_CONFIRMATION);
if (finalityConfirmation) {
processor = processor.setFinalityConfirmation(Number(finalityConfirmation))
processor = processor.setFinalityConfirmation(finalityConfirmation)
Copy link

Choose a reason for hiding this comment

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

Validate Numeric Configuration for finalityConfirmation

Ensure that finalityConfirmation is validated against NaN to prevent unintended behavior.

Apply this diff to fix the issue:

let finalityConfirmation = config[processorName]?.finalityConfirmation ?? Number(process.env.FINALITY_CONFIRMATION);
- if (finalityConfirmation) {
+ if (!Number.isNaN(finalityConfirmation)) {
    processor = processor.setFinalityConfirmation(finalityConfirmation)
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let finalityConfirmation = config[processorName]?.finalityConfirmation ?? Number(process.env.FINALITY_CONFIRMATION);
if (finalityConfirmation) {
processor = processor.setFinalityConfirmation(Number(finalityConfirmation))
processor = processor.setFinalityConfirmation(finalityConfirmation)
let finalityConfirmation = config[processorName]?.finalityConfirmation ?? Number(process.env.FINALITY_CONFIRMATION);
if (!Number.isNaN(finalityConfirmation)) {
processor = processor.setFinalityConfirmation(finalityConfirmation)

@Inkvi Inkvi force-pushed the inkvi/chain-expansion branch from 12193f9 to 0a00314 Compare September 20, 2024 20:35
@Inkvi Inkvi force-pushed the inkvi/chain-expansion branch from 0a00314 to 939b7fc Compare September 20, 2024 20:56
Copy link

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0a00314 and 939b7fc.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (11)
  • README.md (3 hunks)
  • commands.json (1 hunks)
  • package.json (0 hunks)
  • squid.yaml (1 hunks)
  • src/chains/backfill.ts (0 hunks)
  • src/chains/optimism.ts (0 hunks)
  • src/chains/processor.ts (1 hunks)
  • src/chains/wallets/base.ts (0 hunks)
  • src/chains/wallets/eth.ts (0 hunks)
  • src/chains/wallets/optimism.ts (0 hunks)
  • src/utils/ibc-processor.ts (4 hunks)
Files not reviewed due to no reviewable changes (6)
  • package.json
  • src/chains/backfill.ts
  • src/chains/optimism.ts
  • src/chains/wallets/base.ts
  • src/chains/wallets/eth.ts
  • src/chains/wallets/optimism.ts
Files skipped from review as they are similar to previous changes (2)
  • squid.yaml
  • src/chains/processor.ts
Additional context used
LanguageTool
README.md

[uncategorized] ~96-~96: Loose punctuation mark.
Context: ...or the new chain: - PROCESSOR_NAME: Set this to your chosen processor name ...

(UNLIKELY_OPENING_PUNCTUATION)

Biome
src/utils/ibc-processor.ts

[error] 89-89: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 99-99: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

Additional comments not posted (14)
commands.json (2)

47-50: LGTM!

The updated "process" command simplifies the processor execution by centralizing it to a single file lib/chains/processor.js. This change reduces redundancy and improves maintainability.

Loading the .env file allows for flexible configuration through environment variables, while keeping the dependencies unchanged ensures the necessary setup steps are performed before running the processor.

Overall, this change enhances the command structure and makes it easier to manage the processor execution.


52-55: Looks good!

Updating the "process:prod" command to use the same generic processor file lib/chains/processor.js ensures consistency between the development and production environments. This reduces the chances of errors caused by differences in the code.

Removing the .env file loading is appropriate for production, as the configuration should be managed through other means, such as environment variables set in the production environment.

Keeping the "migration:apply" dependency ensures the database is properly set up before running the processor in production.

Overall, this change simplifies the production command, aligns it with the development command, and promotes a consistent and reliable production setup.

src/utils/ibc-processor.ts (6)

13-19: LGTM!

The addition of new optional configuration parameters to the ConfigSchema enhances the flexibility and configurability of the IbcProcessor. The changes look good.


24-32: LGTM!

The updates to the IbcProcessor function signature and the handling of the processorName parameter improve usability and provide clear error handling. The changes look good.


44-47: LGTM!

The introduction of environment variable interpolation in the config file is a useful feature that enhances flexibility. The fallback behavior of keeping the placeholder if the environment variable is not found is a good approach. The changes look good.


78-106: LGTM!

The updates to the configuration value retrieval logic prioritize config values over environment variables, which provides a more consistent and manageable approach. The error handling for missing required values and the flexibility to set custom rate limits and max batch call sizes through processor-specific environment variables are valuable additions. Overall, the changes look good, with the exception of the isNaN usage mentioned in the previous comments.

Tools
Biome

[error] 89-89: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 99-99: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


109-123: LGTM!

The updates to the configuration value retrieval logic for gateway, fromBlock, and finalityConfirmation maintain consistency with the overall configuration approach. Setting the processor's properties based on the defined values allows for flexible configuration. The changes look good.


145-154: LGTM!

The changes to the return value of IbcProcessor and the corresponding updates in runProcessor improve code organization and readability. The version handling logic ensures that the configured version takes precedence and enforces the requirement for a valid version. Overall, the changes look good, with the exception of the version validation logic mentioned in the previous comment.

README.md (6)

8-9: LGTM!

The repository URL update aligns with the PR objective of renaming the repository to reflect expanded functionality.


30-31: LGTM!

The addition of commands for running Optimism and Base processors separately aligns with the PR objective of simplifying the command structure for processing various blockchain transactions. This change improves the flexibility of running individual processors.


73-89: Configuration structure updates look good!

The changes to the configuration file structure, including the addition of optional fields such as rpc, rpcRateLimit, maxBatchCallSize, gateway, fromBlock, finalityConfirmation, and version, simplify the process of adding a new chain for indexing. The ability to override these fields with environment variables provides flexibility in configuration.

These updates align with the PR objective of improving the ease of configuration and setup for handling multichain transfers.


92-93: Clarification and note are helpful!

The clarification about all fields being optional and the ability to override them with environment variables is helpful for users setting up the indexer. It provides flexibility in configuration and ensures that users are aware of the precedence of environment variables over configuration file values.

The note about the processor's behavior when contracts and transactions are omitted is also valuable, as it prevents unexpected behavior and informs users about the conditions under which the processor won't perform any actual work.


94-110: Environment variable instructions are comprehensive!

The instructions for setting environment variables for a new chain are clear and comprehensive. They cover both global environment variables and chain-specific overrides, providing flexibility in configuration.

The inclusion of variables such as PROCESSOR_NAME, CONFIG_FILE, {PROCESSOR_NAME}_RPC, {PROCESSOR_NAME}_GATEWAY, DISPATCHER_ADDRESS_{PROCESSOR_NAME}_START_BLOCK, {PROCESSOR_NAME}_VERSION, RPC_RATE_LIMIT, MAX_BATCH_CALL_SIZE, and FINALITY_CONFIRMATION ensures that users have control over various aspects of the indexer's behavior.

The chain-specific overrides for RPC_RATE_LIMIT and MAX_BATCH_CALL_SIZE allow for fine-grained configuration based on the requirements of each chain.

Tools
LanguageTool

[uncategorized] ~96-~96: Loose punctuation mark.
Context: ...or the new chain: - PROCESSOR_NAME: Set this to your chosen processor name ...

(UNLIKELY_OPENING_PUNCTUATION)


112-124: Instructions for running the processor are clear and emphasize benefits!

The instructions for running the processor for a new chain using the PROCESSOR_NAME environment variable are clear and straightforward. By simply specifying the desired processor name, users can easily run the processor with the configuration specific to that chain.

The emphasis on using the same processor code for multiple chains is a key benefit of this setup. It simplifies maintenance and reduces code duplication, as the same codebase can be used across different chains with minimal modifications. This approach promotes code reuse and makes it easier to manage the indexer for multiple chains.

The note at the end reinforces this benefit and highlights the flexibility of this setup in terms of running the processor for different chains with minimal changes.

Comment on lines +151 to +154
let version = process.env[`${processorName.toUpperCase()}_VERSION`] ?? config.version ?? 1;
if (!version) {
throw new Error('Version not set')
}
Copy link

Choose a reason for hiding this comment

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

Correct Version Validation Logic

Checking !version may incorrectly throw an error if version is 0. Since version defaults to 1, this might not be an immediate issue, but for robustness, consider validating whether version is a valid number.

Apply this diff to improve the check:

let version = process.env[`${processorName.toUpperCase()}_VERSION`] ?? config.version ?? 1;
- if (!version) {
+ if (Number.isNaN(Number(version))) {
    throw new Error('Invalid or missing version')
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let version = process.env[`${processorName.toUpperCase()}_VERSION`] ?? config.version ?? 1;
if (!version) {
throw new Error('Version not set')
}
let version = process.env[`${processorName.toUpperCase()}_VERSION`] ?? config.version ?? 1;
if (Number.isNaN(Number(version))) {
throw new Error('Invalid or missing version')
}

Comment on lines +99 to 100
if (!isNaN(customMaxBatchCallSize)) {
maxBatchCallSize = customMaxBatchCallSize
Copy link

Choose a reason for hiding this comment

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

Use Number.isNaN Instead of isNaN for Type-Safe Checks

Consistent with the previous recommendation, replace isNaN with Number.isNaN to avoid type coercion issues.

Apply this diff to fix the issue:

let customMaxBatchCallSize = Number(process.env[`${capProcessorName}_MAX_BATCH_CALL_SIZE`])
- if (!isNaN(customMaxBatchCallSize)) {
+ if (!Number.isNaN(customMaxBatchCallSize)) {
    maxBatchCallSize = customMaxBatchCallSize
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!isNaN(customMaxBatchCallSize)) {
maxBatchCallSize = customMaxBatchCallSize
if (!Number.isNaN(customMaxBatchCallSize)) {
maxBatchCallSize = customMaxBatchCallSize
Tools
Biome

[error] 99-99: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

Comment on lines +89 to 90
if (!isNaN(customRateLimit)) {
rpcRateLimit = customRateLimit
Copy link

Choose a reason for hiding this comment

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

Use Number.isNaN Instead of isNaN for Type-Safe Checks

The use of isNaN can lead to unexpected results due to type coercion. It's safer to use Number.isNaN, which doesn't coerce the argument.

Apply this diff to fix the issue:

let customRateLimit = Number(process.env[`${capProcessorName}_RPC_RATE_LIMIT`])
- if (!isNaN(customRateLimit)) {
+ if (!Number.isNaN(customRateLimit)) {
    rpcRateLimit = customRateLimit
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!isNaN(customRateLimit)) {
rpcRateLimit = customRateLimit
let customRateLimit = Number(process.env[`${capProcessorName}_RPC_RATE_LIMIT`])
if (!Number.isNaN(customRateLimit)) {
rpcRateLimit = customRateLimit
Tools
Biome

[error] 89-89: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

Copy link
Member

@dshiell dshiell left a comment

Choose a reason for hiding this comment

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

nice, unblocked

@mvpoyatt
Copy link
Contributor

@Inkvi Looking at the README it's not totally clear to me how to add a new chain. Are developers supposed to add a new configuration file, update an environment variable, or both? Can we update the .env already being tracked with examples, or do we need to add the env variable for them?

@Inkvi
Copy link
Collaborator Author

Inkvi commented Sep 27, 2024

@Inkvi Looking at the README it's not totally clear to me how to add a new chain. Are developers supposed to add a new configuration file, update an environment variable, or both? Can we update the .env already being tracked with examples, or do we need to add the env variable for them?

They can do either or both. Env vars take precedence over the config.

@Inkvi Inkvi merged commit 87f6466 into main Sep 27, 2024
4 checks passed
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