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

[Relay Mining] Use per-service difficulty in the relayer #745

Merged
merged 40 commits into from
Sep 5, 2024

Conversation

adshmh
Copy link
Contributor

@adshmh adshmh commented Aug 19, 2024

Summary

  • Relayer is updated to query the tokenmoics module to get the relay difficulty target hash specific to the service corresponding to the relay. This is used to determine if a relay is volume applicable.

  • Relayer is updated to query the service module to get the compute units per relay specific to the service corresponding to the relay. This is used as the weight of the relay when updating the Relayer's SMT for the session corresponding to the relay.

  • Claims are validated at the time of submission to ensure the total claimed compute units is equal to the number of relays multiplied by the compute units per relay for the corresponding service.

  • All [Relay Mining] Maintain per service difficulty on the relayer #705 references in the code have been addressed.

  • Relay test fixture generator has been updated to use the difficulty threshold hash to be consistent with how the relayer now operates.

Issue

UPNEXT

  • Remove the relay_difficulty_target_hash parameter
  • Addressing any remaining instances of TODO_FOLLOWUP(@olshansk, #690)

These have been skipped to: 1) align on the PR before making further changes and 2) restrict the PR size and scope, as these were not strictly required for the above enhancements to function.

Depending on the review results, I can add commits to address the above in this PR as well.

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

    • Added new interfaces for querying tokenomics data, enhancing the app's ability to handle tokenomics-related queries.
    • Introduced a structured approach to query service information and tokenomics data, improving the overall querying functionality.
    • Implemented functionality to retrieve compute units per relay for services, optimizing session management.
  • Bug Fixes

    • Improved error handling for service retrieval and compute units mismatch scenarios.
  • Tests

    • Enhanced test coverage for tokenomics and service querying functionalities, ensuring robust testing of new features.
  • Chores

    • Updated test utilities and dependencies to support new service management capabilities.

@adshmh adshmh added the enhancement New feature or request label Aug 19, 2024
@adshmh adshmh added this to the Shannon MainNet milestone Aug 19, 2024
@adshmh adshmh self-assigned this Aug 19, 2024
Copy link

coderabbitai bot commented Aug 19, 2024

Walkthrough

This update introduces significant enhancements across multiple components of the system, focusing on improved service management, tokenomics querying, and error handling. Key additions include new interfaces and query clients for tokenomics, refined miner functionalities, and robust testing infrastructure. The changes streamline data retrieval processes and enhance the application's capability to handle service-related computations, contributing to a more modular and maintainable codebase.

Changes

Files Change Summary
pkg/client/interface.go, pkg/client/query/errors.go, pkg/client/query/servicequerier.go, pkg/client/query/tokenomicsquerier.go Added new interfaces for tokenomics, modified proof parameters, and enhanced querying capabilities with new clients.
pkg/deps/config/suppliers.go, pkg/relayer/cmd/cmd.go Introduced new functions for dependency injection to include tokenomics and service querying clients in the relayer setup.
pkg/relayer/miner/gen/gen_fixtures.go, pkg/relayer/miner/gen/template.go, pkg/relayer/miner/miner.go, pkg/relayer/miner/miner_test.go, pkg/relayer/miner/relay_fixtures_test.go Significant updates to relay fixture generation logic, including changes to difficulty assessment and testing enhancements for miners.
pkg/relayer/session/service.go, pkg/relayer/session/session.go, pkg/relayer/session/session_test.go Introduced service querying capabilities to manage compute units per relay, improving session management.
testutil/integration/app.go, testutil/keeper/proof.go, testutil/keeper/tokenomics.go Enhanced integration app and keeper functionalities to manage new service-related logic.
testutil/testclient/testqueryclients/servicequerier.go, testutil/testclient/testqueryclients/tokenomicsquerier.go Created mock implementations for testing service query clients and tokenomics for improved test coverage.
x/proof/keeper/keeper.go, x/proof/keeper/msg_server_create_claim.go, x/proof/keeper/service.go, x/proof/module/module.go, x/proof/types/errors.go, x/proof/types/expected_keepers.go Added new service management capabilities, updated error handling for claims, and enhanced keeper functionalities.

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

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

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: 1

Outside diff range, codebase verification and nitpick comments (1)
testutil/testclient/testqueryclients/tokenomicsquerier.go (1)

18-22: Ensure thread-safe access to relayDifficultyTargets.

The relayDifficultyTargets map is accessed without any synchronization mechanisms, which could lead to race conditions if accessed concurrently. Consider using a sync.Mutex or sync.RWMutex to protect access to this map.

  • File: testutil/testclient/testqueryclients/tokenomicsquerier.go
  • Lines: Access operations on relayDifficultyTargets (e.g., lines involving relayDifficultyTargets[serviceId]).
Analysis chain

Initialize relayDifficultyTargets safely.

The relayDifficultyTargets map is initialized in the init function. Ensure that this map is thread-safe if accessed concurrently in tests, possibly by using sync mechanisms if needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for concurrent access to `relayDifficultyTargets`.

# Test: Search for concurrent access patterns. Expect: Safe access patterns or synchronization mechanisms.
rg --type go 'relayDifficultyTargets'

Length of output: 799

pkg/relayer/session/session_test.go Outdated Show resolved Hide resolved
@Olshansk Olshansk added relayminer Changes related to the Relayminer on-chain On-chain business logic labels Aug 19, 2024
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

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

Nice one @adshmh! 🔥

pkg/relayer/miner/gen/gen_fixtures.go Outdated Show resolved Hide resolved
pkg/relayer/miner/gen/gen_fixtures.go Outdated Show resolved Hide resolved
pkg/relayer/miner/gen/gen_fixtures.go Outdated Show resolved Hide resolved
pkg/relayer/miner/gen/gen_fixtures.go Show resolved Hide resolved
pkg/relayer/miner/gen/gen_fixtures.go Outdated Show resolved Hide resolved
x/proof/keeper/msg_server_create_claim_test.go Outdated Show resolved Hide resolved
x/proof/keeper/msg_server_create_claim_test.go Outdated Show resolved Hide resolved
…-service' into feat-relay-mining-difficulty-per-service
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

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

🚀

Makefile Show resolved Hide resolved
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

@adshmh Great job. This was squeaky clean!

Doing a preliminary approval but just make sure to:

  1. See my suggestions on comments & tests
  2. I left a couple questions that may need a TODO added
  3. After (1) & (2), make sure to run E2E tests by adding the devnet-test-e2e and running make trigger_ci after like ten seconds
  4. Feel free to merge after if everything is 🟢

Makefile Show resolved Hide resolved
pkg/deps/config/suppliers.go Show resolved Hide resolved
pkg/relayer/session/session_test.go Outdated Show resolved Hide resolved
pkg/relayer/session/session.go Show resolved Hide resolved
x/proof/keeper/msg_server_create_claim.go Outdated Show resolved Hide resolved
x/proof/keeper/msg_server_create_claim_test.go Outdated Show resolved Hide resolved
x/proof/keeper/msg_server_create_claim_test.go Outdated Show resolved Hide resolved
x/proof/keeper/msg_server_create_claim.go Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Sep 3, 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 745)
Grafana network dashboard for devnet-issue-745

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Sep 3, 2024
@adshmh adshmh merged commit 1556a8f into main Sep 5, 2024
10 checks passed
bryanchriswhite added a commit that referenced this pull request Sep 5, 2024
…ke-transfer

* pokt/main:
  [Relay Mining] Use per-service difficulty in the relayer (#745)
  [Tilt] Enable rest service by default in Tilt (#793)
  [Docs] Minor doc updates across the board (#792)
  build(deps): bump webpack from 5.89.0 to 5.94.0 in /docusaurus (#775)
  [Docs] Tokenomics Documentation (#750)
  fix: ensure stable_marshaler_all option on all proto files (#772)
  build(deps): bump micromatch from 4.0.5 to 4.0.8 in /docusaurus (#774)
  [Tooling] Add `protocheck` CLI tool (#770)
  Update `adding_params.md` to use `ignite` (#764)
  [Docs] Cleanup & Deprecation (#766)
bryanchriswhite added a commit that referenced this pull request Sep 5, 2024
…actor/transfer-msg_period-param

* issues/657/feat/app-stake-transfer:
  chore: regenerate protobufs
  [Relay Mining] Use per-service difficulty in the relayer (#745)
  [Tilt] Enable rest service by default in Tilt (#793)
  [Docs] Minor doc updates across the board (#792)
  build(deps): bump webpack from 5.89.0 to 5.94.0 in /docusaurus (#775)
  [Docs] Tokenomics Documentation (#750)
  fix: ensure stable_marshaler_all option on all proto files (#772)
  build(deps): bump micromatch from 4.0.5 to 4.0.8 in /docusaurus (#774)
  [Tooling] Add `protocheck` CLI tool (#770)
  Update `adding_params.md` to use `ignite` (#764)
  [Docs] Cleanup & Deprecation (#766)
bryanchriswhite added a commit that referenced this pull request Sep 5, 2024
…ues/657/chore/app-transfer-period

* issues/657/refactor/transfer-msg_period-param:
  chore: regenerate protobufs
  chore: regenerate protobufs
  fix: failing test
  chore: regenerate protobufs
  Revert "refactor: rename param to application_transfer_and_unboding_period_sessions"
  [Relay Mining] Use per-service difficulty in the relayer (#745)
  [Tilt] Enable rest service by default in Tilt (#793)
  [Docs] Minor doc updates across the board (#792)
  build(deps): bump webpack from 5.89.0 to 5.94.0 in /docusaurus (#775)
  [Docs] Tokenomics Documentation (#750)
  fix: ensure stable_marshaler_all option on all proto files (#772)
  build(deps): bump micromatch from 4.0.5 to 4.0.8 in /docusaurus (#774)
  [Tooling] Add `protocheck` CLI tool (#770)
  Update `adding_params.md` to use `ignite` (#764)
  [Docs] Cleanup & Deprecation (#766)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devnet devnet-test-e2e enhancement New feature or request on-chain On-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.

3 participants