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 active field for validator #278

Merged

Conversation

trestinlsd
Copy link
Contributor

@trestinlsd trestinlsd commented Jan 3, 2025

Description


Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added an active field to the Validator message to indicate presence in the Tendermint validator set.
    • Introduced a new method to check if a given address is an Exocore validator.
    • Added a new interface for staking functionality.
  • Improvements

    • Enhanced error handling in validator management operations.
    • Improved functionality related to consensus key management.
    • Updated the application structure to better integrate staking and operator functionalities.

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Walkthrough

This pull request introduces a new active boolean field to the Validator message in the protocol buffer definition and updates the consensus keys management in the keeper package. The changes enhance validator tracking by adding an indicator for a validator's presence in the Tendermint validator set. Additional modifications include refining error handling in the GetValidatorByConsAddrForChainID method and introducing a new interface for validator checks.

Changes

File Change Summary
proto/exocore/operator/v1/validator.proto Added new bool active = 12; field to Validator message
x/operator/keeper/consensus_keys.go Updated GetValidatorByConsAddrForChainID() method to set Active field and refined error handling
app/app.go Updated ExocoreApp to include StakingKeeper in OperatorKeeper initialization
x/dogfood/keeper/validators.go Added IsExocoreValidator method to Keeper struct
x/operator/keeper/keeper.go Added stakingKeeper field to Keeper struct and updated NewKeeper constructor
x/operator/types/expected_keepers.go Added new StakingKeeper interface with IsExocoreValidator method

Possibly related PRs

  • feat(appchains): Introduce module + register AVS #173: The changes in app/app.go regarding the initialization of the OperatorKeeper may relate to the management of validators, as the main PR introduces a new field in the Validator message that could affect how validators are handled in the application.
  • feat(Validator endpoints): Implement exocore validator endpoints #235: The addition of new RPC methods for querying validators in query.proto directly relates to the changes made in the main PR, which adds a field to the Validator message, enhancing the overall functionality related to validators.
  • fix(oracle): restart on validator set change #264: The modifications to the AggregatorContext and its handling of validator set changes may connect with the main PR's focus on validators, as both involve managing validator states and their implications in the system.
  • feat(evm): add predeployed contracts #279: The inclusion of predeployed contracts in the genesis state may indirectly relate to the management of validators, as the overall functionality of the network is enhanced, which could include how validators interact with these contracts.

Suggested labels

C:Types

Suggested reviewers

  • MaxMustermann2
  • bwhour
  • mikebraver
  • TimmyExogenous
  • leonz789
  • adu-web3

Poem

🐰 In the realm of validators, we hop and play,
With a new field active, brightening the way.
From consensus to keeper, our changes align,
Ensuring each validator's status will shine.
So let’s dance through the code, with joy and delight! 🌟


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.

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.

@trestinlsd trestinlsd changed the title Feature/add active field to validator feat:add active field for validator Jan 3, 2025
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

🧹 Nitpick comments (4)
x/operator/keeper/consensus_keys.go (4)

4-4: Apply gofumpt formatting.

Static analysis flags these lines for not being gofumpt-formatted. Consider running gofumpt or a compatible formatter to align with project guidelines and pass CI checks.

Also applies to: 7-7

🧰 Tools
🪛 golangci-lint (1.62.2)

4-4: File is not gofumpt-ed

(gofumpt)

🪛 GitHub Check: Run golangci-lint

[failure] 4-4:
File is not gofumpt-ed (gofumpt)


610-615: Leverage the existing context for remote queries.

Here, a new call to QueryCometbftValidators() is made, using context.Background(). Consider passing down the ctx from the caller or implementing a timeout/cancellation strategy for better control over potential network issues.


699-718: Parameterize RPC URL for better configuration.

QueryCometbftValidators() currently uses a hardcoded RPC URL ("http://localhost:26657"). Extracting this into a configurable parameter or environment variable can improve maintainability and accommodate different deployments.

🧰 Tools
🪛 golangci-lint (1.62.2)

718-718: File is not gofumpt-ed

(gofumpt)

🪛 GitHub Check: Run golangci-lint

[failure] 718-718:
File is not gofumpt-ed (gofumpt)


719-726: Optimize for large validator sets if performance is a concern.

IsAddressInSlice does a linear lookup. For large validator sets, consider using a map to achieve O(1) lookups. Otherwise, if the list remains small, the current approach is acceptable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a928315 and 6434e3e.

⛔ Files ignored due to path filters (1)
  • x/operator/types/validator.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (2)
  • proto/exocore/operator/v1/validator.proto (1 hunks)
  • x/operator/keeper/consensus_keys.go (3 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
x/operator/keeper/consensus_keys.go

4-4: File is not gofumpt-ed

(gofumpt)


7-7: File is not gofumpt-ed

(gofumpt)


718-718: File is not gofumpt-ed

(gofumpt)

🪛 GitHub Check: Run golangci-lint
x/operator/keeper/consensus_keys.go

[failure] 4-4:
File is not gofumpt-ed (gofumpt)


[failure] 7-7:
File is not gofumpt-ed (gofumpt)


[failure] 718-718:
File is not gofumpt-ed (gofumpt)

🔇 Additional comments (1)
proto/exocore/operator/v1/validator.proto (1)

59-60: New field aligns with the intended functionality.

Introducing the active field is straightforward and should default to false in Proto3, which makes sense for an opt-in setting. Ensure any client code handles the default correctly and updates this field only after verifying validator status in the Tendermint set.

@cloud8little cloud8little added this to the Testnet V8 milestone Jan 7, 2025
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

🧹 Nitpick comments (1)
x/operator/keeper/consensus_keys.go (1)

722-729: Consider optimizing address lookup for large validator sets.

The current implementation has O(n) time complexity. For large validator sets, consider using a map for O(1) lookup.

+func BuildAddressMap(addresses []sdk.ConsAddress) map[string]struct{} {
+    addrMap := make(map[string]struct{}, len(addresses))
+    for _, addr := range addresses {
+        addrMap[addr.String()] = struct{}{}
+    }
+    return addrMap
+}

 func IsAddressInSlice(address sdk.ConsAddress, addresses []sdk.ConsAddress) bool {
+    // For small slices (n < 50), keep the current implementation
+    if len(addresses) < 50 {
         for _, addr := range addresses {
             if addr.Equals(address) {
                 return true
             }
         }
         return false
+    }
+    
+    // For larger slices, use a map for O(1) lookup
+    addrMap := BuildAddressMap(addresses)
+    _, exists := addrMap[address.String()]
+    return exists
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6434e3e and 614913c.

📒 Files selected for processing (1)
  • x/operator/keeper/consensus_keys.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: goreleaser

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

🧹 Nitpick comments (1)
x/dogfood/keeper/validators.go (1)

158-158: Update method comment to accurately describe its purpose.

The current comment is copied from GetExocoreValidator and doesn't accurately describe what this method does. Consider updating it to:

// IsExocoreValidator checks if a validator exists based on the pub key derived (consensus) address.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 614913c and d7ee567.

📒 Files selected for processing (5)
  • app/app.go (1 hunks)
  • x/dogfood/keeper/validators.go (1 hunks)
  • x/operator/keeper/consensus_keys.go (2 hunks)
  • x/operator/keeper/keeper.go (3 hunks)
  • x/operator/types/expected_keepers.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/operator/keeper/consensus_keys.go
🧰 Additional context used
📓 Learnings (1)
x/operator/types/expected_keepers.go (1)
Learnt from: MaxMustermann2
PR: ExocoreNetwork/exocore#220
File: x/avs/types/expected_keepers.go:47-48
Timestamp: 2024-11-12T10:03:10.791Z
Learning: Adding new methods to the `OperatorKeeper` interface in `x/avs/types/expected_keepers.go` is acceptable, even if there are other unmodifiable `OperatorKeeper` interfaces elsewhere, because interfaces can be extended without causing conflicts.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (go)
  • GitHub Check: goreleaser
🔇 Additional comments (5)
x/operator/keeper/keeper.go (2)

23-23: LGTM! Field placement follows existing pattern.

The stakingKeeper field is appropriately placed with other keeper dependencies.


35-35: LGTM! Consistent initialization of stakingKeeper.

The stakingKeeper parameter and initialization follow the established pattern for keeper dependencies.

Also applies to: 45-45

x/operator/types/expected_keepers.go (1)

144-146: LGTM! Clean interface definition.

The StakingKeeper interface is well-defined with a single, focused responsibility. The method name and signature clearly indicate its purpose.

x/dogfood/keeper/validators.go (1)

159-164: LGTM! Efficient implementation.

The implementation efficiently checks for validator existence using store.Has() instead of loading the full validator data.

app/app.go (1)

701-701: LGTM! Proper dependency injection.

The StakingKeeper is correctly wired into the OperatorKeeper initialization, maintaining the proper dependency graph.

Copy link
Contributor

@adu-web3 adu-web3 left a comment

Choose a reason for hiding this comment

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

LGTM, but we already have stakingtypes.Validator, so what's the difference of this types.Validator from stakingtypes.Validator?

@MaxMustermann2
Copy link
Contributor

LGTM, but we already have stakingtypes.Validator, so what's the difference of this types.Validator from stakingtypes.Validator?

It's the x/dogfood version of validator, containing only the consensus address, the consensus key and the vote power.

@adu-web3
Copy link
Contributor

adu-web3 commented Jan 8, 2025

LGTM, but we already have stakingtypes.Validator, so what's the difference of this types.Validator from stakingtypes.Validator?

It's the x/dogfood version of validator, containing only the consensus address, the consensus key and the vote power.

thanks, I see, so this is only used for querying?

@MaxMustermann2
Copy link
Contributor

LGTM, but we already have stakingtypes.Validator, so what's the difference of this types.Validator from stakingtypes.Validator?

It's the x/dogfood version of validator, containing only the consensus address, the consensus key and the vote power.

thanks, I see, so this is only used for querying?

No; it is important to x/dogfood. It wasn't introduced in this PR but has been present throughout. My rationale behind creating this type is that the x/dogfood module only needs to know the bare-minimum information (key and vote power) to pass to the consensus engine. Everything else can be handled by other modules; for example, x/operator handles the metadata of each operator and maps back from the consensus address to the account address.

Copy link
Contributor

@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.

LGTM.

Copy link
Contributor

@TimmyExogenous TimmyExogenous left a comment

Choose a reason for hiding this comment

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

LGTM

@trestinlsd trestinlsd merged commit 5ad71ea into imua-xyz:develop Jan 8, 2025
22 checks passed
Copy link

@magj2006 magj2006 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants