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

feat: add signet and testnet4 addresses #435

Merged
merged 4 commits into from
Dec 11, 2024
Merged

feat: add signet and testnet4 addresses #435

merged 4 commits into from
Dec 11, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Dec 3, 2024

The generator wasn't working so I added these by hand. The generator code also needs to be updated to correctly handle these new networks.

Related to zeta-chain/node#2242

Summary by CodeRabbit

  • New Features

    • Added support for two new omnichain entries: btc_signet and btc_testnet4.
  • Improvements

    • Enhanced data handling for address management to prevent duplicate entries in the address list.
  • Type Updates

    • Updated chain name definitions to include new values and remove obsolete ones.
  • Workflows

    • Removed obsolete GitHub Actions workflows for generated files and testing.

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces two new entries to the v1/tasks/addresses.testnet.json file under the "omnichain" category, both sharing the same address but differing in chain_id and chain_name. Additionally, it updates the ParamChainName type in v2/lib/types.ts by removing the "empty" value and adding "btc_signet_testnet" and "btc_testnet4". The fetchTssData function in v2/tasks/addresses.ts is modified to change the property name from chain_name to name, and logic for adding WETH addresses is refined to prevent duplicates.

Changes

File Change Summary
v1/tasks/addresses.testnet.json Added two new entries for the address tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur under "omnichain" with different chain_id and chain_name.
`v2/lib/types.ts Updated ParamChainName type: removed "empty" and added "btc_signet_testnet" and "btc_testnet4".
`v2/tasks/addresses.ts Modified fetchTssData to change chain_name to name and updated logic in fetchFactoryV3 to prevent duplicate WETH addresses.

Possibly related PRs

  • fix: build workflow and generate addresses #203: This PR adds new entries to a JSON file for various addresses, including entries categorized under "omnichain," which is directly related to the new entries added in the main PR for the same category.
  • feat: contract addresses #348: This PR introduces a new JSON file for testnet addresses, which includes entries for "omnichain" addresses, similar to the changes made in the main PR.
  • chore: gateway addresses #414: This PR adds new entries to the addresses.testnet.json file for "omnichain" addresses, which aligns with the new entries added in the main PR.
  • chore: add ZetaChain Gateway address #421: This PR adds a new entry to the addresses.testnet.json file for an "omnichain" address, which is directly related to the changes made in the main PR.

Suggested labels

to-backport

Suggested reviewers

  • skosito
  • CharlieMc0
  • brewmaster012
  • fbac
  • lumtis

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cdc1b46 and 6c6f171.

📒 Files selected for processing (2)
  • .github/workflows/generated-files_v1.yaml (0 hunks)
  • .github/workflows/test_v1.yaml (0 hunks)
💤 Files with no reviewable changes (2)
  • .github/workflows/test_v1.yaml
  • .github/workflows/generated-files_v1.yaml

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

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.

@gartnera gartnera changed the title Add signet and testnet4 addresses feat: add signet and testnet4 addresses Dec 3, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.37%. Comparing base (5368eb8) to head (6c6f171).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #435      +/-   ##
==========================================
+ Coverage   84.06%   86.37%   +2.31%     
==========================================
  Files           8        8              
  Lines         389      499     +110     
  Branches      124      124              
==========================================
+ Hits          327      431     +104     
- Misses         62       68       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fadeev
Copy link
Member

fadeev commented Dec 4, 2024

@gartnera ZRC-20 addresses are fetched automatically from https://zetachain-athens.blockpi.network/lcd/v1/public/zeta-chain/fungible/foreign_coins.

Can you, please, move:

  {
    "address": "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur",
    "category": "omnichain",
    "chain_id": 18333,
    "chain_name": "btc_signet",
    "type": "tss"
  },
  {
    "address": "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur",
    "category": "omnichain",
    "chain_id": 18334,
    "chain_name": "btc_testnet4",
    "type": "tss"
  },

To addresses.testnet.json so they're not overwritten when the script runs again.

@gartnera
Copy link
Member Author

gartnera commented Dec 4, 2024

@gartnera ZRC-20 addresses are fetched automatically from https://zetachain-athens.blockpi.network/lcd/v1/public/zeta-chain/fungible/foreign_coins.

So I/we can remove all the zrc20 entries?

Can you, please, move:

  {
    "address": "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur",
    "category": "omnichain",
    "chain_id": 18333,
    "chain_name": "btc_signet",
    "type": "tss"
  },
  {
    "address": "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur",
    "category": "omnichain",
    "chain_id": 18334,
    "chain_name": "btc_testnet4",
    "type": "tss"
  },

To addresses.testnet.json so they're not overwritten when the script runs again.

I already have entries in the addresses.testnet.json file?

@fadeev
Copy link
Member

fadeev commented Dec 4, 2024

@gartnera not exactly.

This script: https://github.com/zeta-chain/protocol-contracts/blob/main/v2/tasks/addresses.ts

And this file (containing addresses we can't fetch automatically): https://github.com/zeta-chain/protocol-contracts/blob/main/v2/tasks/addresses.testnet.json (note it's in the tasks dir) ❗️ I propose we add Bitcoin TSS addresses to this file and not the auto-generated file.

Results in this auto-generated file: https://github.com/zeta-chain/protocol-contracts/blob/main/v2/data/addresses.testnet.json (note it's in the data dir)

@fadeev
Copy link
Member

fadeev commented Dec 4, 2024

I know this system is crap (auto-generation breaking all the time), but the one we had before (manually maintained file, wrong addresses everywhere) was even worse.

Let's do it right this time! 😃

https://www.notion.so/zetachain/Contract-Address-Registry-1517b3fb9049800e9eb4e292ca9867f0?pvs=4

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 (1)
v1/tasks/addresses.testnet.json (1)

44-56: Consider adding documentation for manual entries

Since these addresses are being manually maintained (as discussed in the PR comments), consider adding a comment in the JSON to indicate this is intentional and to prevent future automated scripts from removing these entries.

Add a comment before these entries:

   },
+  // Manual entries for Bitcoin networks - DO NOT REMOVE
+  // These addresses are intentionally maintained here instead of being auto-generated
   {
     "address": "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur",
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5368eb8 and 399f3b1.

⛔ Files ignored due to path filters (2)
  • v1/data/addresses.testnet.json is excluded by !v1/data/**
  • v2/data/addresses.testnet.json is excluded by !v2/data/**
📒 Files selected for processing (1)
  • v1/tasks/addresses.testnet.json (1 hunks)
🔇 Additional comments (2)
v1/tasks/addresses.testnet.json (2)

44-56: LGTM on JSON structure and format

The new entries maintain consistent formatting with the existing entries and include all required fields (address, category, chain_id, chain_name, type).


45-49: Verify the safety of using identical addresses across different Bitcoin networks

The same Bitcoin address tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur is being used for both signet and testnet4 networks. While technically possible, this practice could potentially lead to operational confusion or security risks.

Let's verify the Bitcoin address format and network compatibility:

Also applies to: 52-56

✅ Verification successful

Let me gather more context about the usage patterns of this address across different networks.


Using the same Bitcoin address across test networks is an established pattern

The address reuse across Bitcoin test networks (testnet, signet, testnet4) appears to be an intentional and established pattern in the codebase. This is evidenced by:

  • The same pattern exists in both v1 and v2 configurations
  • The address is consistently used as a TSS (Threshold Signature Scheme) endpoint
  • All instances are properly categorized as "omnichain" and "type: tss"
  • The address format is valid for Bitcoin testnet networks (validated by regex)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Bitcoin address format and search for any existing usage
# Expected results: Address should be a valid testnet/signet format (tb1 prefix)
#                  and we should find any other instances where this address is used

# Check if the address follows Bitcoin testnet bech32 format
echo "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur" | grep -E "^tb1[a-zA-HJ-NP-Z0-9]{39,59}$" || echo "Invalid testnet address format"

# Search for any other instances of this address in the codebase
rg "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur"

Length of output: 1094


Script:

#!/bin/bash
# Let's examine the complete entries in both v1 and v2 files to understand the network contexts
# where this address is being used

echo "=== v1/tasks/addresses.testnet.json ==="
cat v1/tasks/addresses.testnet.json

echo -e "\n=== v2/data/addresses.testnet.json ==="
cat v2/data/addresses.testnet.json

echo -e "\n=== v1/data/addresses.json ==="
cat v1/data/addresses.json

echo -e "\n=== v1/data/addresses.testnet.json ==="
cat v1/data/addresses.testnet.json

Length of output: 30664

@gartnera
Copy link
Member Author

gartnera commented Dec 5, 2024

Ok @fadeev I think I know what you're saying. I've updated the PR.

If this still isn't correct maybe you could fix it up?

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 (1)
v2/tasks/addresses.testnet.json (1)

77-77: New tss type introduced

The entries introduce a new type: "tss" which differs from the existing gateway and custody types. This appears intentional for Bitcoin networks, but please ensure:

  1. The type is documented in the relevant specifications
  2. Any dependent systems are updated to handle this new type

Also applies to: 84-84

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 399f3b1 and 8db4a3d.

⛔ Files ignored due to path filters (2)
  • v1/data/addresses.testnet.json is excluded by !v1/data/**
  • v2/data/addresses.testnet.json is excluded by !v2/data/**
📒 Files selected for processing (2)
  • v1/tasks/addresses.testnet.json (1 hunks)
  • v2/tasks/addresses.testnet.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • v1/tasks/addresses.testnet.json
🔇 Additional comments (3)
v2/tasks/addresses.testnet.json (3)

71-84: LGTM: JSON structure and formatting

The new entries maintain consistent structure and formatting with existing entries. The JSON is valid and properly formatted.


73-73: Verify Bitcoin address format and ownership

The Bitcoin testnet address format is valid (native SegWit with 'tb1' prefix). However, since this is a critical TSS address, please ensure:

  1. The address was generated using the correct network parameters
  2. The TSS key shares are properly distributed and backed up

Also applies to: 80-80

✅ Verification successful

Bitcoin testnet address is already in use across multiple configurations

The address tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur is already being used in both v1 and v2 configurations across multiple files:

  • v1/tasks/addresses.testnet.json
  • v1/data/addresses.testnet.json
  • v1/data/addresses.json
  • v2/tasks/addresses.testnet.json
  • v2/data/addresses.testnet.json

This confirms that:

  1. The address is a known and validated TSS address
  2. The key shares are already distributed and in use
  3. The address is being consistently used across different network configurations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if this address is already in use in testnet
# Note: This helps prevent address collisions and confirms ownership

# Search for any existing references to this address
rg "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur" --type json

Length of output: 1157


75-76: Verify chain IDs and network configurations

The chain IDs (18333 for signet, 18334 for testnet4) match Bitcoin's standard testnet identifiers. Please ensure:

  1. These chain IDs are consistently used across the entire protocol
  2. Network-specific configurations are properly set for each chain

Also applies to: 82-83

✅ Verification successful

Chain IDs and network configurations are consistent across the codebase

The verification shows that the chain IDs (18333 for btc_signet and 18334 for btc_testnet4) are consistently used across both v1 and v2 versions in the following files:

  • v1/data/addresses.testnet.json
  • v1/tasks/addresses.testnet.json
  • v2/data/addresses.testnet.json
  • v2/tasks/addresses.testnet.json

Additionally, there's a proper cross-chain reference in v2/data/addresses.testnet.json where "foreign_chain_id": "18333" is used to link with the Bitcoin signet network.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify chain ID consistency across the codebase

# Search for any existing references to these chain IDs
echo "Checking signet chain ID..."
rg "18333|btc_signet" --type json -A 5 -B 5

echo "Checking testnet4 chain ID..."
rg "18334|btc_testnet4" --type json -A 5 -B 5

Length of output: 7182

@fadeev
Copy link
Member

fadeev commented Dec 5, 2024

Removed testnet 4 and signet addresses from the manual JSON file, because they're fetched automatically. Updated the script to take chain names from name rather than chain_name from supported chains. For some reason chain_name is "ampty" for BTC testnets.

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)
v2/tasks/addresses.ts (3)

Line range hint 32-73: Consider adding error handling for new Bitcoin networks.

The fetchTssData function should handle potential errors specific to signet and testnet4 networks.

Consider adding network-specific error handling:

 const fetchTssData = async (chains: any, addresses: any, network: Network) => {
   const bitcoinChainID = network === "zeta_mainnet" ? "8332" : "18332";
+  // Map network-specific chain IDs
+  const bitcoinChainIDs = {
+    btc_testnet: "18332",
+    btc_signet_testnet: "18333",
+    btc_testnet4: "18334"
+  };
   const URL = `${api[network].rpc}/zeta-chain/observer/get_tss_address/${bitcoinChainID}`;
   try {
     const tssResponse: AxiosResponse<any> = await axios.get(URL);
     if (tssResponse.status === 200) {
       chains.forEach((chain: any) => {
         const { btc, eth } = tssResponse.data;
         const isEVM = chain.consensus === "ethereum";
         const isBitcoin = chain.consensus === "bitcoin";
+        // Validate Bitcoin network type
+        if (isBitcoin && !bitcoinChainIDs[chain.name]) {
+          console.warn(`Unsupported Bitcoin network: ${chain.name}`);
+          return;
+        }
         if (isEVM || isBitcoin) {
           addresses.push({
             address: isBitcoin ? btc : eth,

Line range hint 1-273: Consider improving address generation architecture.

Given the issues with the generator mentioned in the PR objectives, consider these architectural improvements:

  1. Add type safety for chain name fields
  2. Implement a unified chain name handling strategy
  3. Add validation for supported networks

Would you like help designing a more robust address generation system that better handles different Bitcoin networks?


Use chain.chain_name instead of chain.name for consistency

The codebase consistently uses chain.chain_name across both v1 and v2 versions, with only one instance using chain.name in the modified code. Update the property access to maintain consistency:

- chain_name: chain.name,
+ chain_name: chain.chain_name,
🔗 Analysis chain

Line range hint 32-73: Ensure consistency with other functions using chain data.

The change to use chain.name in fetchTssData should be consistent across all functions handling chain information.

Let's check for consistency:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of chain_name vs name in chain handling
echo "Files using chain_name:"
rg "chain\.chain_name" --type ts
echo -e "\nFiles using chain.name:"
rg "chain\.name" --type ts

Length of output: 1483

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8db4a3d and cdc1b46.

⛔ Files ignored due to path filters (1)
  • v2/data/addresses.testnet.json is excluded by !v2/data/**
📒 Files selected for processing (2)
  • v2/lib/types.ts (1 hunks)
  • v2/tasks/addresses.ts (1 hunks)
🔇 Additional comments (2)
v2/lib/types.ts (1)

2-2: LGTM! Type changes align with new Bitcoin networks.

The addition of "btc_signet_testnet" and "btc_testnet4" to ParamChainName is appropriate. Removal of "empty" improves type accuracy.

Let's verify that removing "empty" doesn't break existing code:

✅ Verification successful

Removal of "empty" from ParamChainName is safe

The search results confirm that:

  1. There are no usages of "empty" as a chain name in the TypeScript codebase
  2. The ParamChainName type is consistently used across v1 and v2 directories
  3. The only places using ParamChainName are type declarations and the getAddress function, none of which reference an "empty" chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of the removed "empty" chain name
rg -l '"empty"' --type ts

Length of output: 27


Script:

#!/bin/bash
# Let's try a more comprehensive search for "empty" in TypeScript files
# This will show the actual content and context where "empty" appears
rg "empty" --type ts -B 2 -A 2

# Also search for any type declarations or assignments using ParamChainName
rg "ParamChainName.*=|:.*ParamChainName" --type ts -B 2 -A 2

Length of output: 3763

v2/tasks/addresses.ts (1)

68-68: Verify API response structure for chain name field.

The change from chain.chain_name to chain.name suggests a change in API response structure. This could affect how Bitcoin signet and testnet4 addresses are mapped.

Let's verify the API response structure:

✅ Verification successful

Let me gather more information about how the chain fields are used across the codebase.


API response structure change is correct and consistent

The change from chain.chain_name to chain.name in fetchTssData is correct as both fields exist in the API response. The codebase shows a clear pattern:

  • chain.name is used for TSS addresses in v2
  • chain.chain_name is used for other contract addresses (zetaToken, connector, erc20Custody)

This split usage is intentional as TSS addresses follow a different mapping structure compared to other contract addresses.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch and examine the API response structure for chain fields
curl -s "https://zetachain-athens.blockpi.network/lcd/v1/public/zeta-chain/observer/supportedChains" | jq '.' > chain_response.json
echo "Chain fields in response:"
jq '.chains[0] | keys' chain_response.json

Length of output: 345


Script:

#!/bin/bash
# Search for usages of chain.name and chain.chain_name
echo "=== Searching for chain.name usage ==="
rg "chain\.name" -A 2

echo -e "\n=== Searching for chain.chain_name usage ==="
rg "chain\.chain_name" -A 2

echo -e "\n=== Checking the full context of addresses.ts ==="
cat v2/tasks/addresses.ts

Length of output: 14436

@fadeev
Copy link
Member

fadeev commented Dec 5, 2024

CI is failing because RPC endpoints are blocking requests.

@lumtis
Copy link
Member

lumtis commented Dec 9, 2024

CI is failing because RPC endpoints are blocking requests.

This is for v1 it doesn't matter anymore isn't it? @fadeev

@fadeev
Copy link
Member

fadeev commented Dec 10, 2024

CI is failing because RPC endpoints are blocking requests.

This is for v1 it doesn't matter anymore isn't it? @fadeev

🤦‍♂️ I didn't notice it's only failing for v1. Yes, we can merge, and then disable generated CI for v1.

@fadeev
Copy link
Member

fadeev commented Dec 10, 2024

In fact, shall I disable both generated and test for v1, so we have clean CI before merging?

@lumtis
Copy link
Member

lumtis commented Dec 10, 2024

In fact, shall I disable both generated and test for v1, so we have clean CI before merging?

Yes

@fadeev fadeev requested review from a team as code owners December 10, 2024 09:38
@fadeev fadeev merged commit 81dbeb9 into main Dec 11, 2024
12 checks passed
@fadeev fadeev deleted the signet-testnet4 branch December 11, 2024 07:59
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.

5 participants