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

[Relayminer] refactor: query min_relay_difficulty_bits param #655

Merged
merged 10 commits into from
Jul 5, 2024

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jul 4, 2024

Summary

Refactors the relayminer to query for the min_relay_difficulty_bits from on-chain.

Issue

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

Documentation changes (only if making doc changes)

  • make docusaurus_start; only needed if you make doc changes

Local Testing (only if making code changes)

  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • See quickstart guide for instructions

PR Testing (only if making code changes)

  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.
    • THIS IS VERY EXPENSIVE, so only do it after all the reviews are complete.
    • Optionally run make trigger_ci if you want to re-trigger tests without any code changes
    • If tests fail, try re-running failed tests only using the GitHub UI as shown here

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

Summary by CodeRabbit

  • New Features

    • Introduced a new interface and client for querying on-chain proof module parameters.
    • Added dependency injection for proof query clients to enhance modularity and testing.
  • Improvements

    • Updated miner struct to dynamically fetch and set relay difficulty bits from on-chain parameters.
    • Enhanced NewMiner function to include dependency injection for greater flexibility.
  • Bug Fixes

    • Fixed type mismatch in relay difficulty comparison to ensure accurate mining operations.
  • Tests

    • Added mock clients for proof query testing to improve test coverage and reliability.

@bryanchriswhite bryanchriswhite added relayminer Changes related to the Relayminer off-chain Off-chain business logic code health Cleans up some code push-image CI related - pushes images to ghcr.io devnet-test-e2e labels Jul 4, 2024
@bryanchriswhite bryanchriswhite self-assigned this Jul 4, 2024
Copy link

coderabbitai bot commented Jul 4, 2024

Walkthrough

The update integrates a new querying interface for on-chain proof module parameters, adjusts the mining logic to use this new interface, and updates dependency injections accordingly. The changes ensure relay difficulty bits are fetched and compared as uint64, improving type safety.

Changes

File / Grouping Summary
pkg/client/interface.go Added ProofQueryClient and ProofParams interfaces.
pkg/client/query/proofquerier.go Introduced proofQuerier struct and methods for on-chain proof querying.
pkg/deps/config/suppliers.go Added a function to supply the ProofQueryClient dependency.
pkg/relayer/cmd/cmd.go Introduced dependency injection for ProofQueryClient in miner creation.
pkg/relayer/miner/miner.go Updated mining logic to include proofQueryClient and adjust relay difficulty comparison to uint64.
pkg/relayer/miner/miner_test.go Added mock client and adjusted tests for uint64 relay difficulty bits.
pkg/relayer/miner/options.go Changed WithDifficulty function to accept uint64.
testutil/testclient/testqueryclients/proofquerier.go Created mock ProofQueryClient for testing.
x/proof/types/params.go Demonstrated interface implementation for ProofParams.

Sequence Diagram(s)

sequenceDiagram
    participant Application
    participant ProofQueryClient
    participant Blockchain
    
    Application->>ProofQueryClient: GetParams(ctx)
    ProofQueryClient->>Blockchain: Query proof module params
    Blockchain-->>ProofQueryClient: Return params
    ProofQueryClient-->>Application: Return proof module params
Loading

Poem

In fields of code, where bytes do play,
A rabbit hops, with joy today.
Proofs and queries, all aligned,
Mining's path, now well-defined.
🎉✨ The Blockchain sings, in pure delight,
As relays mine through day and night!
🐇💻 Keep hopping, coder bright!


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

github-actions bot commented Jul 4, 2024

The image is going to be pushed after the next commit.

You can use make trigger_ci to push an empty commit.

If you also want to run E2E tests, please add devnet-test-e2e label.

Copy link

github-actions bot commented Jul 4, 2024

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 655)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added the devnet label Jul 4, 2024
@bryanchriswhite bryanchriswhite linked an issue Jul 4, 2024 that may be closed by this pull request
15 tasks
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 4, 2024 10:24
Copy link

@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 ebac0ae and 41c7219.

Files selected for processing (9)
  • pkg/client/interface.go (3 hunks)
  • pkg/client/query/proofquerier.go (1 hunks)
  • pkg/deps/config/suppliers.go (1 hunks)
  • pkg/relayer/cmd/cmd.go (2 hunks)
  • pkg/relayer/miner/miner.go (4 hunks)
  • pkg/relayer/miner/miner_test.go (2 hunks)
  • pkg/relayer/miner/options.go (1 hunks)
  • testutil/testclient/testqueryclients/proofquerier.go (1 hunks)
  • x/proof/types/params.go (1 hunks)
Additional comments not posted (15)
pkg/relayer/miner/options.go (1)

7-7: Function parameter type change: Ensure consistency.

The parameter type for WithDifficulty has been changed from int to uint64. Ensure that all calls to WithDifficulty and related functions handle uint64 correctly.

Verification successful

Function parameter type change: Verification successful.

The parameter type for WithDifficulty has been changed to uint64, and all calls to this function handle the uint64 type correctly.

  • testDifficulty is defined as uint64 in pkg/relayer/miner/miner_test.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `WithDifficulty` handle `uint64` correctly.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'WithDifficulty'

Length of output: 386


Script:

#!/bin/bash
# Search for the definition and type of `testDifficulty` in `pkg/relayer/miner/miner_test.go`
rg 'testDifficulty' pkg/relayer/miner/miner_test.go

Length of output: 230

testutil/testclient/testqueryclients/proofquerier.go (1)

1-24: Ensure mock behavior correctness.

The function NewTestProofQueryClient creates a mock ProofQueryClient with default proof module parameters. Ensure that the mock behavior is consistent with the expected usage in tests.

Verification successful

Mock behavior is consistent with test usage.

The NewTestProofQueryClient function creates a mock ProofQueryClient with default proof module parameters, and its usage in the TestMiner_MinedRelays test is consistent with this behavior.

  • The GetParams method of the mock client is set up to return default proof parameters.
  • The test involves creating a Miner instance with the mock client, which likely uses the GetParams method internally.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewTestProofQueryClient` in tests.

# Test: Search for the function usage. Expect: Consistent mock behavior.
rg --type go $'NewTestProofQueryClient'

Length of output: 404


Script:

#!/bin/bash
# Extract relevant portions of the file where NewTestProofQueryClient is used.
rg -A 10 -B 10 'NewTestProofQueryClient' pkg/relayer/miner/miner_test.go

Length of output: 973


Script:

#!/bin/bash
# Extract more lines from the file to see the complete usage and expectations around proofQueryClientMock.
rg -A 50 -B 10 'NewTestProofQueryClient' pkg/relayer/miner/miner_test.go

Length of output: 2299

pkg/client/query/proofquerier.go (1)

1-50: Ensure correct dependency injection and error handling.

The NewProofQuerier function injects dependencies using depinject.Config and initializes the proofQuerier struct. Ensure that all required dependencies are correctly injected and error handling is robust.

Verification successful

Dependency injection and error handling are correctly implemented.

The NewProofQuerier function is used in NewSupplyProofQueryClientFn within pkg/deps/config/suppliers.go. The dependency injection and error handling are correctly managed, ensuring robust functionality.

  • pkg/deps/config/suppliers.go: The function NewSupplyProofQueryClientFn correctly handles errors and injects dependencies.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewProofQuerier` and ensure correct dependency injection.

# Test: Search for the function usage. Expect: Correct dependency injection and error handling.
rg --type go $'NewProofQuerier'

Length of output: 329


Script:

#!/bin/bash
# Extract the context around the usage of NewProofQuerier in suppliers.go to inspect dependency injection and error handling.
rg --type go -A 10 -B 10 'NewProofQuerier' pkg/deps/config/suppliers.go

Length of output: 721

pkg/relayer/miner/miner_test.go (1)

15-21: Ensure correct dependency injection in tests.

The TestMiner_MinedRelays function now includes dependency injection for a proof query client. Ensure that the dependency injection is correctly implemented and consistent with the rest of the codebase.

Verification successful

Ensure correct dependency injection in tests.

The TestMiner_MinedRelays function in pkg/relayer/miner/miner_test.go correctly uses depinject.Supply for dependency injection, ensuring consistency with the rest of the codebase.

  • pkg/relayer/miner/miner_test.go: Verified the usage of depinject.Supply for dependency injection.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of dependency injection in tests.

# Test: Search for the usage of `depinject.Supply` and ensure correctness.
rg --type go $'depinject.Supply'

Length of output: 5627

pkg/relayer/miner/miner.go (5)

6-8: Imports look good.

The new imports are necessary for dependency injection and the new proof query client.


34-35: New field proofQueryClient looks good.

The new field is necessary to incorporate the proof query client into the miner struct.


51-66: Changes in NewMiner function look good.

The changes are necessary to inject the new proof query client into the miner struct.


96-106: Changes in setDefaults function look good.

The changes are necessary to fetch the default relay difficulty bits from the proof query client.


128-128: Changes in mapMineRelay function look good.

The changes are necessary to handle the new uint64 type for relay difficulty bits.

x/proof/types/params.go (1)

9-13: New import and interface implementation declaration look good.

The new import and declaration are necessary to implement the ProofParams interface.

pkg/relayer/cmd/cmd.go (2)

198-198: New function call to config.NewSupplyProofQueryClientFn() looks good.

The new function call is necessary to supply the proof query client.


221-221: Changes in supplyMiner function look good.

The changes are necessary to create a new miner with the supplied dependencies.

pkg/deps/config/suppliers.go (1)

449-465: New function NewSupplyProofQueryClientFn looks good.

The new function is necessary to create and supply a proof query client.

pkg/client/interface.go (2)

318-326: LGTM!

The ProofParams interface is well-defined and consistent with the existing codebase.


328-333: LGTM!

The ProofQueryClient interface is consistent with the existing codebase and provides necessary functionality for querying proof module parameters.

Copy link

@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 41c7219 and 3e574bd.

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

@bryanchriswhite bryanchriswhite changed the title Issues/584/refactor/miner query params [Relayminer] refactor: miner queries for on-chain min_relay_difficulty_bits param Jul 4, 2024
@bryanchriswhite bryanchriswhite changed the title [Relayminer] refactor: miner queries for on-chain min_relay_difficulty_bits param [Relayminer] refactor: query min_relay_difficulty_bits param Jul 4, 2024
Copy link

@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 3e574bd and 2e9ad57.

Files selected for processing (1)
  • pkg/relayer/miner/miner.go (4 hunks)
Additional comments not posted (4)
pkg/relayer/miner/miner.go (4)

25-30: LGTM! New fields added to miner struct.

The fields proofQueryClient and relayDifficultyBits are correctly added with appropriate comments.


42-57: LGTM! Dependency injection and defaults setting in NewMiner function.

The proofQueryClient dependency is correctly injected, and the setDefaults method is called to ensure proper configuration.


87-97: LGTM! Fetching parameters and setting defaults in setDefaults method.

The setDefaults method correctly fetches parameters from proofQueryClient and sets relayDifficultyBits if it is not already set.


119-119: LGTM! Updated difficulty comparison in mapMineRelay method.

The comparison logic is correctly updated to handle uint64 values.

Copy link

@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 2e9ad57 and 7ce8558.

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


// ProofParams is a go interface type which corresponds to the poktroll.proof.Params
// protobuf message. Since the generated go types don't include interface types, this
// is necessary to prevent dependency cycles.
Copy link
Member

Choose a reason for hiding this comment

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

#PUC what the dependency cycle is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this will need to become its own issue where we evaluate potential solutions. There are potential dependency cycles looming in pkg/client due to the importing of concrete module types. In this case, we were trying to import x/proof/types for the Params type but that package imports pkg/client for some querier interface types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pkg/client/interface.go Show resolved Hide resolved
@bryanchriswhite bryanchriswhite merged commit e119984 into main Jul 5, 2024
10 checks passed
bryanchriswhite added a commit that referenced this pull request Jul 6, 2024
…bility

* pokt/main:
  [Relayminer] refactor: query `min_relay_difficulty_bits` param (#655)
  [Docs] Claim expiration (#649)
  [LoadTest] Passing non-existing plans variable (#661)
bryanchriswhite added a commit that referenced this pull request Jul 6, 2024
…lays

* pokt/main:
  [Docs] Update observability docusaurus & godocs (#654)
  [Relayminer] refactor: query `min_relay_difficulty_bits` param (#655)
  [Docs] Claim expiration (#649)
  [LoadTest] Passing non-existing plans variable (#661)
bryanchriswhite added a commit that referenced this pull request Jul 6, 2024
…elayer-session-manager

* issues/553/fix/replay-observable:
  chore: go imports
  chore: update comment
  chore: update comment
  chore: review feedback improvements
  [Relayminer] refactor: query `min_relay_difficulty_bits` param (#655)
  [Docs] Claim expiration (#649)
  [LoadTest] Passing non-existing plans variable (#661)
  Tiny: updating labels in tiltfile
  [Load Testing] fix: relay stress test duration calculation (#651)
  [LocalNet] Grafana stress test dashboard changes (#641)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Cleans up some code devnet devnet-test-e2e off-chain Off-chain business logic push-image CI related - pushes images to ghcr.io relayminer Changes related to the Relayminer
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[TODO] @Olshansk's (and now @Bryan's) Blocker TODOs
2 participants