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

(Deposit/Withdraw) Update Nomic Relayers #3968

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

JoseRFelix
Copy link
Collaborator

Linear Task

https://linear.app/osmosis/issue/FE-1248/update-nomic-relayers-array

Testing and Verifying

  • Can deposit BTC or nBTC

Sorry, something went wrong.

Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
osmosis-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 4:16pm
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
osmosis-frontend-datadog ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 4:16pm
osmosis-frontend-dev ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 4:16pm
osmosis-frontend-edgenet ⬜️ Ignored (Inspect) Dec 2, 2024 4:16pm
osmosis-testnet ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 4:16pm

@JoseRFelix JoseRFelix requested review from a team November 25, 2024 23:44
Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes in this pull request modify the getNomicRelayerUrl function in the packages/utils/src/bitcoin.ts file. The function now returns an array of three URLs for the mainnet environment, replacing the previous single URL. The return value for the testnet environment remains unchanged. This adjustment alters the control flow of the function, specifically how it handles different environments.

Changes

File Path Change Summary
packages/utils/src/bitcoin.ts Updated getNomicRelayerUrl function to return an array of URLs for mainnet instead of a single URL. The testnet return value remains unchanged.

Possibly related PRs

Suggested reviewers

  • CryptoAssassin1
  • jonator

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/utils/src/bitcoin.ts

Oops! Something went wrong! :(

ESLint: 8.50.0

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/packages/utils/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


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: 0

🧹 Outside diff range and nitpick comments (3)
packages/bridge/src/nomic/index.ts (3)

Line range hint 101-103: Fix potential incorrect error handling of 'swapMessages'

The condition if (!swapMessages) may not function as intended because an empty array is truthy in JavaScript. If swapMessages is an empty array, the check will pass, but you might want to handle the case when it's empty. Consider adjusting the condition to check if the array is empty.

Apply this diff to fix the issue:

- if (!swapMessages) {
+ if (!swapMessages || swapMessages.length === 0) {
    throw new BridgeQuoteError({
      bridgeId: "Nomic",
      errorType: "CreateCosmosTxError",
      message: "Failed to get swap messages.",
    });
  }

Line range hint 158-160: Extract timeout calculation into a helper function for clarity

The calculation for timeoutTimestampFiveDaysFromNow is complex and could benefit from being extracted into a well-named helper function to improve readability and maintainability.

Example:

function calculateTimeoutTimestamp(daysFromNow: number): number {
  const now = Date.now();
  const millisecondsInDay = 86_400 * 1_000;
  const timeout = now + millisecondsInDay * daysFromNow - (now % (60 * 60 * 1_000));
  return timeout * 1_000_000; // Convert to nanoseconds
}

// Usage:
const timeoutTimestampFiveDaysFromNow = calculateTimeoutTimestamp(5);

Line range hint 320-323: Avoid using 'console.error' for error logging

Using console.error to log errors may expose sensitive information. Consider using a standardized logging mechanism that handles sensitive data appropriately or remove the logging statement if it's not necessary.

Apply this diff to remove the logging statement:

- console.error("Error parsing memo:", error);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 11449ab and 7e79824.

📒 Files selected for processing (1)
  • packages/bridge/src/nomic/index.ts (1 hunks)
🔇 Additional comments (1)
packages/bridge/src/nomic/index.ts (1)

65-69: LGTM: Added multiple relayer URLs for redundancy

The addition of multiple relayer URLs enhances reliability by providing redundancy for the mainnet environment.

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e79824 and 49e841d.

📒 Files selected for processing (1)
  • packages/utils/src/bitcoin.ts (1 hunks)
🔇 Additional comments (2)
packages/utils/src/bitcoin.ts (2)

50-52: Verify the authenticity and reliability of new relayer URLs

The new relayer URLs are from different providers. We should ensure these are official and trusted Nomic relayers.


49-53: Verify consumer compatibility with multiple relayer URLs

The change from a single URL to an array of URLs might require updates in consuming code to handle multiple relayers (e.g., for failover or load balancing).

✅ Verification successful

Let me analyze the usage of getNomicRelayerUrl to verify if the consumers handle multiple URLs correctly.


Let me check the nomic-bitcoin package's implementation to understand how it handles the relayers array.


Based on the analysis of the codebase, I can now provide a final response:

The array of relayer URLs is safely handled by consumers

The code inspection shows that all consumers of getNomicRelayerUrl are already designed to work with an array of URLs:

  1. The NomicBridge class explicitly types relayers as string[]
  2. All usages pass the array directly to the underlying nomic-bitcoin functions without attempting to access a single URL
  3. The implementation maintains backward compatibility as the previous single URL was also returned as a single-element array
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of getNomicRelayerUrl to verify they can handle an array of URLs

# Search for function usage patterns
echo "Searching for direct usage of getNomicRelayerUrl..."
ast-grep --pattern 'getNomicRelayerUrl($$$)'

# Look for array operations on the result
echo "Checking how the result is used..."
rg -A 5 "getNomicRelayerUrl"

Length of output: 4113


Script:

#!/bin/bash
# Let's check the implementation in nomic-bitcoin package to see how relayers are handled
rg -A 10 "relayers:" packages/bridge/src/nomic

# Also check the type definitions
ast-grep --pattern 'interface $_ {
  $$$
  relayers: $$$
  $$$
}'

Length of output: 3332


Script:

#!/bin/bash
# Check for nomic-bitcoin package implementation
rg -A 10 "relayers" node_modules/nomic-bitcoin

# Also check package.json to see the nomic-bitcoin version
cat package.json | grep nomic-bitcoin

Length of output: 153

Comment on lines +49 to +53
: [
"https://btc-relayer.nomic.io",
"https://btc-relay.nomic-main.ccvalidators.com",
"https://nomic-relayer.forbole.com",
];
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add explicit TypeScript return type for better type safety

The function's return type has changed from a single URL to an array of URLs. To prevent potential runtime errors, consider adding explicit type annotations.

-export function getNomicRelayerUrl({ env }: { env: "mainnet" | "testnet" }) {
+export function getNomicRelayerUrl({ env }: { env: "mainnet" | "testnet" }): string[] {
📝 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
: [
"https://btc-relayer.nomic.io",
"https://btc-relay.nomic-main.ccvalidators.com",
"https://nomic-relayer.forbole.com",
];
: [
"https://btc-relayer.nomic.io",
"https://btc-relay.nomic-main.ccvalidators.com",
"https://nomic-relayer.forbole.com",
];

@JoseRFelix JoseRFelix merged commit 50a682e into stage Dec 2, 2024
33 checks passed
@JoseRFelix JoseRFelix deleted the jose/fe-1248-update-nomic-relayers-array branch December 2, 2024 16:22
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.

None yet

2 participants