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

[Supplier] Deny supplier staking with unknown services #693

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

red-0ne
Copy link
Contributor

@red-0ne red-0ne commented Jul 12, 2024

Summary

Prevent Suppliers from staking with non-existing services.

This PR does not enforce/restrict the Service creation.

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

  • Bug Fixes

    • Fixed issue where staking a supplier with a non-existing service did not return an error.
  • New Features

    • Added service integration with new serviceKeeper and supplierKeeper functionality.
    • Introduced method to send coins from a module to an account in BankKeeper.
  • Improvements

    • Updated GetAllService to GetAllServices for clarity.
    • Enhanced error handling with the new ErrSupplierServiceNotFound error code.
  • Tests

    • Added tests to ensure error handling when staking with non-existing services.

@red-0ne red-0ne added supplier Changes related to the Supplier actor service Anything related to general-purpose RPC service support on-chain On-chain business logic labels Jul 12, 2024
@red-0ne red-0ne self-assigned this Jul 12, 2024
Copy link

coderabbitai bot commented Jul 12, 2024

Walkthrough

This update introduces an extensive set of changes focused on enhancing the service provisioning and staking mechanisms within the system. Key highlights include the addition of a serviceKeeper to various modules, renaming functions for clarity, and adding validation checks for non-existent services. These changes aim to improve the overall modularity, integration, and error handling of the service and supplier modules.

Changes

File Change Summary
config.yml Added a new serviceList item under genesis section.
localnet/poktrolld/config/supplier1_stake_config.yaml Removed the endpoints section under the services field.
testutil/integration/app.go Added serviceKeeper parameter in bankModule and supplierModule constructor calls.
testutil/keeper/proof.go Introduced servicekeeper for service module, modified construction of serviceKeeper and its usage in supplierKeeper.
testutil/keeper/supplier.go Added imports for servicekeeper, created serviceKeeper instance, registered services within SupplierKeeper function.
testutil/keeper/tokenomics.go Added declarations for servicekeeper and servicetypes, created serviceKeeper instance, passed serviceKeeper to supplierKeeper.
x/service/keeper/service.go Renamed GetAllService to GetAllServices.
x/service/keeper/service_test.go Modified test function to call GetAllServices.
x/service/module/genesis.go Updated ExportGenesis function to call GetAllServices.
x/service/types/expected_keepers.go Added SendCoinsFromModuleToAccount to BankKeeper interface.
x/supplier/keeper/keeper.go Added serviceKeeper field to Keeper struct, updated NewKeeper function.
x/supplier/keeper/msg_server_stake_supplier.go Added a check for existing services in StakeSupplier function.
x/supplier/keeper/msg_server_stake_supplier_test.go Added test for staking with non-existent service.
x/supplier/module/module.go Updated AppModule to include serviceKeeper, modified NewAppModule function.
x/supplier/types/errors.go Added ErrSupplierServiceNotFound error.
x/supplier/types/expected_keepers.go Added SpendableCoins to BankKeeper, introduced ServiceKeeper interface.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SupplierModule
    participant ServiceModule
    participant BankKeeper

    User->>SupplierModule: StakeSupplier
    SupplierModule->>ServiceModule: Check if Service Exists
    ServiceModule-->>SupplierModule: Service Exists / Not Found
    alt Service Exists
        SupplierModule->>BankKeeper: Send Coins for Staking
        BankKeeper-->>SupplierModule: Confirm Transaction
        SupplierModule-->>User: Staking Successful
    else Service Not Found
        SupplierModule-->>User: Error: Service Not Found
    end
Loading

Poem

In the land of code, changes unfold,
Keepers and services, stories retold.
With checks and balances, they stake their claim,
Errors caught swiftly, in this modular game.
A rabbit's delight, in this field of tech,
For each line of code, a future to deck.


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bfbfcfe and 20b2947.

Files selected for processing (16)
  • config.yml (1 hunks)
  • localnet/poktrolld/config/supplier1_stake_config.yaml (1 hunks)
  • testutil/integration/app.go (1 hunks)
  • testutil/keeper/proof.go (4 hunks)
  • testutil/keeper/supplier.go (2 hunks)
  • testutil/keeper/tokenomics.go (2 hunks)
  • x/service/keeper/service.go (1 hunks)
  • x/service/keeper/service_test.go (1 hunks)
  • x/service/module/genesis.go (1 hunks)
  • x/service/types/expected_keepers.go (1 hunks)
  • x/supplier/keeper/keeper.go (3 hunks)
  • x/supplier/keeper/msg_server_stake_supplier.go (1 hunks)
  • x/supplier/keeper/msg_server_stake_supplier_test.go (1 hunks)
  • x/supplier/module/module.go (3 hunks)
  • x/supplier/types/errors.go (1 hunks)
  • x/supplier/types/expected_keepers.go (2 hunks)
Files skipped from review due to trivial changes (4)
  • config.yml
  • localnet/poktrolld/config/supplier1_stake_config.yaml
  • x/service/keeper/service.go
  • x/supplier/types/errors.go
Additional comments not posted (27)
x/service/module/genesis.go (1)

27-27: LGTM! The function name is now more grammatically correct.

The change from GetAllService to GetAllServices is appropriate and aligns with best practices.

x/service/types/expected_keepers.go (2)

Line range hint 9-9:
Addition of SpendableCoins method approved.

The SpendableCoins method enhances the functionality of the BankKeeper interface.


Line range hint 25-29:
New ServiceKeeper interface approved.

The addition of the ServiceKeeper interface with the GetService method is appropriate and aligns with the new feature introduced in the PR.

x/supplier/types/expected_keepers.go (2)

21-21: Addition of SpendableCoins method approved.

The SpendableCoins method enhances the functionality of the BankKeeper interface.


26-29: New ServiceKeeper interface approved.

The addition of the ServiceKeeper interface with the GetService method is appropriate and aligns with the new feature introduced in the PR.

x/supplier/keeper/keeper.go (3)

24-25: Addition of serviceKeeper field approved.

The serviceKeeper field enhances the functionality of the Keeper struct.


36-36: Update to NewKeeper function approved.

The NewKeeper function now correctly accepts and initializes the serviceKeeper field.


48-49: Initialization of serviceKeeper field approved.

The serviceKeeper field is correctly initialized in the NewKeeper function.

x/service/keeper/service_test.go (1)

72-72: LGTM! Verify the function usage in the codebase.

The code change is approved.

However, ensure that all function calls to GetAllServices match the new signature.

Verification successful

All instances of the GetAllServices function call match the new signature.

  • x/service/keeper/service_test.go: Verified
  • x/service/module/genesis.go: Verified
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `GetAllServices` match the new signature.

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

Length of output: 1026


Script:

#!/bin/bash
# Description: Verify the context of GetAllServices call in x/service/module/genesis.go

# Fetching the context around the GetAllServices call in genesis.go to verify it matches the new signature
rg --type go -A 5 -B 5 $'GetAllServices' x/service/module/genesis.go

Length of output: 407

testutil/keeper/supplier.go (5)

23-24: LGTM!

The imports for servicekeeper and sharedtypes are correctly added.


47-48: LGTM!

The mock expectation for SpendableCoins is correctly added.


49-55: LGTM!

The serviceKeeper initialization is correctly added.


63-63: LGTM!

The serviceKeeper instance is correctly passed to the Keeper.


71-74: LGTM! Verify the function usage in the codebase.

The services are correctly added for testing.

However, ensure that all function calls to SetService match the new signature.

Verification successful

Verified: All instances of SetService in the codebase match the new signature.

  • testutil/keeper/supplier.go
  • testutil/integration/app.go
  • x/service/module/genesis.go
  • x/service/keeper/msg_server_add_service.go
  • x/service/keeper/service_test.go
  • x/service/keeper/service.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `SetService` match the new signature.

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

Length of output: 2544

x/supplier/keeper/msg_server_stake_supplier.go (1)

30-36: LGTM! Verify the function usage in the codebase.

The new checks for verifying the existence of services before staking are correctly added.

However, ensure that all function calls to GetService match the new signature.

Verification successful

Ensure all function calls to GetService match the new signature.

From the provided output, we can see multiple occurrences of GetService. Here are the critical points to check:

  • Function Definition:
    • x/supplier/types/expected_keepers.go: GetService(ctx context.Context, serviceId string) (sharedtypes.Service, bool)
  • Function Calls:
    • x/supplier/keeper/msg_server_stake_supplier.go: if _, serviceFound := k.serviceKeeper.GetService(ctx, serviceConfig.Service.Id); !serviceFound { ... }
    • x/service/keeper/msg_server_add_service.go: if _, found := k.GetService(ctx, msg.Service.Id); found { ... }
    • x/service/keeper/query_service.go: service, found := k.GetService(ctx, req.Id)
    • x/service/keeper/service_test.go: foundService, found := keeper.GetService(ctx, service.Id)
    • x/service/keeper/service_test.go: _, found := keeper.GetService(ctx, service.Id)
    • x/service/keeper/msg_server_add_service_test.go: serviceFound, found := k.GetService(ctx, preExistingService.Id)
    • x/service/keeper/msg_server_add_service_test.go: serviceFound, found := k.GetService(ctx, test.service.Id)

All the function calls listed above correctly match the new signature GetService(ctx, serviceId string) (sharedtypes.Service, bool).

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `GetService` match the new signature.

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

Length of output: 77998

x/supplier/module/module.go (6)

101-101: LGTM!

The serviceKeeper field is correctly added to the AppModule struct.


109-109: LGTM!

The serviceKeeper parameter is correctly added to the NewAppModule function.


116-116: LGTM!

The serviceKeeper field is correctly initialized in the AppModule struct.


185-185: LGTM!

The serviceKeeper field is correctly added to the ModuleInputs struct.


207-207: LGTM!

The serviceKeeper parameter is correctly passed to the NewKeeper function.


214-214: LGTM! Verify the function usage in the codebase.

The serviceKeeper parameter is correctly passed to the NewAppModule function.

However, ensure that all function calls to NewAppModule match the new signature.

x/supplier/keeper/msg_server_stake_supplier_test.go (1)

238-266: LGTM!

The test function TestMsgServer_StakeSupplier_FailWithNonExistingService correctly tests the scenario of staking a supplier with a non-existing service and ensures that the appropriate error is returned.

testutil/keeper/proof.go (2)

31-31: LGTM!

The added imports for servicekeeper and servicetypes are necessary for the new serviceKeeper functionality.

Also applies to: 41-42


186-194: LGTM!

The creation and integration of the serviceKeeper instance is correctly implemented.

Also applies to: 202-202

testutil/keeper/tokenomics.go (2)

39-40: LGTM!

The added imports for servicekeeper and servicetypes are necessary for the new serviceKeeper functionality.


288-296: LGTM!

The creation and integration of the serviceKeeper instance is correctly implemented.

Also applies to: 304-304

testutil/integration/app.go (1)

341-341: LGTM!

The creation and integration of the serviceKeeper instance in NewCompleteIntegrationApp is correctly implemented.

Also applies to: 348-348

@@ -283,13 +285,23 @@ func NewTokenomicsModuleKeepers(
)
require.NoError(t, appKeeper.SetParams(ctx, apptypes.DefaultParams()))

// Construct a service keeper need by the supplier keeper.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Construct a service keeper need by the supplier keeper.
// Construct a service keeper needed by the supplier keeper.

Copy link

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 693)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Jul 16, 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 20b2947 and e2f42b1.

Files selected for processing (1)
  • testutil/keeper/tokenomics.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • testutil/keeper/tokenomics.go

@red-0ne red-0ne merged commit 4ba2ec3 into main Jul 17, 2024
10 checks passed
bryanchriswhite added a commit that referenced this pull request Jul 17, 2024
…get-hash

* pokt/main:
  [Supplier] Deny supplier staking with unknown services (#693)
  [Documentation] Load Testing on DevNets and TestNets (#637)
bryanchriswhite added a commit that referenced this pull request Jul 17, 2024
…-root

* pokt/main:
  [TODOs] add `EventApplicationOverserviced` event (#669)
  [Supplier] Deny supplier staking with unknown services (#693)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devnet devnet-test-e2e on-chain On-chain business logic push-image CI related - pushes images to ghcr.io service Anything related to general-purpose RPC service support supplier Changes related to the Supplier actor
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants