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: enable multiple confirmation count values in chain params #3461

Merged
merged 13 commits into from
Feb 6, 2025

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Feb 4, 2025

Description

Added an extra Confirmation field to chain params struct so we could have fine-grained, separate control over inbound/outbound confirmation counts and safe/fast confirmation counts.

type ConfirmationParams struct {
    SafeInboundCount  uint64
    FastInboundCount  uint64
    SafeOutboundCount uint64
    FastOutboundCount uint64
}

Closes: #3423

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

  • New Features
    • Introduced enhanced configuration settings including liquidity caps for token creation and multiple confirmation count values.
    • Added a new CLI command for retrieving inbound ballots and upgraded core platform components.
  • Refactor
    • Streamlined cross-chain transaction workflows to optimize performance and observability.
  • Bug Fixes
    • Improved error handling for transaction fee validations.
  • Documentation
    • Expanded API specifications with detailed confirmation metrics.
  • Tests
    • Implemented comprehensive tests to verify migration integrity and configuration updates.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

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

This update introduces significant changes across the codebase in version 27.0.0. The modifications include an updated changelog detailing breaking changes and new features, enhancements to API documentation with additional confirmation structures, and expanded Protocol Buffers definitions. The observer module now incorporates a new Confirmation field into the ChainParams structure along with additional validation checks, while migration functions and tests have been added to transition the state from consensus version 9 to 10. Test utilities and mocks have also been updated to include the new confirmation data.

Changes

File(s) Change Summary
changelog.md, docs/openapi/openapi.swagger.yaml, typescript/zetachain/zetacore/observer/index.d.ts Updated changelog for v27.0.0 with breaking changes, new features, and fixes; enhanced OpenAPI spec with a new confirmation property and observerConfirmation object; added an export for the new confirmation protobuf definitions.
proto/zetachain/zetacore/observer/confirmation.proto, proto/zetachain/zetacore/observer/params.proto Introduced a new Protocol Buffers message Confirmation with confirmation count fields; in params.proto, replaced the import from observer.proto to confirmation.proto and added a non-nullable Confirmation field to the ChainParams message.
x/observer/keeper/migrator.go, x/observer/migrations/v10/migrate.go, x/observer/migrations/v10/migrate_test.go, x/observer/module.go, x/observer/types/chain_params.go, x/observer/types/chain_params_test.go Added a migration function (Migrate9to10) and updated migration registration in the module; updated consensus version from 9 to 10; enhanced ChainParams with a new Confirmation struct and validation logic; added tests to validate the migration and updated chain parameter functionality.
testutil/sample/observer.go, zetaclient/testutils/mocks/chain_params.go Updated ChainParams generation functions and mocks to include new fields (GatewayAddress and Confirmation) in the returned structures, with the Confirmation field initialized using new logic.

Sequence Diagram(s)

sequenceDiagram
    participant M as Migrator
    participant V10 as v10.MigrateStore
    participant OK as observerKeeper
    participant DB as ChainParams Store

    M->>V10: Call Migrate9to10(ctx)
    V10->>OK: GetChainParamsList(ctx)
    OK-->>V10: Return ChainParams list
    V10->>V10: For each ChainParams update Confirmation fields<br/>(safe_inbound, fast_inbound, safe_outbound, fast_outbound)
    V10->>OK: SetChainParamsList(updated list)
    OK-->>V10: Acknowledge update
    V10-->>M: Return success (nil)
Loading

Assessment against linked issues

Objective Addressed Explanation
Enable multiple confirmation count values in chain params (#3423)

Possibly related PRs

Suggested labels

breaking:cli, UPGRADE_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • swift1337
  • skosito
  • lumtis

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. (Beta)
  • @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.

@ws4charlie ws4charlie added zetacore Issues related to ZetaCore UPGRADE_TESTS Run make start-upgrade-tests labels Feb 4, 2025
Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.41%. Comparing base (5cda985) to head (d9a8d62).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3461      +/-   ##
===========================================
+ Coverage    65.29%   65.41%   +0.11%     
===========================================
  Files          441      442       +1     
  Lines        30425    30521      +96     
===========================================
+ Hits         19865    19964      +99     
+ Misses        9704     9702       -2     
+ Partials       856      855       -1     
Files with missing lines Coverage Δ
x/observer/migrations/v10/migrate.go 100.00% <100.00%> (ø)
x/observer/types/chain_params.go 94.62% <100.00%> (+2.39%) ⬆️

@ws4charlie ws4charlie removed the UPGRADE_TESTS Run make start-upgrade-tests label Feb 4, 2025
@ws4charlie ws4charlie marked this pull request as ready for review February 4, 2025 05:33
@ws4charlie ws4charlie requested a review from a team as a code owner February 4, 2025 05:33
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: 6

🧹 Nitpick comments (7)
x/observer/migrations/v10/migrate_test.go (3)

15-25: Consider adding more diverse test cases.

The test data could be more comprehensive. Consider adding edge cases such as:

  • Maximum allowed values for confirmation counts
  • Different combinations of fast/safe counts
  • Chain params with existing confirmation values

27-65: Add assertions for individual field migrations.

While the test verifies overall equality, it would be beneficial to add specific assertions for each migrated field before the final comparison.

 // compare the old and new chain params
 for i, newParam := range newChainParams.ChainParams {
     oldParam := oldChainParams.ChainParams[i]
+    
+    // Assert chain ID remains unchanged
+    require.Equal(t, oldParam.ChainId, newParam.ChainId)
+    
+    // Assert old confirmation count is correctly migrated
+    require.Equal(t, oldParam.ConfirmationCount, newParam.ConfirmationCount)
 
     // ensure the confirmation fields are set correctly
     require.Equal(t, newParam.Confirmation.SafeInboundCount, oldParam.ConfirmationCount)

86-92: Consider adding validation for confirmation values.

The helper function could validate that confirmation counts are non-negative.

 func makeChainParamsEmptyConfirmation(chainID int64, confirmationCount uint64) *types.ChainParams {
+    if confirmationCount < 0 {
+        panic("confirmation count must be non-negative")
+    }
     chainParams := sample.ChainParams(chainID)
     chainParams.ConfirmationCount = confirmationCount
     chainParams.Confirmation = types.Confirmation{}
     return chainParams
 }
x/observer/types/chain_params_test.go (1)

160-177: Consider adding boundary test cases.

While the validation tests are good, consider adding tests for:

  • Maximum allowed values
  • Equal safe/fast counts
  • Zero fast count (disabled state)
x/observer/types/chain_params.go (2)

192-197: Extract common confirmation count values into constants.

The confirmation count values are repeated across multiple chain configurations. Consider extracting these into named constants for better maintainability.

+const (
+	DefaultEthereumConfirmationCount   = 14
+	DefaultBitcoinConfirmationCount    = 2
+	DefaultTestnetConfirmationCount    = 6
+	DefaultLocalnetConfirmationCount   = 1
+)

 func GetDefaultEthMainnetChainParams() *ChainParams {
 	return &ChainParams{
 		// ...
 		Confirmation: Confirmation{
-			SafeInboundCount:  14,
-			FastInboundCount:  14,
-			SafeOutboundCount: 14,
-			FastOutboundCount: 14,
+			SafeInboundCount:  DefaultEthereumConfirmationCount,
+			FastInboundCount:  DefaultEthereumConfirmationCount,
+			SafeOutboundCount: DefaultEthereumConfirmationCount,
+			FastOutboundCount: DefaultEthereumConfirmationCount,
 		},
 	}
 }

Also applies to: 216-221, 241-245, 266-270, 290-294, 314-318, 338-342, 362-366, 387-391


429-430: Implement explicit field comparison for Confirmation struct.

Direct struct comparison might not be safe if the Confirmation struct is modified in the future. Consider comparing individual fields explicitly.

-		params1.GatewayAddress == params2.GatewayAddress &&
-		params1.Confirmation == params2.Confirmation
+		params1.GatewayAddress == params2.GatewayAddress &&
+		params1.Confirmation.SafeInboundCount == params2.Confirmation.SafeInboundCount &&
+		params1.Confirmation.FastInboundCount == params2.Confirmation.FastInboundCount &&
+		params1.Confirmation.SafeOutboundCount == params2.Confirmation.SafeOutboundCount &&
+		params1.Confirmation.FastOutboundCount == params2.Confirmation.FastOutboundCount
docs/openapi/openapi.swagger.yaml (1)

59812-59826: ObserverConfirmation Object Definition
The newly defined observerConfirmation object, with its four distinct properties (safe_inbound_count, fast_inbound_count, safe_outbound_count, and fast_outbound_count), is well structured. The use of type: string with format: uint64 is a common pattern in APIs to safely represent large integers. However, please verify consistency with other similar definitions in your codebase, and ensure that clients correctly parse these values as unsigned 64-bit integers.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9106fe6 and a72b421.

⛔ Files ignored due to path filters (4)
  • typescript/zetachain/zetacore/observer/confirmation_pb.d.ts is excluded by !**/*_pb.d.ts
  • typescript/zetachain/zetacore/observer/params_pb.d.ts is excluded by !**/*_pb.d.ts
  • x/observer/types/confirmation.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/observer/types/params.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
📒 Files selected for processing (13)
  • changelog.md (1 hunks)
  • docs/openapi/openapi.swagger.yaml (2 hunks)
  • proto/zetachain/zetacore/observer/confirmation.proto (1 hunks)
  • proto/zetachain/zetacore/observer/params.proto (2 hunks)
  • testutil/sample/observer.go (2 hunks)
  • typescript/zetachain/zetacore/observer/index.d.ts (1 hunks)
  • x/observer/keeper/migrator.go (2 hunks)
  • x/observer/migrations/v10/migrate.go (1 hunks)
  • x/observer/migrations/v10/migrate_test.go (1 hunks)
  • x/observer/module.go (2 hunks)
  • x/observer/types/chain_params.go (11 hunks)
  • x/observer/types/chain_params_test.go (3 hunks)
  • zetaclient/testutils/mocks/chain_params.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
x/observer/keeper/migrator.go (1)

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

proto/zetachain/zetacore/observer/confirmation.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

zetaclient/testutils/mocks/chain_params.go (1)

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

x/observer/module.go (1)

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

x/observer/types/chain_params.go (1)

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

testutil/sample/observer.go (1)

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

proto/zetachain/zetacore/observer/params.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

x/observer/migrations/v10/migrate_test.go (1)

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

x/observer/types/chain_params_test.go (1)

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

x/observer/migrations/v10/migrate.go (1)

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

🪛 Buf (1.47.2)
proto/zetachain/zetacore/observer/confirmation.proto

2-2: Files with package "zetachain.zetacore.observer" must be within a directory "zetachain/zetacore/observer" relative to root but were in directory "proto/zetachain/zetacore/observer".

(PACKAGE_DIRECTORY_MATCH)


6-11: Message "Confirmation" should have a non-empty comment for documentation.

(COMMENT_MESSAGE)

🔇 Additional comments (11)
typescript/zetachain/zetacore/observer/index.d.ts (1)

4-4: LGTM! Export follows established pattern.

The new export for confirmation_pb aligns with the existing export structure and supports the new confirmation types.

x/observer/keeper/migrator.go (1)

60-63: LGTM! Migration function follows established pattern.

The implementation correctly delegates to the v10 migration logic and maintains consistency with existing migration functions.

x/observer/migrations/v10/migrate_test.go (1)

67-83: LGTM! Good error case coverage.

The test properly verifies the error case when chain params are not found.

x/observer/module.go (2)

155-157: LGTM! Migration registration follows established pattern.

The migration registration follows the same pattern as previous migrations.


182-182: LGTM! Consensus version updated correctly.

The consensus version is correctly incremented to 10.

x/observer/types/chain_params_test.go (1)

72-77: LGTM! Good test coverage for confirmation fields.

The test setup properly initializes both EVM and BTC chain params with appropriate confirmation values.

Also applies to: 94-99

docs/openapi/openapi.swagger.yaml (1)

59802-59803: New Confirmation Field Addition
The new confirmation field is correctly added and references the observerConfirmation definition. Ensure that downstream consumers are aware of this new field change for proper integration.

proto/zetachain/zetacore/observer/confirmation.proto (1)

1-2: Directory Structure and Package Alignment.
Static analysis indicates that files declared with the package zetachain.zetacore.observer should reside in a directory structured as zetachain/zetacore/observer relative to the repository root. Since this file is located under proto/zetachain/zetacore/observer, please verify that this arrangement is intentional and consistent with your project’s organizational conventions.

🧰 Tools
🪛 Buf (1.47.2)

2-2: Files with package "zetachain.zetacore.observer" must be within a directory "zetachain/zetacore/observer" relative to root but were in directory "proto/zetachain/zetacore/observer".

(PACKAGE_DIRECTORY_MATCH)

proto/zetachain/zetacore/observer/params.proto (2)

5-5: Updated Import of Confirmation Definition.
The import statement for "zetachain/zetacore/observer/confirmation.proto" has been added to incorporate the new Confirmation message. Please verify that the import path is correct relative to your project's proto search paths and aligns with your overall directory structure.


33-33: 🛠️ Refactor suggestion

Integrating the New Confirmation Field.
A new field of type Confirmation has been appended to the ChainParams message at line 33. While this addition provides enhanced granularity through multiple confirmation counts, note that an existing field (confirmation_count at line 13) is still present. If the intention is to replace the old aggregated count with the new structure, consider deprecating or removing the confirmation_count field to avoid ambiguity in future iterations. For example, you might add a deprecation option or comment to signal its planned removal.

changelog.md (1)

18-18: Clear Changelog Entry for Multiple Confirmation Count Values.
The changelog entry at line 18 succinctly documents the feature update introduced by [PR #3461]. This new entry reflects the implementation of multiple confirmation count values in the chain parameters. It may be beneficial to ensure that any necessary migration details or usage notes are also referenced in your documentation elsewhere.

x/observer/migrations/v10/migrate.go Outdated Show resolved Hide resolved
zetaclient/testutils/mocks/chain_params.go Outdated Show resolved Hide resolved
testutil/sample/observer.go Outdated Show resolved Hide resolved
x/observer/types/chain_params.go Outdated Show resolved Hide resolved
x/observer/types/chain_params.go Outdated Show resolved Hide resolved
proto/zetachain/zetacore/observer/confirmation.proto Outdated Show resolved Hide resolved
changelog.md Outdated Show resolved Hide resolved
proto/zetachain/zetacore/observer/confirmation.proto Outdated Show resolved Hide resolved
proto/zetachain/zetacore/observer/params.proto Outdated Show resolved Hide resolved
testutil/sample/observer.go Outdated Show resolved Hide resolved
testutil/sample/observer.go Outdated Show resolved Hide resolved
x/observer/migrations/v10/migrate_test.go Outdated Show resolved Hide resolved
x/observer/migrations/v10/migrate_test.go Outdated Show resolved Hide resolved
x/observer/types/chain_params.go Outdated Show resolved Hide resolved
@ws4charlie ws4charlie requested a review from lumtis February 4, 2025 18:57
x/observer/types/chain_params.go Show resolved Hide resolved
proto/zetachain/zetacore/observer/params.proto Outdated Show resolved Hide resolved
x/observer/types/chain_params_test.go Outdated Show resolved Hide resolved
@gartnera gartnera requested a review from a team February 4, 2025 19:04
@ws4charlie ws4charlie requested a review from gartnera February 4, 2025 20:14
changelog.md Outdated Show resolved Hide resolved
@ws4charlie ws4charlie requested a review from kingpinXD February 4, 2025 23:32
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.

This looks good to me but please attach a upgrade test to the CI when you have a igration script in your PR

@lumtis lumtis added the UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light label Feb 5, 2025
@ws4charlie ws4charlie added this pull request to the merge queue Feb 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2025
@ws4charlie ws4charlie added this pull request to the merge queue Feb 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2025
@ws4charlie ws4charlie added this pull request to the merge queue Feb 5, 2025
@ws4charlie ws4charlie removed this pull request from the merge queue due to a manual request Feb 5, 2025
@ws4charlie ws4charlie added the CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change label Feb 5, 2025
@ws4charlie ws4charlie added this pull request to the merge queue Feb 5, 2025
Merged via the queue into develop with commit 304c4d7 Feb 6, 2025
52 checks passed
@ws4charlie ws4charlie deleted the feat-add-multiple-confirmation-counts branch February 6, 2025 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:proto CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light zetacore Issues related to ZetaCore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable multiple confirmation count values in chain params
4 participants