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

fix(generate): update for chain addition #130

Merged

Conversation

MaxMustermann2
Copy link
Collaborator

@MaxMustermann2 MaxMustermann2 commented Dec 6, 2024

Summary by CodeRabbit

  • New Features

    • Updated Ethereum testnet configuration, including renaming from "Sepolia" to "Holesky" and token metadata adjustments.
    • Enhanced error handling and data integrity checks for genesis file management.
    • Output format for storage layout inspection changed to JSON for improved clarity.
  • Bug Fixes

    • Improved handling of duplicates in token management and validator processing.

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes in this pull request primarily focus on updating the script/generate.mjs file to refine the configuration for the Ethereum testnet. Key modifications include renaming the clientChainInfo from "Sepolia" to "Holesky," updating the layer_zero_chain_id, and adjusting the tokenMetaInfos and tokenNamesForOracle arrays. The updateGenesisFile function has been enhanced with improved error handling and checks to prevent duplicates in the genesis file, ensuring better organization and clarity in the management of tokens and validators. Additionally, the CI workflow has been updated to output storage layout inspections in JSON format.

Changes

File Change Summary
script/generate.mjs - Updated clientChainInfo to change name from "Sepolia" to "Holesky" and layer_zero_chain_id from 40161 to 40217.
- Modified tokenMetaInfos to include "Exocore Holesky ETH" and removed "Exocore testnet ETH".
- Adjusted order of tokens in tokenNamesForOracle.
- Enhanced updateGenesisFile function with new error handling and checks to prevent duplicates.
- Streamlined token management and improved clarity in genesis JSON object processing.
.github/workflows/forge-ci.yml - Updated commands in extract-base-storage-layout-exocore-gateway and extract-storage-layout jobs to include --json flag for JSON output format during storage layout inspection.

Possibly related PRs

  • v4: testnet changes #71: The changes in script/generate.js regarding token management and genesis file updates are related to the modifications in the generate.js file in this PR, which also focuses on enhancing token handling and genesis file structure.
  • feat(generate.js): update for compatibility #91: This PR updates generate.js to ensure compatibility with genesis export changes, which aligns with the main PR's focus on restructuring the updateGenesisFile function and managing token metadata.
  • feat(generate): support native asset #103: The addition of nativeChain and nativeAsset in this PR directly relates to the changes in the main PR where the updateGenesisFile function is modified to include similar structures in the genesis JSON.
  • CI: enhance CI to check storage layout backwards compatibility #112: The enhancements to the CI process for checking storage layout compatibility in this PR are relevant to the main PR's updates, as both involve ensuring the integrity and compatibility of contract structures.
  • feat(ci): carve out storage layout CI #127: This PR's focus on improving the CI process for storage layout checks complements the main PR's changes, which also aim to enhance the robustness of the contract management and deployment processes.

Suggested reviewers

  • cloud8little
  • leonz789
  • adu-web3
  • TimmyExogenous
  • magj2006

🐇 In the land of code, where changes bloom,
A new chain emerges, dispelling the gloom.
Holesky now shines, with tokens anew,
Validators dance, in a structured view.
With checks in place, the genesis sings,
A rabbit rejoices, for the joy that it brings! 🐇


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 or @coderabbitai title 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

github-actions bot commented Dec 6, 2024

✅ The Slither Analysis workflow has completed successfully. Check the workflow run for details. (89db9ee)

Copy link

github-actions bot commented Dec 6, 2024

✅ The Forge CI workflow has completed successfully. Check the workflow run for details. (89db9ee)

Copy link

github-actions bot commented Dec 6, 2024

✅ The Solhint workflow has completed successfully. Check the workflow run for details. (89db9ee)

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

🧹 Outside diff range and nitpick comments (1)
script/generate.mjs (1)

738-746: Refactor Validators and Operators Initialization

Mapping and initializing validators, operators, and associations enhance code readability and maintainability. This refactoring makes the codebase easier to understand and modify in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5eea872 and fb61569.

📒 Files selected for processing (1)
  • script/generate.mjs (13 hunks)
🔇 Additional comments (15)
script/generate.mjs (15)

6-9: Update clientChainInfo for Holesky Testnet

The updates to clientChainInfo correctly reflect the change to the Holesky testnet with the new name, meta_info, and layer_zero_chain_id. Ensure that all references to clientChainInfo in the codebase are updated accordingly.


14-14: Verify Token Metadata Alignment

The tokenMetaInfos array now includes 'Exocore Holesky ETH'. Confirm that the order of tokens in tokenMetaInfos matches the order in tokenNamesForOracle to maintain correct token associations.


23-23: Confirm Oracle Token Names Mapping

The tokenNamesForOracle array has been updated to ['ETH', 'nstETH']. Ensure that these names correctly correspond to the tokens defined in tokenMetaInfos and that they are accurately used in the oracle configurations.


164-166: Add Error Handling for Already Bootstrapped Contract

Throwing an error when the contract is already bootstrapped prevents redundant operations and potential overwriting of critical information.


232-233: Initialize supportedTokens and assetIds

Initializing supportedTokens and assetIds before their use ensures that they are correctly populated and prevents potential undefined errors later in the execution.


254-254: Append Cleaned Token to Supported Tokens

Adding tokenCleaned to supportedTokens ensures that the new token information is included in the genesis file for accurate asset representation.


Line range hint 259-263: Initialize Oracle Token Feeder Correctly

The oracleTokenFeeder object is properly initialized with the correct token_id, start_base_block, and other parameters. Verify that start_base_block is accurately calculated based on height.


291-303: Prevent Duplicates in Oracle Tokens

The code effectively checks for existing token names in oracleTokens to avoid duplicates, appending asset IDs if the token exists or adding a new token if not.


347-355: Update Start Base Block for Oracle Token Feeders

Updating the start_base_block for each oracleTokenFeeder ensures that the feeders commence at the correct block height, improving the reliability of oracle data feeds.


374-374: Initialize Deposits Array

Initializing deposits in genesisJSON.app_state.assets ensures that deposit data can be correctly accumulated without encountering undefined errors.


644-644: Initialize Operator Assets Array

The initialization of operator_assets prepares the array to store operator asset states, facilitating accurate tracking of operator holdings.


749-752: Initialize Operator-Related Arrays

Initializing operator_records, opt_states, avs_usd_values, and operator_usd_values ensures that all necessary data structures are prepared for storing operator information.


806-812: Validate Exchange Rates Against Supported Tokens

The check ensures the number of exchange rates matches the supportedTokensCount. This validation is crucial to prevent calculation errors when converting token amounts to USD values.


931-942: Update AVS USD Values Accurately

Updating avs_usd_values by checking if an existing item exists prevents duplicate entries and ensures that the USD values are aggregated correctly.


1000-1008: Initialize Delegation States and Staker Mapping

Initializing delegation_states and stakers_by_operator, and mapping stakers to operators, enhances data organization for delegation tracking.

script/generate.mjs Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Dec 6, 2024

✅ The Compare Storage Layouts workflow has completed successfully. Check the workflow run for details. (89db9ee)

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 (6)
script/generate.mjs (6)

Line range hint 232-303: Consider modularizing token management logic

The token management logic is complex and handles multiple responsibilities. Consider extracting the token processing logic into separate functions for better maintainability.

Example refactor:

+ function processOracleToken(token, tokenName, height) {
+   return {
+     name: tokenName,
+     chain_id: 1,
+     contract_address: token.tokenAddress,
+     active: true,
+     asset_id: token.tokenAddress.toLowerCase() + clientChainSuffix,
+     decimal: 8,
+   };
+ }

+ function processTokenFeeder(tokenId, height) {
+   return {
+     token_id: tokenId,
+     rule_id: "1",
+     start_round_id: "1",
+     start_base_block: (height + 20).toString(),
+     interval: "30",
+     end_block: "0",
+   };
+ }

Line range hint 644-752: Consider migrating to TypeScript for better type safety

The operator and validator handling logic deals with complex data structures. TypeScript would help catch potential type-related errors early and improve code maintainability.

Example type definitions:

interface OperatorRecord {
  operator_address: string;
  chains: {
    chain_id: string;
    consensus_key: string;
  }[];
}

interface ValidatorState {
  public_key: string;
  power: Decimal;
}

806-812: Improve error message clarity

The error message for exchange rates validation could be more descriptive.

- throw new Error(
-   `The number of exchange rates (${exchangeRates.length}) 
-   does not match the number of supported tokens (${supportedTokensCount}).`
- );
+ throw new Error(
+   `Exchange rates count mismatch: expected ${supportedTokensCount} rates for supported tokens, ` +
+   `but received ${exchangeRates.length} rates. Please ensure all token rates are provided.`
+ );

931-942: Add documentation for AVS USD value calculation

The AVS USD value update logic would benefit from comments explaining the business rules and calculation methodology.

+ // Update or create AVS USD value entry
+ // If an entry exists for the AVS address, add the new USD value to the existing amount
+ // Otherwise, create a new entry with the calculated USD value

1000-1001: Use more descriptive variable names

Consider using more descriptive names for better code readability.

- const delegation_states = genesisJSON.app_state.delegation.delegation_states;
- const stakers_by_operator = genesisJSON.app_state.delegation.stakers_by_operator;
+ const delegatorStates = genesisJSON.app_state.delegation.delegation_states;
+ const stakersGroupedByOperator = genesisJSON.app_state.delegation.stakers_by_operator;

1101-1116: Extract native chain handling into a separate function

Consider extracting the native chain handling logic into a dedicated function for better code organization.

+ function addNativeChainIfNotExists(genesisJSON, nativeChain, nativeAsset) {
+   const nativeChainExists = genesisJSON.app_state.assets.client_chains.some(
+     chain => chain.layer_zero_chain_id === nativeChain.layer_zero_chain_id
+   );
+   
+   if (!nativeChainExists) {
+     genesisJSON.app_state.assets.client_chains.push(nativeChain);
+     genesisJSON.app_state.assets.tokens.push(nativeAsset);
+     genesisJSON.app_state.dogfood.params.asset_ids.push(
+       nativeAsset.asset_basic_info.address.toLowerCase() + '_0x' +
+       nativeAsset.asset_basic_info.layer_zero_chain_id.toString(16)
+     );
+   }
+   return genesisJSON;
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fb61569 and 4144123.

📒 Files selected for processing (1)
  • script/generate.mjs (13 hunks)
🔇 Additional comments (2)
script/generate.mjs (2)

6-23: LGTM: Configuration updates for Holesky testnet

The changes correctly update the testnet configuration from Sepolia to Holesky, including the appropriate layer_zero_chain_id and token configurations.


164-164: LGTM: Improved error handling for bootstrap state

Clear error message when attempting to modify an already bootstrapped contract.

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)
.github/workflows/forge-ci.yml (1)

177-177: LGTM! Consider adding JSON validation step.

The addition of the --json flag is consistent with the previous change and improves the output format for all contracts.

Consider adding a validation step after generating the JSON files to ensure they are well-formed. Here's a suggested addition after the current line:

 forge inspect --json src/core/${{ matrix.contract }}.sol:${{ matrix.contract }} storage-layout > ${{ matrix.contract }}.compiled.json;
+jq empty ${{ matrix.contract }}.compiled.json || (echo "Invalid JSON generated for ${{ matrix.contract }}" && exit 1)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4144123 and 89db9ee.

📒 Files selected for processing (1)
  • .github/workflows/forge-ci.yml (2 hunks)
🔇 Additional comments (1)
.github/workflows/forge-ci.yml (1)

141-141: LGTM! Verify JSON output format.

The addition of the --json flag improves machine readability of the storage layout output.

@MaxMustermann2 MaxMustermann2 added this pull request to the merge queue Dec 10, 2024
Merged via the queue into ExocoreNetwork:main with commit 389fc09 Dec 10, 2024
15 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