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: refactor consumers config #55

Merged
merged 7 commits into from
Jun 16, 2024
Merged

Conversation

freak12techno
Copy link
Collaborator

@freak12techno freak12techno commented Jun 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new methods for handling denomination information, validation, and warnings.
    • Added GetConsumerAssignedKey method to the RPC struct for key management.
  • Bug Fixes

    • Fixed inconsistencies by updating various fetcher and generator structs to use the new tendermint.RPCWithConsumers.
  • Enhancements

    • Improved configuration handling with new methods for retrieving chain queries, host information, and validation.
    • Updated RPC struct to include ChainName, ChainHost, and ChainQueries for better context management.

@freak12techno freak12techno changed the title Refactor consumers config feat: refactor consumers config Jun 15, 2024
Copy link
Contributor

coderabbitai bot commented Jun 15, 2024

Walkthrough

The changes encompass significant updates across various files within the codebase, including structural modifications to configuration, fetching, and RPC handling. Notably, new interfaces, structs, and methods are introduced for handling and validating configurations, querying, and managing consumer chains. The transformation enhances functionality and improves the flexibility of configurations and RPC interactions, notably shifting from tendermint.RPC to tendermint.RPCWithConsumers.

Changes

Files / Groups Change Summary
.golangci.yml Adjusted linter configurations, enabling/disabling specific linters.
pkg/app.go Modified App struct's RPCs map to use tendermint.RPCWithConsumers.
pkg/config/chain.go, pkg/config/config.go Enhanced Chain struct with validation methods, updated fields and default values, added ConsumerChain.
New Config Files (various) Added chain_info.go, consumer_chain.go, denom_info.go, query.go, tracing.go with new structs/methods.
Multiple Fetcher Files (pkg/fetchers/...) Updated fetchers to use tendermint.RPCWithConsumers and revised method signatures and fields.
Generator Files (pkg/generators/...) Updated generators to handle slices of pointers to config.Chain rather than config.Chain directly.
pkg/tendermint/rpc.go, pkg/tendermint/rpc_with_consumers.go, pkg/types/tendermint.go Revised RPC struct and added new RPCWithConsumers struct, updated method implementations and function signatures, added AssignedKeyResponse struct.

Poem

🌈 In the realm where code does play,
Chains and queries find their way. 🌐
A rabbit hops, with bytes it weaves,
RPCs dance, and balance fetchers breathe!
Configs validated, warnings shine,
In this enchanted code define. ✨


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>.
    • 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 show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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: 5

Outside diff range and nitpick comments (5)
pkg/config/query.go (1)

3-11: The Queries type and its Enabled method are correctly implemented. Consider adding documentation for the method to explain the default behavior of enabling all queries unless explicitly disabled.

pkg/fetchers/validators.go (1)

Line range hint 54-75: Ensure proper handling of goroutines and synchronization. The use of RPC.RPC might be confusing and could benefit from renaming for clarity.

Consider renaming RPC.RPC to something more descriptive to avoid confusion, such as BaseRPC.

pkg/fetchers/rewards.go (1)

Line range hint 59-101: Concurrency is handled well with sync.WaitGroup and sync.Mutex. However, consider adding error handling for the rpc lookup.

- rpc, _ := q.RPCs[chain.Name]
+ rpc, exists := q.RPCs[chain.Name]
+ if !exists {
+     q.Logger.Error().Str("chain", chain.Name).Msg("RPC configuration not found")
+     continue
+ }
pkg/fetchers/self_delegation.go (1)

Line range hint 60-102: Concurrency is handled well with sync.WaitGroup and sync.Mutex. However, consider adding error handling for the rpc lookup.

- rpc, _ := q.RPCs[chain.Name]
+ rpc, exists := q.RPCs[chain.Name]
+ if !exists {
+     q.Logger.Error().Str("chain", chain.Name).Msg("RPC configuration not found")
+     continue
+ }
pkg/tendermint/rpc.go (1)

[!TIP]
Codebase Verification

The verification scripts did not find any unit tests in pkg/tendermint/rpc.go or pkg/utils/utils.go, which are the files where the parsing logic is present. This indicates a potential lack of test coverage for the parsing logic.

  • Please ensure that the parsing logic for the threshold value is robust and handles potential edge cases.
  • Add unit tests to cover the parsing logic in pkg/tendermint/rpc.go and pkg/utils/utils.go.
Analysis chain

Line range hint 410-422: GetConsumerSoftOutOutThreshold method uses the Enabled check, which is consistent with other methods. Ensure that the parsing logic for the threshold value is robust and handles potential edge cases.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the robustness of parsing logic for threshold values.

# Test: Search for unit tests covering the parsing logic.
rg --type python $'strconv.ParseFloat'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify the robustness of parsing logic for threshold values.

# Step 1: Search for the parsing logic in Go files
rg --type go 'ParseFloat|ParseInt|Atof|Atoi'

# Step 2: Search for unit tests covering the parsing logic
rg --type go 'ParseFloat|ParseInt|Atof|Atoi' --files-with-matches | xargs -I {} sh -c 'rg -l "func Test" {}'

Length of output: 417



Script:

#!/bin/bash
# Description: Verify the robustness of parsing logic for threshold values.

# Step 1: Search for unit tests in the identified files
rg --type go 'func Test' pkg/tendermint/rpc.go pkg/utils/utils.go

Length of output: 67

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ec959b4 and 2f23cd7.

Files selected for processing (29)
  • .golangci.yml (2 hunks)
  • pkg/app.go (2 hunks)
  • pkg/config/chain.go (1 hunks)
  • pkg/config/chain_info.go (1 hunks)
  • pkg/config/config.go (2 hunks)
  • pkg/config/consumer_chain.go (1 hunks)
  • pkg/config/denom_info.go (1 hunks)
  • pkg/config/query.go (1 hunks)
  • pkg/config/tracing.go (1 hunks)
  • pkg/fetchers/balance.go (3 hunks)
  • pkg/fetchers/commission.go (4 hunks)
  • pkg/fetchers/delegations.go (4 hunks)
  • pkg/fetchers/node_info.go (3 hunks)
  • pkg/fetchers/rewards.go (4 hunks)
  • pkg/fetchers/self_delegation.go (4 hunks)
  • pkg/fetchers/signing_info.go (4 hunks)
  • pkg/fetchers/slashing_params.go (3 hunks)
  • pkg/fetchers/soft_opt_out_threshold.go (3 hunks)
  • pkg/fetchers/staking_params.go (4 hunks)
  • pkg/fetchers/unbonds.go (4 hunks)
  • pkg/fetchers/validators.go (4 hunks)
  • pkg/generators/active_set_tokens.go (1 hunks)
  • pkg/generators/denom_coefficient.go (2 hunks)
  • pkg/generators/is_consumer.go (2 hunks)
  • pkg/generators/single_validator_info.go (3 hunks)
  • pkg/generators/validator_rank.go (1 hunks)
  • pkg/tendermint/rpc.go (25 hunks)
  • pkg/tendermint/rpc_with_consumers.go (1 hunks)
  • pkg/types/tendermint.go (1 hunks)
Files not reviewed due to errors (6)
  • pkg/config/tracing.go (no review received)
  • pkg/fetchers/node_info.go (no review received)
  • pkg/fetchers/delegations.go (no review received)
  • pkg/generators/single_validator_info.go (no review received)
  • pkg/fetchers/signing_info.go (no review received)
  • pkg/app.go (no review received)
Additional comments not posted (59)
pkg/config/chain_info.go (1)

3-7: Interface ChainInfo is well-defined with essential methods for chain operations.

.golangci.yml (1)

26-26: The linter settings have been updated to disable a significant number of linters. Ensure that the disabling of these linters is justified and documented, especially for critical ones like gosec and errorlint. This could impact the code quality and security assessments.

pkg/generators/is_consumer.go (2)

12-12: Using a slice of pointers in IsConsumerGenerator is a good practice for memory efficiency and ensuring data consistency across the application.


Line range hint 15-37: The Generate method effectively utilizes Prometheus gauges and labels to monitor whether chains are consumers, showcasing good use of external libraries for monitoring.

pkg/config/denom_info.go (2)

9-16: The DenomInfo struct is well-structured with sensible defaults and serialization tags, ensuring that the denomination data is robustly managed.


30-37: The DisplayWarnings method proactively logs configuration issues using structured logging, which is an excellent practice for maintaining system health.

pkg/config/consumer_chain.go (5)

8-18: The ConsumerChain struct is well-defined, effectively handling complex configurations with appropriate data types and serialization tags.


32-51: The Validate method in ConsumerChain thoroughly checks all necessary fields and validates DenomInfo within a loop, ensuring the integrity of the consumer chain configuration.


20-22: The GetQueries method correctly provides access to the Queries field, following good encapsulation practices.


24-26: The GetHost method correctly encapsulates access to the LCDEndpoint field.


28-30: The GetName method correctly provides access to the Name field, adhering to good encapsulation practices.

pkg/fetchers/validators.go (2)

18-18: Refactored RPCs field to use RPCWithConsumers aligns with the new architecture to handle consumer chains.


29-29: Correctly updated the constructor to accept RPCWithConsumers which matches the structural change in the ValidatorsFetcher struct.

pkg/fetchers/staking_params.go (3)

18-18: Refactored RPCs field to use RPCWithConsumers aligns with the new architecture to handle consumer chains.


29-29: Correctly updated the constructor to accept RPCWithConsumers, ensuring consistency with the structural change in the StakingParamsFetcher struct.


Line range hint 55-81: Good addition of comments explaining the context of fetching staking parameters only for provider chains. Proper error handling and synchronization in the goroutine.

pkg/generators/denom_coefficient.go (1)

Line range hint 12-66: The refactoring to use pointers in Chains is consistent with changes in other parts of the codebase. The iteration over consumer chains and handling of denominations are well-implemented. Ensure that the DenomCoefficient field exists in the DenomInfo struct.

Verification successful

The DenomCoefficient field exists in the DenomInfo struct as expected.

  • pkg/config/denom_info.go:
    • DenomCoefficient int64 default:"1000000" toml:"denom-coefficient"`
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the existence of `DenomCoefficient` field in the `DenomInfo` struct.

# Test: Search for the `DenomCoefficient` field definition. Expect: Definition found.
rg --type go $'type DenomInfo struct {.*DenomCoefficient.*}'

Length of output: 211



Script:

#!/bin/bash
# Description: Verify the existence of `DenomCoefficient` field in the `DenomInfo` struct.

# Test: Search for the `DenomCoefficient` field definition. Expect: Definition found.
rg --type go 'type DenomInfo struct {[^}]*DenomCoefficient[^}]*}'

Length of output: 223



Script:

#!/bin/bash
# Description: Verify the existence of `DenomCoefficient` field in the `DenomInfo` struct.

# Test: Search for the `DenomInfo` struct definition and check for the `DenomCoefficient` field within it.
rg --type go 'type DenomInfo struct' -A 10 | rg 'DenomCoefficient'

Length of output: 174

pkg/config/config.go (2)

30-30: Update the default value of ListenAddress to ":9560" to accommodate new port requirements.


32-32: Switched from a slice of Chain to a slice of pointers to Chain to potentially reduce memory usage and enhance performance when manipulating large configurations.

pkg/fetchers/soft_opt_out_threshold.go (3)

18-18: Updated RPCs to use RPCWithConsumers reflecting the new structure to handle multiple consumers for each chain.


29-29: Constructor now accepts map[string]*tendermint.RPCWithConsumers to initialize the fetcher with the updated RPC structure.


53-80: Refactored the fetch logic to handle multiple consumer chains per RPC. This change allows fetching thresholds for each consumer chain separately, improving data granularity and potentially enhancing error isolation in multi-consumer environments.

pkg/fetchers/commission.go (3)

18-18: Updated RPCs to use RPCWithConsumers, aligning with the new architecture to support multiple consumer chains.


29-29: Constructor updated to accept RPCWithConsumers, ensuring compatibility with the new RPC handling mechanism.


Line range hint 47-86: Enhanced the logic to fetch commission data for each validator across all chains, now considering the updated RPC structure. The new implementation is designed to handle multiple consumers per chain, which is crucial for accurate data fetching in environments with complex chain configurations.

pkg/fetchers/unbonds.go (3)

19-19: Updated RPCs to use RPCWithConsumers, aligning with the new architecture to support multiple consumer chains.


30-30: Constructor updated to accept RPCWithConsumers, ensuring compatibility with the new RPC handling mechanism.


Line range hint 60-88: Refactored the logic to fetch unbonding information for each validator across all chains, considering the updated RPC structure. This implementation is crucial for environments where chains have multiple consumers, ensuring accurate and isolated data retrieval.

pkg/generators/active_set_tokens.go (3)

16-16: The change to use pointers for Chains in ActiveSetTokensGenerator is appropriate for efficient memory management and consistent with the broader refactoring strategy observed in other parts of the system.


19-19: Correct implementation of the constructor for ActiveSetTokensGenerator using pointers, ensuring memory efficiency and consistency with the rest of the application's architecture.


19-19: The Generate function is well-implemented, handling multiple edge cases and integrating various components effectively to produce the desired metrics.

pkg/fetchers/slashing_params.go (3)

18-18: Updating the RPCs field to use RPCWithConsumers aligns with the refactor goal to enhance concurrent processing capabilities and manage multiple consumer chains more effectively.


35-35: Proper initialization of SlashingParamsFetcher with RPCWithConsumers, ensuring consistency with the new system architecture.


49-67: The Fetch method is robust, effectively managing concurrency and error handling while fetching slashing parameters across multiple chains and their consumers.

pkg/fetchers/rewards.go (3)

19-19: Refactor to use RPCWithConsumers aligns with the updated architecture.


30-30: Constructor correctly initializes the RewardsFetcher with the new RPCWithConsumers type.


47-49: Initialization of allRewards is clear and correctly scoped within the fetch loop.

pkg/fetchers/self_delegation.go (3)

19-19: Refactor to use RPCWithConsumers aligns with the updated architecture.


30-30: Constructor correctly initializes the SelfDelegationFetcher with the new RPCWithConsumers type.


48-51: Initialization of allSelfDelegations is clear and correctly scoped within the fetch loop.

pkg/generators/validator_rank.go (2)

18-18: Use of pointers for Chains in ValidatorRankGenerator aligns with the updated data structure.


23-23: Constructor correctly initializes the ValidatorRankGenerator with the new pointer-based Chains.

pkg/fetchers/balance.go (3)

19-19: Refactor to use RPCWithConsumers aligns with the updated architecture.


36-36: Constructor correctly initializes the BalanceFetcher with the new RPCWithConsumers type.


50-57: Initialization of allBalances is clear and correctly scoped within the fetch loop. Handling of consumer chains is also correctly implemented.

pkg/types/tendermint.go (1)

123-126: The addition of AssignedKeyResponse struct aligns well with existing response structures and appears to be correctly integrated.

pkg/tendermint/rpc.go (13)

21-27: LGTM! The updated RPC struct now includes ChainQueries, which supports the new configurable query enabling feature.


33-46: Improved constructor function NewRPC using the ChainInfo interface. This aligns with the new architecture, allowing more flexibility and encapsulation of chain-related information.


Line range hint 127-143: The method GetSingleDelegation correctly checks the query enablement before proceeding. This pattern is consistent and should be maintained across all similar methods.


Line range hint 166-176: Consistent use of the Enabled check in GetAllValidators. This is a critical pattern ensuring that only enabled queries are processed.


Line range hint 196-209: The GetValidatorCommission method reflects consistent application of the new query enabling system. It's crucial that all such methods follow this pattern to ensure system integrity.


Line range hint 274-287: The method GetWalletBalance correctly uses the new ChainQueries structure to check if the query is enabled, which is a good practice.


Line range hint 351-362: The method GetSigningInfo correctly uses the Enabled check. This consistency is key to the new configuration's effectiveness.


Line range hint 381-391: GetSlashingParams method uses the Enabled check effectively. Consistency in these checks across the system is crucial.


Line range hint 448-458: GetStakingParams method consistently uses the Enabled check. This method's implementation aligns with the system's architectural changes.


Line range hint 477-487: GetNodeInfo method's implementation is consistent with the new system's architecture, using the Enabled check effectively.


Line range hint 233-249: Use of Enabled in GetDelegatorRewards maintains consistency. As with other similar methods, ensure this logic is backed by robust tests.


Line range hint 57-70: Refactor in GetDelegationsCount method to use ChainQueries.Enabled is a good use of the new configuration capabilities. However, ensure that the Enabled method is thoroughly tested to handle all expected inputs correctly.


Line range hint 92-105: Similar to the previous method, GetUnbondsCount also uses the Enabled method effectively. Ensure comprehensive test coverage for these query checks.

pkg/tendermint/rpc_with_consumers.go Show resolved Hide resolved
pkg/config/chain.go Show resolved Hide resolved
pkg/fetchers/balance.go Show resolved Hide resolved
pkg/tendermint/rpc.go Show resolved Hide resolved
pkg/config/denom_info.go Outdated Show resolved Hide resolved
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 2f23cd7 and 7e4ead6.

Files selected for processing (1)
  • pkg/config/denom_info.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/config/denom_info.go

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 7e4ead6 and e548617.

Files selected for processing (1)
  • pkg/tendermint/rpc.go (25 hunks)
Additional comments not posted (3)
pkg/tendermint/rpc.go (3)

21-27: Refactoring of the RPC struct to accommodate the new configuration structure looks clean and well-integrated.


33-47: The constructor function NewRPC is updated to use the ChainInfo interface, which is a good practice as it decouples the RPC functionality from the concrete Chain struct and adheres to dependency inversion principles.


Line range hint 58-71: Ensure all ChainQueries.Enabled checks are correctly implemented for the respective RPC calls. This is a critical part of the logic to prevent unnecessary API calls when certain features are disabled.

Also applies to: 93-106, 128-144, 167-177, 197-210, 234-250, 275-288, 308-332, 352-363, 382-392, 411-423, 449-459, 478-488

Verification successful

The extracted lines confirm that each ChainQueries.Enabled check is correctly placed before its respective RPC call to prevent unnecessary API calls when certain features are disabled.

  • Lines 55-61: The check for "delegations" is correctly implemented.
  • Lines 93-106, 128-144, 167-177, 197-210, 234-250, 275-288, 308-332, 352-363, 382-392, 411-423, 449-459, 478-488: All other checks for various features are also correctly implemented.

The review comment is verified as correct.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct implementation of ChainQueries.Enabled checks.

# Test: Search for "ChainQueries.Enabled" usage and ensure it matches expected logic.
rg --type go 'ChainQueries.Enabled'

Length of output: 924



Script:

#!/bin/bash
# Extract relevant lines where ChainQueries.Enabled is used in pkg/tendermint/rpc.go
rg --type go --line-number 'ChainQueries.Enabled' pkg/tendermint/rpc.go | cut -d: -f1 | xargs -I {} sed -n '{}p' pkg/tendermint/rpc.go

Length of output: 739



Script:

#!/bin/bash
# Extract lines around each ChainQueries.Enabled check in pkg/tendermint/rpc.go to review the context
rg --type go --line-number 'ChainQueries.Enabled' pkg/tendermint/rpc.go | cut -d: -f1 | xargs -I {} sed -n '{}-2,{}+4p' pkg/tendermint/rpc.go

Length of output: 819



Script:

#!/bin/bash
# Extract lines around each ChainQueries.Enabled check in pkg/tendermint/rpc.go to review the context
rg --type go --line-number 'ChainQueries.Enabled' pkg/tendermint/rpc.go | cut -d: -f1 | xargs -I {} sed -n -e '{}-2,{}+4p' pkg/tendermint/rpc.go

Length of output: 822



Script:

#!/bin/bash
# Extract lines around each ChainQueries.Enabled check in pkg/tendermint/rpc.go to review the context
rg --type go --line-number 'ChainQueries.Enabled' pkg/tendermint/rpc.go | cut -d: -f1 | xargs -I {} sh -c 'sed -n "$(({}-2)),$(({}+4))p" pkg/tendermint/rpc.go'

Length of output: 2656

pkg/tendermint/rpc.go Show resolved Hide resolved
@freak12techno freak12techno merged commit e384ec1 into main Jun 16, 2024
5 checks passed
@freak12techno freak12techno deleted the refactor-consumers-config branch June 16, 2024 09:42
@coderabbitai coderabbitai bot mentioned this pull request Sep 25, 2024
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.

1 participant