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 consumer commission #69

Merged
merged 2 commits into from
Jun 27, 2024
Merged

Conversation

freak12techno
Copy link
Collaborator

@freak12techno freak12techno commented Jun 27, 2024

Summary by CodeRabbit

  • New Features

    • Introduced consumer commission data fetching and handling.
    • Added functionality for generating validator commission rates.
  • Bug Fixes

    • Adjusted test cases to match updated generator output.
  • Refactor

    • Removed commissionGauge metric from validator info generator.
  • Tests

    • Added comprehensive tests for consumer commission fetcher and validator commission rate generator.
  • Chores

    • Updated JSON configuration to include consumer commission rate.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The update introduces functionalities to handle consumer commission data for validators. It adds new fetchers and generators, enhances configuration constants, and modifies Tendermint RPC interactions. Additionally, tests for both fetchers and generators ensure the new processes work correctly. A new JSON file sets a default commission rate. The update refines existing functionalities by removing unnecessary metrics and adjusts suitable test expectations accordingly.

Changes

File/Path Summary
assets/consumer-commission.json Introduces a key-value pair defining a commission rate of 0.1.
pkg/app.go Adds fetchers and generators for handling consumer commission and validator commission rate, respectively.
pkg/constants/constants.go Adds constant FetcherNameConsumerCommission.
pkg/fetchers/consumer_commission.go Introduces ConsumerCommissionFetcher struct and related methods for fetching commission data.
pkg/fetchers/consumer_commission_test.go Adds test functions for ConsumerCommissionFetcher.
pkg/generators/single_validator_info.go Removes commissionGauge metric from SingleValidatorInfoGenerator.
pkg/generators/single_validator_info_test.go Updates expected results length and indexing in tests.
pkg/generators/validator_commission_rate.go Introduces ValidatorCommissionRateGenerator struct and related methods.
pkg/generators/validator_commission_rate_test.go Adds test functions for ValidatorCommissionRateGenerator.
pkg/tendermint/rpc.go Adds GetConsumerCommission method to RPC struct.
pkg/types/tendermint.go Adds ConsumerCommissionResponse type.

Sequence Diagram(s)

Below is the sequence diagram representing the interaction between fetching and generating consumer commission rates:

sequenceDiagram
    participant App as App
    participant Fetcher as ConsumerCommissionFetcher
    participant Generator as ValidatorCommissionRateGenerator
    participant RPC as Tendermint RPC
    participant State as State

    App->>Fetcher: NewConsumerCommissionFetcher(logger, appConfig.Chains, rpcs, tracer)
    Fetcher->>RPC: fetchConsumerCommission(valcons, chainID)
    RPC-->>Fetcher: ConsumerCommissionResponse
    
    App->>Generator: NewValidatorCommissionRateGenerator(appConfig.Chains, logger)
    Generator->>State: Generate(state)
    State-->>Generator: Commission rates data
    Generator-->>App: Prometheus metrics
Loading

Poem

In the digital meadow, data flows with grace,
Fetching commissions from each validator's place.
With new generators, metrics shine anew,
Reflecting rates in a dashboard view.
Through code we weave a structured scene,
Validators' work now clear and clean.
Hopping forward, we build and dream! 🌟🐇


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

codecov bot commented Jun 27, 2024

Codecov Report

Attention: Patch coverage is 98.29060% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.01%. Comparing base (95d607b) to head (407edd0).

Files Patch % Lines
pkg/app.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #69      +/-   ##
==========================================
+ Coverage   90.71%   91.01%   +0.30%     
==========================================
  Files          61       63       +2     
  Lines        2455     2560     +105     
==========================================
+ Hits         2227     2330     +103     
- Misses        227      229       +2     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 95d607b and 407edd0.

Files selected for processing (11)
  • assets/consumer-commission.json (1 hunks)
  • pkg/app.go (2 hunks)
  • pkg/constants/constants.go (1 hunks)
  • pkg/fetchers/consumer_commission.go (1 hunks)
  • pkg/fetchers/consumer_commission_test.go (1 hunks)
  • pkg/generators/single_validator_info.go (3 hunks)
  • pkg/generators/single_validator_info_test.go (3 hunks)
  • pkg/generators/validator_commission_rate.go (1 hunks)
  • pkg/generators/validator_commission_rate_test.go (1 hunks)
  • pkg/tendermint/rpc.go (1 hunks)
  • pkg/types/tendermint.go (1 hunks)
Files not reviewed due to errors (1)
  • pkg/generators/validator_commission_rate_test.go (no review received)
Files skipped from review due to trivial changes (4)
  • assets/consumer-commission.json
  • pkg/constants/constants.go
  • pkg/generators/single_validator_info.go
  • pkg/generators/single_validator_info_test.go
Additional context used
Learnings (3)
pkg/fetchers/consumer_commission.go (2)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_info.go:34-40
Timestamp: 2024-06-23T11:24:17.378Z
Learning: User freak12techno plans to add unit tests for the `NewConsumerInfoFetcher` constructor later.
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_validators.go:40-40
Timestamp: 2024-06-23T16:11:23.143Z
Learning: The `TestConsumerValidatorsFetcherBase` method in `pkg/fetchers/consumer_validators_test.go` tests the initialization of `ConsumerValidatorsFetcher` with the `Chains` parameter.
pkg/app.go (1)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#57
File: pkg/app.go:86-86
Timestamp: 2024-06-16T10:28:15.556Z
Learning: The `fetchers` array in `pkg/app.go` is iteratively processed, and each fetcher's `Fetch` method is invoked, confirming that all fetchers, including `ConsumerValidatorsFetcher`, are actively used to fetch data.
pkg/fetchers/consumer_commission_test.go (2)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_validators.go:40-40
Timestamp: 2024-06-23T16:11:23.143Z
Learning: The `TestConsumerValidatorsFetcherBase` method in `pkg/fetchers/consumer_validators_test.go` tests the initialization of `ConsumerValidatorsFetcher` with the `Chains` parameter.
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_info.go:34-40
Timestamp: 2024-06-23T11:24:17.378Z
Learning: User freak12techno plans to add unit tests for the `NewConsumerInfoFetcher` constructor later.
GitHub Check: codecov/patch
pkg/app.go

[warning] 99-99: pkg/app.go#L99
Added line #L99 was not covered by tests


[warning] 124-124: pkg/app.go#L124
Added line #L124 was not covered by tests

Additional comments not posted (13)
pkg/fetchers/consumer_commission.go (3)

15-26: Struct Definition: ConsumerCommissionFetcher

This struct is well-defined with appropriate fields for handling consumer commission data. However, consider documenting the purpose of each field for better maintainability.


32-44: Constructor Function: NewConsumerCommissionFetcher

The constructor function is correctly implemented. It properly initializes the ConsumerCommissionFetcher struct with the provided arguments. Adding a comment describing the function could improve code readability.


78-80: Method: Name

This simple getter method is correctly implemented and returns the appropriate constant for the fetcher name. No issues here.

pkg/generators/validator_commission_rate.go (2)

16-19: Struct Definition: ValidatorCommissionRateGenerator

The struct is minimal and appropriate for its intended use. However, adding documentation for the struct and its fields would improve code clarity and maintainability.


21-28: Constructor Function: NewValidatorCommissionRateGenerator

The constructor is straightforward and correctly initializes the struct. It uses fluent logging which is good for adding more context-specific information in logs. Consider adding a brief comment to describe the constructor's purpose.

pkg/types/tendermint.go (1)

198-201: New Type: ConsumerCommissionResponse

The ConsumerCommissionResponse type is well-defined with appropriate JSON tags. It includes fields for code and rate, which are essential for handling commission data. No issues found here.

pkg/fetchers/consumer_commission_test.go (6)

19-49: Basic test setup and assertions look good.

The test function TestConsumerCommissionFetcherBase properly initializes the fetcher and checks its integrity and correct naming, which aligns well with the expected functionality.


51-91: Test logic and setup for missing consensus address are appropriate.

The function TestConsumerCommissionFetcherNoConsensusAddress correctly simulates a scenario with no consensus address and validates that no data is returned, which is expected behavior.


93-135: Test setup for disabled query scenario is correctly implemented.

The function TestConsumerCommissionFetcherQueryDisabled accurately tests the behavior when the consumer commission query is disabled, ensuring no data is fetched or processed.


137-187: Error handling in the test is robust and well-simulated.

The function TestConsumerCommissionFetcherQueryError effectively uses httpmock to simulate an API error and checks that the fetcher handles this scenario correctly by not processing any data.


189-239: Node error simulation and handling are effectively tested.

The function TestConsumerCommissionFetcherNodeError correctly simulates a node error using a predefined JSON response and validates that the fetcher handles this error scenario properly.


241-296: Successful query handling is thoroughly tested.

The function TestConsumerCommissionFetcherQuerySuccess effectively simulates a successful API response and ensures that the fetcher processes and stores the data correctly, adhering to the expected outcomes.

pkg/tendermint/rpc.go (1)

593-622: Implementation of GetConsumerCommission is consistent and well-structured.

The method GetConsumerCommission is implemented consistently with other RPC methods. It properly handles the enabled state check, error handling, and response parsing.

Verification successful

Integration of GetConsumerCommission is correctly handled.

The method GetConsumerCommission is properly integrated within the processChain method of ConsumerCommissionFetcher. The results are handled correctly, with appropriate error logging and data storage.

  • pkg/fetchers/consumer_commission.go: processChain method
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of `GetConsumerCommission` with other components.

# Test: Search for the method usage. Expect: Proper integration with other components.
rg --type go $'GetConsumerCommission'

Length of output: 238



Script:

#!/bin/bash
# Description: Extract the context of `GetConsumerCommission` usage in `pkg/fetchers/consumer_commission.go`.

# Display lines around the usage of GetConsumerCommission to understand its context.
rg --type go --context 10 'GetConsumerCommission' pkg/fetchers/consumer_commission.go

Length of output: 525



Script:

#!/bin/bash
# Description: Extract the full implementation of the `processChain` method in `pkg/fetchers/consumer_commission.go`.

# Display the full implementation of the processChain method to understand its context.
ast-grep --lang go --pattern 'func (f *ConsumerCommissionFetcher) processChain($_, $_, $_, $_) {
  $$$
}' pkg/fetchers/consumer_commission.go

Length of output: 1904

pkg/fetchers/consumer_commission.go Show resolved Hide resolved
pkg/fetchers/consumer_commission.go Show resolved Hide resolved
pkg/generators/validator_commission_rate.go Show resolved Hide resolved
pkg/app.go Show resolved Hide resolved
@@ -96,6 +96,7 @@
fetchersPkg.NewNodeInfoFetcher(logger, appConfig.Chains, rpcs, tracer),
fetchersPkg.NewConsumerInfoFetcher(logger, appConfig.Chains, rpcs, tracer),
fetchersPkg.NewValidatorConsumersFetcher(logger, appConfig.Chains, rpcs, tracer),
fetchersPkg.NewConsumerCommissionFetcher(logger, appConfig.Chains, rpcs, tracer),
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 27, 2024

Choose a reason for hiding this comment

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

Addition of New Fetcher: ConsumerCommissionFetcher

The new fetcher for consumer commissions is correctly added to the list of fetchers. However, this line was not covered by tests according to the static analysis tool.

+ fetchersPkg.NewConsumerCommissionFetcher(logger, appConfig.Chains, rpcs, tracer),

Consider adding unit tests to ensure this fetcher is initialized correctly and functions as expected.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fetchersPkg.NewConsumerCommissionFetcher(logger, appConfig.Chains, rpcs, tracer),
fetchersPkg.NewConsumerCommissionFetcher(logger, appConfig.Chains, rpcs, tracer),
Tools
GitHub Check: codecov/patch

[warning] 99-99: pkg/app.go#L99
Added line #L99 was not covered by tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will add tests for app.go later

Copy link
Contributor

Choose a reason for hiding this comment

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

@freak12techno, understood! If you need any assistance when adding those tests later, feel free to reach out. Looking forward to seeing the updates!


Learnings used
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#64
File: pkg/app.go:105-112
Timestamp: 2024-06-25T19:32:53.262Z
Learning: User freak12techno has clarified that while specific tests for new generator functions in `app.go` exist, there is an overall lack of tests for `app.go` itself, which is currently expected and accepted.

User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_info.go:34-40
Timestamp: 2024-06-23T11:24:17.378Z
Learning: User freak12techno plans to add unit tests for the `NewConsumerInfoFetcher` constructor later.

User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/validators.go:28-34
Timestamp: 2024-06-23T11:24:50.154Z
Learning: The constructor function `NewValidatorsFetcher` in `pkg/fetchers/validators.go` is now covered by tests in `validators_test.go`.

User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/soft_opt_out_threshold.go:28-34
Timestamp: 2024-06-23T11:25:06.862Z
Learning: The `NewSoftOptOutThresholdFetcher` constructor function in `pkg/fetchers/soft_opt_out_threshold.go` is now covered by tests as verified by the presence of its usage in `pkg/fetchers/soft_opt_out_threshold_test.go`.

User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#57
File: pkg/app.go:86-86
Timestamp: 2024-06-16T10:28:15.556Z
Learning: The `fetchers` array in `pkg/app.go` is iteratively processed, and each fetcher's `Fetch` method is invoked, confirming that all fetchers, including `ConsumerValidatorsFetcher`, are actively used to fetch data.

User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_validators.go:40-40
Timestamp: 2024-06-23T16:11:23.143Z
Learning: The `TestConsumerValidatorsFetcherBase` method in `pkg/fetchers/consumer_validators_test.go` tests the initialization of `ConsumerValidatorsFetcher` with the `Chains` parameter.

@freak12techno freak12techno merged commit 560faca into main Jun 27, 2024
8 checks passed
@freak12techno freak12techno deleted the add-consumer-commission branch June 27, 2024 22:35
@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