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(generate.js): update for compatibility #91

Conversation

TimmyExogenous
Copy link
Contributor

@TimmyExogenous TimmyExogenous commented Sep 3, 2024

description

This PR updates the generate.js to be compatible with the PR regarding genesis export. Please take a look at the related PR for more details.
genesis exporting PR

This PR hasn't been tested so it might have some issues.

Summary by CodeRabbit

  • New Features

    • Enhanced functionality for managing and processing blockchain-related data.
    • Introduced address generation and key joining capabilities.
    • Improved handling of operator assets and their states.
    • Dynamic association of vaults with whitelisted tokens in the contract.
    • Added support for accurately processing large integers in JSON data.
    • Updated environment variable for clarity regarding its usage.
  • Bug Fixes

    • Refined logic for calculating withdrawable amounts to improve accuracy.
  • Documentation

    • Updated data structures and output representation in the genesis file for better clarity.

Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Walkthrough

The changes introduce a new dependency, json-bigint, to handle large integers in JSON data. The script/generate.js file has been significantly enhanced with new functions for address generation and composite key creation. The logic for updating the genesis file has been expanded to include more detailed handling of token deposits and validator assets, improving the structure and clarity of the data representation. Additionally, the DeployContracts contract has been modified to use an interface type for vaults, enhancing flexibility.

Changes

Files Change Summary
package.json Added json-bigint dependency with version ^1.0.0.
script/generate.js Added generateAVSAddr and getJoinedStoreKey functions; expanded logic for updating the genesis file with operator assets; introduced new data structures (operator_records, opt_states, avs_usd_values); refined deposit calculation with dynamic withdrawableValue; improved delegation state handling.
script/integration/1_DeployBootstrap.s.sol Changed vaults from type Vault[] to IVault[] in the DeployContracts contract; added dynamic population of vaults based on whitelistTokens.
.env.example Renamed environment variable SEPOLIA_RPC to CLIENT_CHAIN_RPC; updated comments for clarity.
script/8_RegisterValidatorsAndDelegate.s.sol Updated clientChainRPCURL variable to reference CLIENT_CHAIN_RPC instead of SEPOLIA_RPC.
script/TokenTransfer.s.sol Updated clientChainRPCURL variable to reference CLIENT_CHAIN_RPC instead of SEPOLIA_RPC.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant Blockchain

    User->>Script: Request to generate genesis file
    Script->>Script: Retrieve validator addresses and assets
    Script->>Script: Calculate withdrawable amounts
    Script->>Blockchain: Update genesis file with structured data
    Blockchain-->>Script: Confirmation of update
    Script-->>User: Provide updated genesis file
Loading

🐰 "In the garden where data flows,
New functions sprout, as logic grows.
With addresses bright and keys that join,
The genesis shines, our work we coin!
Hooray for changes, let’s hop and cheer,
For blockchain magic, we hold so dear!" 🌼

Possibly related PRs

  • feat: register whitelist tokens to Exocore from client chain contract #23: This PR involves the registration of whitelist tokens to Exocore, which is directly related to the changes in the main PR that enhance the handling of tokens and their associated functionalities.
  • refactor: add natspec documentation #58: This PR includes changes to the .env.example file, specifically renaming the SEPOLIA_RPC variable to CLIENT_CHAIN_RPC, which aligns with the main PR's update to the same environment variable.
  • v4: testnet changes #71: This PR updates the generate.js script to improve token management and includes changes to the genesis file structure, which relates to the main PR's enhancements in handling blockchain-related data structures.

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.

@TimmyExogenous TimmyExogenous changed the title feat(generate.js): update generate.js to be compatiable with the #PR108 feat(generate.js): update generate.js to be compatiable with genesis export Sep 3, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 021ea9d and af95196.

Files selected for processing (1)
  • script/generate.js (12 hunks)
Additional comments not posted (10)
script/generate.js (10)

49-50: LGTM!

The code changes are approved.


51-56: LGTM!

The code changes are approved.


58-61: LGTM!

The code changes are approved.


177-179: LGTM!

The code changes are approved.


233-235: LGTM!

The code changes are approved.


278-339: LGTM!

The code changes are approved.


363-370: LGTM!

The code changes are approved.


Line range hint 382-484: LGTM!

The code changes are approved.


497-546: LGTM!

The code changes are approved.


Line range hint 593-663: LGTM!

The code changes are approved.

@MaxMustermann2 MaxMustermann2 changed the title feat(generate.js): update generate.js to be compatiable with genesis export feat(generate.js): update for compabitility Sep 4, 2024
@TimmyExogenous TimmyExogenous force-pushed the compatible-with-genesis-exporting branch from 9f5993a to 996fd30 Compare September 19, 2024 01:38
@MaxMustermann2 MaxMustermann2 changed the title feat(generate.js): update for compabitility feat(generate.js): update for compatibility Sep 20, 2024
Previously, we had used the `SEPOLIA_RPC` variable, which is now changed
to `CLIENT_CHAIN_RPC`.
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

Files that changed from the base of the PR and between 996fd30 and 65752f7.

Files selected for processing (2)
  • .env.example (2 hunks)
  • script/integration/1_DeployBootstrap.s.sol (2 hunks)
Additional comments not posted (3)
.env.example (1)

20-20: LGTM!

The comment update accurately reflects the inclusion of CLIENT_CHAIN_RPC among the variables used by generate.js, enhancing code clarity and maintainability.

script/integration/1_DeployBootstrap.s.sol (2)

51-51: LGTM!

The change from Vault[] to IVault[] for the vaults array is a good design decision. It allows the contract to interact with any implementation of the IVault interface, promoting flexibility and loose coupling.


148-152: LGTM!

The new loop that populates the vaults array based on the whitelistTokens is a great addition. It improves the contract's operational capabilities by automatically associating vaults with whitelisted tokens, reducing manual effort and ensuring synchronization between the vaults and whitelistTokens arrays.

.env.example Show resolved Hide resolved
- Use `opAddressHex` and `opAddressExo` so that they fit in the same font
  width when using monospace.
- Calculate total deposit amount first before setting token information
Copy link
Collaborator

@MaxMustermann2 MaxMustermann2 left a comment

Choose a reason for hiding this comment

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

Tested on localnet and generated the genesis.json from the integration test. Ran a network of 3 operators, and all good.

Made some minor changes in the last 4 commits.

Copy link

@trestinlsd trestinlsd left a comment

Choose a reason for hiding this comment

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

looks good

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

Outside diff range and nitpick comments (2)
script/generate.js (2)

Line range hint 574-574: Convert validators to the top N validators

The validators.slice method returns a new array but does not modify validators. To limit the validators array, assign the result back to validators.

Apply this diff:

- validators.slice(0, genesisJSON.app_state.dogfood.params.max_validators);
+ validators = validators.slice(0, genesisJSON.app_state.dogfood.params.max_validators);

Line range hint 588-642: Optimize nested loops for efficiency

The nested loops over depositors, tokens, and operators can lead to performance issues, especially with large datasets. Consider refactoring to reduce complexity.

  • Fetch all required data beforehand and use maps to reduce the number of iterations.
  • Parallelize asynchronous calls where appropriate.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d10eca2 and 3ab61d1.

Files selected for processing (1)
  • script/generate.js (11 hunks)
Additional comments not posted (3)
script/generate.js (3)

560-560: Assign the result of validators.slice to limit the array size

The slice method returns a new array and does not modify the original array in place. To limit the validators array to the top N validators, you need to assign the result back to validators.

Apply this diff to fix the problem:

- validators.slice(0, genesisJSON.app_state.dogfood.params.max_validators);
+ validators = validators.slice(0, genesisJSON.app_state.dogfood.params.max_validators);

Likely invalid or redundant comment.


586-587: Ensure totalPower calculation is accurate

After truncating val.power using toFixed(0), val.power becomes a string. When adding to totalPower, ensure you're converting it back to a number.

Modify the addition to correctly parse the integer value:

- totalPower += parseInt(val.power, 10);
+ totalPower += Number(val.power);

Likely invalid or redundant comment.


373-393: Validate existence of operator information

Ensure that the operatorInfo retrieved from the contract contains all necessary fields before using them. Missing or undefined properties can lead to runtime errors.

Run the following script to check for missing operatorInfo fields:

script/generate.js Show resolved Hide resolved
script/generate.js Show resolved Hide resolved
Copy link
Collaborator

@bwhour bwhour left a comment

Choose a reason for hiding this comment

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

looks good.

@TimmyExogenous TimmyExogenous added this pull request to the merge queue Sep 24, 2024
Merged via the queue into ExocoreNetwork:main with commit 8b56d67 Sep 24, 2024
7 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.

5 participants