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: support multiple btc chain config #2870

Merged
merged 9 commits into from
Sep 18, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Sep 12, 2024

Description

  • Allow multiple Bitcoin chain config in zetaclient config file.
  • Create multiple Bitcoin observer/signer pairs when configured.

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for stateful precompiled contracts, enhancing smart contract functionality.
    • Introduced a common importable zetacored rpc package for easier integration.
    • Implemented a staking precompiled contract to improve staking mechanisms.
    • Added support for restricted addresses in the Solana network for enhanced security.
    • Emission of events from the staking precompile for better transparency.
    • Expanded support for multiple Bitcoin chains, increasing compatibility.
  • Bug Fixes

    • Improved error handling for Bitcoin chain configurations.
  • Tests

    • Enhanced test coverage for GetEVMConfig and GetBTCConfig methods, ensuring robustness against edge cases.

Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The recent updates to the Zeta Chain node introduce significant enhancements, including support for stateful precompiled contracts, a common importable zetacored rpc package, and a staking precompiled contract. Additionally, the changes improve security by supporting restricted addresses in the Solana network and enhance transparency with event emissions from staking activities. The configuration management for Bitcoin chains has been restructured to allow multiple configurations, improving flexibility and usability across various blockchain networks.

Changes

File Path Change Summary
changelog.md Added support for stateful precompiled contracts, zetacored rpc package, staking precompiled contract, restricted addresses in Solana, event emissions from staking, and multiple Bitcoin chains in zetaclient.
cmd/zetaclientd/debug.go Updated Bitcoin chain configuration handling, changing checks from IsUTXO() to IsBitcoin() and enhancing error handling.
cmd/zetaclientd/start.go Modified filtering criteria for Bitcoin chains from IsUTXO to IsBitcoin.
cmd/zetaclientd/start_utils.go Simplified masking of sensitive configuration data, removing URL parsing for EVM endpoints.
zetaclient/config/config_chain.go Restructured configuration management for Bitcoin and EVM chains, replacing BitcoinConfig with BTCChainConfigs map.
zetaclient/config/types.go Introduced a new structure for managing Bitcoin configurations, allowing multiple configurations indexed by chain IDs.
zetaclient/config/types_test.go Added tests for GetEVMConfig and GetBTCConfig methods, enhancing test coverage.
zetaclient/context/app_test.go Updated Bitcoin RPC username in tests and modified assertions to reflect new configuration structure.
zetaclient/context/chain.go Renamed method IsUTXO to IsBitcoin for clarity.
zetaclient/orchestrator/bootstrap.go Renamed Bitcoin configuration handling and log messages to clarify intent.
zetaclient/orchestrator/orchestrator.go Changed control flow in runScheduler to explicitly check for Bitcoin chains.

Possibly related PRs

Suggested labels

chain:solana, SOLANA_TESTS


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 generate interesting stats about this repository and render them as a table.
    -- @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.

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

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 81.25000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 67.14%. Comparing base (3bf36b9) to head (71f2f99).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/orchestrator/bootstrap.go 57.14% 3 Missing ⚠️
zetaclient/config/types.go 88.23% 1 Missing and 1 partial ⚠️
zetaclient/orchestrator/orchestrator.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2870      +/-   ##
===========================================
+ Coverage    66.86%   67.14%   +0.28%     
===========================================
  Files          378      378              
  Lines        21108    21121      +13     
===========================================
+ Hits         14113    14182      +69     
+ Misses        6330     6273      -57     
- Partials       665      666       +1     
Files with missing lines Coverage Δ
pkg/chains/chains.go 93.68% <ø> (ø)
zetaclient/config/config_chain.go 100.00% <100.00%> (+88.00%) ⬆️
zetaclient/context/chain.go 76.82% <100.00%> (ø)
zetaclient/orchestrator/orchestrator.go 22.04% <0.00%> (ø)
zetaclient/config/types.go 50.94% <88.23%> (+39.31%) ⬆️
zetaclient/orchestrator/bootstrap.go 58.95% <57.14%> (ø)

@gartnera gartnera added the UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light label Sep 13, 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: 3

Outside diff range and nitpick comments (2)
cmd/zetaclientd/start.go (1)

233-233: LGTM!

The change in filtering criteria from IsUTXO to IsBitcoin is appropriate as it aligns with the current support for only the Bitcoin chain.

Consider adding a TODO comment to track the future support for multiple UTXO chains:

+	// TODO: Support multiple UTXO chains in the future.
	btcChains := appContext.FilterChains(zctx.Chain.IsBitcoin)
changelog.md (1)

54-54: Add the pull request number for consistency.

To maintain consistency with other changelog entries, please add the pull request number in the format [PR_NUMBER] at the beginning of the line.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 75a4189 and 31eaed1.

Files selected for processing (14)
  • changelog.md (1 hunks)
  • cmd/zetaclientd/debug.go (1 hunks)
  • cmd/zetaclientd/start.go (1 hunks)
  • cmd/zetaclientd/start_utils.go (1 hunks)
  • zetaclient/config/config_chain.go (3 hunks)
  • zetaclient/config/types.go (4 hunks)
  • zetaclient/config/types_test.go (2 hunks)
  • zetaclient/context/app_test.go (3 hunks)
  • zetaclient/context/chain.go (1 hunks)
  • zetaclient/context/chain_test.go (1 hunks)
  • zetaclient/orchestrator/bootstap_test.go (2 hunks)
  • zetaclient/orchestrator/bootstrap.go (2 hunks)
  • zetaclient/orchestrator/orchestrator.go (1 hunks)
  • zetaclient/orchestrator/orchestrator_test.go (1 hunks)
Additional context used
Path-based instructions (13)
zetaclient/config/config_chain.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetaclientd/start_utils.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/context/chain_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/config/types_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/context/chain.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetaclientd/debug.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/config/types.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/context/app_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/orchestrator/bootstrap.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/orchestrator/bootstap_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetaclientd/start.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/orchestrator/orchestrator_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/orchestrator/orchestrator.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

GitHub Check: codecov/patch
zetaclient/orchestrator/bootstrap.go

[warning] 142-142: zetaclient/orchestrator/bootstrap.go#L142
Added line #L142 was not covered by tests


[warning] 148-148: zetaclient/orchestrator/bootstrap.go#L148
Added line #L148 was not covered by tests


[warning] 326-326: zetaclient/orchestrator/bootstrap.go#L326
Added line #L326 was not covered by tests

zetaclient/orchestrator/orchestrator.go

[warning] 413-413: zetaclient/orchestrator/orchestrator.go#L413
Added line #L413 was not covered by tests

Additional comments not posted (30)
zetaclient/config/config_chain.go (4)

17-17: LGTM!

The initialization of the BTCChainConfigs field as an empty map in the New function is correct and consistent with the EVMChainConfigs field.


24-25: LGTM!

The population of the BTCChainConfigs field with default values using the btcChainsConfigs function when setDefaults is true is correct and consistent with the EVMChainConfigs field.

The order of populating the fields is not a concern as long as all the required fields are populated before the Config object is returned.


34-34: LGTM!

The change in the RPCUsername field from "smoketest" to "e2etest" does not affect the functionality of the code and is likely due to a change in the naming convention or the purpose of the configuration.


80-86: LGTM!

The btcChainsConfigs function is consistent with the evmChainsConfigs function in terms of structure and purpose. It returns a map with a single entry for the BitcoinRegtest chain using the bitcoinConfigRegnet function, which is sufficient for the current use case.

The function can be easily extended to include more entries for other Bitcoin chains if needed in the future.

cmd/zetaclientd/start_utils.go (4)

55-59: LGTM!

The updated function comment accurately describes the purpose of the maskCfg function and the specific fields that are currently being masked. The changes provide clarity and improve the documentation of the function.


62-67: Excellent simplification!

The updated code for masking EVM endpoints is more straightforward and efficient. By directly setting the endpoint to an empty string, the need for URL parsing and associated error handling is eliminated. This simplifies the code and improves its clarity.


71-77: Streamlined Bitcoin configuration masking!

The updated code for masking Bitcoin endpoints and credentials is more concise and aligned with the overall masking approach. By only assigning the RPCParams from the original configuration, the code avoids redundant assignments and improves readability.


78-79: Consistent masking for BitcoinConfig!

The change to assign only the RPCParams from the original configuration to the BitcoinConfig structure is consistent with the updated masking approach for Bitcoin configuration. This simplifies the masking logic and reduces redundancy in the code.

zetaclient/context/chain_test.go (1)

76-76: LGTM!

The change in the assertion accurately categorizes the Ethereum chain by explicitly distinguishing it from Bitcoin. This enhances the specificity and correctness of the test case.

zetaclient/config/types_test.go (2)

19-62: Excellent test coverage for EVM configuration retrieval.

The Test_GetEVMConfig function is well-structured and covers important scenarios for retrieving EVM configurations. The sub-tests are clearly defined and validate the expected behavior of the GetEVMConfig method in various situations, such as when a valid endpoint is provided, when the endpoint is empty, and when the chain is empty.

The test cases ensure that the method correctly identifies valid configurations and handles cases where configurations are incomplete or missing. This comprehensive test coverage enhances the reliability and robustness of the EVM configuration handling.


64-125: Comprehensive test coverage for BTC configuration retrieval.

The Test_GetBTCConfig function utilizes a table-driven test approach, which is an effective way to test multiple scenarios in a concise and maintainable manner. The test cases cover important scenarios, such as finding a non-empty BTC configuration, falling back to an old configuration when a new one is not set, and ensuring that an empty configuration does not yield a valid result.

Each test case is well-defined, specifying the input parameters and the expected outcome. The assertions within each test case verify that the GetBTCConfig method behaves as expected based on the provided configurations.

This comprehensive test coverage enhances the reliability and robustness of the BTC configuration handling, ensuring that various edge cases are accounted for in the logic.

zetaclient/context/chain.go (1)

160-160: LGTM!

The function renaming from IsUTXO to IsBitcoin enhances clarity by explicitly indicating that it checks for a Bitcoin chain. The underlying logic remains unchanged and correctly uses the chains.IsBitcoinChain function. The function is concise and follows the single responsibility principle.

cmd/zetaclientd/debug.go (3)

172-172: LGTM!

The change from chain.IsUTXO() to chain.IsBitcoin() is appropriate and aligns with the objective of specifically handling Bitcoin chains.


176-179: LGTM!

The added check for the existence of the Bitcoin configuration and the corresponding error handling improves the robustness of the code by catching potential configuration issues early in the process.


181-186: LGTM!

Using the btcConfig values retrieved based on the chain ID ensures that the correct configuration is applied for the specific Bitcoin chain being processed. This change aligns with the objective of supporting multiple Bitcoin chain configurations.

zetaclient/config/types.go (4)

91-91: LGTM!

The change from a single BitcoinConfig field to a BTCChainConfigs map is a good enhancement to support multiple Bitcoin chain configurations. The backward compatibility concern raised in the past review comment is addressed in a subsequent commit.


106-108: LGTM!

The modifications to the GetEVMConfig method are correct and in line with the introduction of the EVMChainConfigs map to support multiple EVM chain configurations. Returning the config along with a boolean to indicate if it's empty is a good practice.


124-136: Excellent backward compatibility handling!

The modifications to the GetBTCConfig method are well-designed to support the new BTCChainConfigs map while maintaining backward compatibility with the deprecated BitcoinConfig field. This allows for a smooth transition to the new structure without breaking existing configurations.

The method first attempts to retrieve the config from the BTCChainConfigs map using the provided chainID. If the config is not found or if it's empty, it falls back to the deprecated BitcoinConfig field. This ensures that both new and old configurations can be handled gracefully.

Great job on implementing this change!


188-192: LGTM!

The modifications to the Empty method for EVMConfig and the addition of the Empty method for BTCConfig are correct and consistent with the expected behavior.

For EVMConfig, checking both the Endpoint and Chain fields ensures a comprehensive check for emptiness. This is important because both fields are required for a valid EVM configuration.

For BTCConfig, checking the RPCHost field is sufficient to determine if the config is empty. The RPCHost is a mandatory field for a valid Bitcoin configuration, so its presence or absence can be used to assess the emptiness of the config.

These changes enhance the reliability and correctness of the configuration checks.

zetaclient/context/app_test.go (4)

33-33: LGTM!

The change is part of the test setup and does not affect the production code. The specific key 111 and the username "satoshi" are likely chosen for testing purposes and align with the test's objective to support multiple Bitcoin chain configurations.


109-110: LGTM!

The assertions are correct and improve the test coverage by ensuring that the Ethereum chain is correctly identified. They align with the test's objective to verify the behavior of the AppContext when updating with new chains and parameters.


124-124: LGTM!

The assertion is correct and verifies that the Bitcoin chain configuration is correctly updated with the expected RPCUsername. It aligns with the test's objective to support multiple Bitcoin chain configurations.


33-33: Excellent test coverage and structure!

The changes introduce support for multiple Bitcoin chain configurations and assert the correct behavior of the AppContext when updating with new chains and parameters. The test cases cover various scenarios and use clear and descriptive names, making the test's purpose and expected behavior easily understandable.

The test cases follow the Given-When-Then (GWT) structure, improving readability and maintainability. The changes are well-structured and improve the overall test coverage of the AppContext.

Great work on enhancing the test suite!

Also applies to: 109-110, 124-124

zetaclient/orchestrator/bootstrap.go (2)

Line range hint 139-152: Improved clarity in handling Bitcoin chain configurations.

The changes enhance the clarity and specificity of the code by:

  • Explicitly fetching the Bitcoin configuration for the given chain ID using app.Config().GetBTCConfig(chainID).
  • Updating the log messages to provide clearer context regarding the inability to find configurations or construct signers for Bitcoin chains.

These modifications improve the readability and maintainability of the code without altering its fundamental logic.

Tools
GitHub Check: codecov/patch

[warning] 142-142: zetaclient/orchestrator/bootstrap.go#L142
Added line #L142 was not covered by tests


[warning] 148-148: zetaclient/orchestrator/bootstrap.go#L148
Added line #L148 was not covered by tests


Line range hint 323-350: Improved clarity in handling Bitcoin chain configurations.

Similar to the changes in syncSignerMap, the modifications in syncObserverMap enhance the clarity and specificity of the code by:

  • Explicitly fetching the Bitcoin configuration for the given chain ID using app.Config().GetBTCConfig(chainID).
  • Updating the log message to provide clearer context regarding the inability to find configurations for Bitcoin chain observers.

These changes improve the readability and maintainability of the code without altering its fundamental logic.

Tools
GitHub Check: codecov/patch

[warning] 326-326: zetaclient/orchestrator/bootstrap.go#L326
Added line #L326 was not covered by tests

zetaclient/orchestrator/bootstap_test.go (2)

52-52: LGTM!

The change to assign the Bitcoin configuration to a map using the chain ID as the key is a good improvement. It enhances the flexibility and scalability of the configuration management system, allowing for multiple Bitcoin chain configurations to be stored and accessed via their respective chain IDs. This change accommodates future expansions or variations in Bitcoin chain configurations without requiring significant changes to the underlying code structure.


230-230: LGTM!

The change to assign the Bitcoin configuration to a map using the chain ID as the key is consistent with the similar change made in the TestCreateSignerMap function. It improves the flexibility and scalability of the configuration management system for chain observers, allowing for multiple Bitcoin chain configurations to be stored and accessed via their respective chain IDs. This change enhances the overall design and maintainability of the codebase.

zetaclient/orchestrator/orchestrator_test.go (1)

524-525: LGTM!

The change consolidates the Bitcoin chain configuration logic and improves maintainability by handling it within the loop. The functionality remains the same.

zetaclient/orchestrator/orchestrator.go (1)

413-413: LGTM: The change enhances clarity and accuracy.

Explicitly checking for the Bitcoin blockchain using chain.IsBitcoin() instead of checking for the UTXO model is a good change. It directly associates the scheduling function with the Bitcoin blockchain rather than the more general UTXO model, which could potentially apply to other blockchains as well.

Tools
GitHub Check: codecov/patch

[warning] 413-413: zetaclient/orchestrator/orchestrator.go#L413
Added line #L413 was not covered by tests

changelog.md (1)

49-54: LGTM!

The new features are documented clearly and concisely, following the established changelog format.

zetaclient/orchestrator/bootstrap.go Show resolved Hide resolved
zetaclient/orchestrator/bootstrap.go Show resolved Hide resolved
zetaclient/orchestrator/orchestrator.go Show resolved Hide resolved
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

Let's wait for a review from @swift1337 for this one.

Not specifically for this PR but I think we should remove the concept of EVM and BTC configs in the future. Just keeping a list of config associated with a chain ID

changelog.md Outdated Show resolved Hide resolved
zetaclient/orchestrator/orchestrator_test.go Outdated Show resolved Hide resolved
@ws4charlie
Copy link
Contributor Author

Let's wait for a review from @swift1337 for this one.

Not specifically for this PR but I think we should remove the concept of EVM and BTC configs in the future. Just keeping a list of config associated with a chain ID

Totally agree. We'll need to a unified config struct (containing endpoint, user, password, etc.) for every external chain.

cmd/zetaclientd/start_utils.go Outdated Show resolved Hide resolved
zetaclient/config/types.go Show resolved Hide resolved
@ws4charlie ws4charlie added this pull request to the merge queue Sep 18, 2024
Merged via the queue into develop with commit 8d17118 Sep 18, 2024
26 checks passed
@ws4charlie ws4charlie deleted the support-multiple-btc-chains branch September 18, 2024 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants