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

[On-chain, Relayminer] chore: add claim msg validation #236

Merged
merged 38 commits into from
Dec 7, 2023

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Nov 29, 2023

Summary

Human Summary

Adds validation logic around the claim's session during claim creation. The session ID must match that as determined by an on-chain query of the session given the same inputs. Additionally, the supplier list for the session must contain the supplier whose address is referenced in the claim.

AI Summary

Summary generated by Reviewpad on 07 Dec 23 10:58 UTC

This pull request includes various changes across multiple files. Here is a summary of the changes:

  • supplier.go (in testutil/keeper package):

    • Added imports for supplier and supplier/mocks packages.
    • Added import for sessiontypes package from github.com/pokt-network/poktroll/x/session/types.
    • Modified the SupplierKeeper function to accept an additional parameter sessionByAppAddr of type supplier.SessionsByAppAddress.
    • Added implementation for GetSession method of the mockSessionKeeper mock.
    • Added a call to k.SupplySessionKeeper(mockSessionKeeper).
  • relay_verifier.go (in pkg/relayer/proxy package):

    • Added import for sdkerrors package.
    • Added import for ring_secp256k1 package.
    • Removed import for github.com/cometbft/cometbft/crypto package.
    • Removed import for github.com/pokt-network/poktroll/x/session/types package.
    • Modified the VerifyRelayRequest function to handle missing application address from the relay request.
    • Changed the method of obtaining signable bytes of the relay request to GetSignableBytesHash.
    • Changed the method of verifying relay request's signature using ringSig.
    • Modified the code for verifying relay request session using GetSession method of rp.sessionQuerier.
    • Improved error message when session ID does not match relay request's session ID.
  • relay_builders.go:

    • Added a debug log message when there is a failure in unmarshaling the relay request.
  • ring_signer.go:

    • Changed the Sign function to accept an array of 32 bytes for the message argument instead of a byte slice.
  • sessiontypes package:

    • Added SessionKeeper interface which includes the GetSession method.
    • Updated the go:generate mockgen command to include the SessionKeeper interface in the mock generation.
  • testqueryclients/appquerier.go:

    • Updated the import paths for the mockclient and types packages.
    • Replaced the context parameter in the GetApplication function with an underscore.
    • Updated the return type of the GetApplication function to use the apptypes type.
    • Updated the variable names within the GetApplication function.
    • Updated the error type returned in case of an application not found to apptypes.ErrAppNotFound.
  • app.go:

    • Changes to the New function related to the ordering of code and addition of comments.
  • interface.go:

    • Added SupplierQueryClient interface.
    • Added SessionQueryClient interface.
  • session.feature:

    • Added a new feature file describing the "Session Namespace" feature.
    • Includes a scenario for completing the claim/proof lifecycle for a valid session.
  • simple_signer.go:

    • Changed the signature parameter of the Sign function to accept an array of bytes with a fixed size of 32.
  • logger.go (in pkg/polylog/polyzero package):

    • Added the os package as an import.
    • Updated the NewLogger function to provide default logger configuration.
    • Added TODO comments for improving and adding new logger functions.
  • client.go:

    • Added import of the cosmossdk.io/api/tendermint/abci package.
    • Removed import of the abciTypes package from github.com/cometbft/cometbft/abci/types.
    • Changed the type TxEvent to be an alias for the abci.TxResult type.
    • Added comments.
  • proxy.go:

    • Removed the import of cosmosclient package.
    • Removed the import of querytypes package.
    • Replaced the type suppliertypes.QueryClient with client.SupplierQueryClient.
    • Replaced the type sessiontypes.QueryClient with client.SessionQueryClient.
    • Removed the field clientCtx.
    • Replaced the initialization of supplierQuerier with client.SupplierQueryClient.
    • Replaced the initialization of sessionQuerier with client.SessionQueryClient.
    • Removed the initialization of keyring.
    • Added a check to ensure proxiedServicesEndpoints is not empty in the validateConfig method.
  • relayerproxy.go:

    • Added various package imports and new struct and functions related to testing utilities and mock structures for the relayer proxy.

Issue

On-chain claim message handling should validate that the claimed session matches the session at the given claimed sesison end height; i.e. given some session inputs, ensure that the ID matches and that the supplier is in the session.

Type of change

Select one or more:

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

Testing

  • Run all unit tests: make go_develop_and_test
  • Verify Localnet manually: See the instructions [here](TODO: add link to instructions)

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have performed a self-review of my own code
  • I have commented my code, updated documentation and left TODOs throughout the codebase

@bryanchriswhite bryanchriswhite added relayminer Changes related to the Relayminer on-chain On-chain business logic labels Nov 29, 2023
@bryanchriswhite bryanchriswhite added this to the Shannon TestNet milestone Nov 29, 2023
@bryanchriswhite bryanchriswhite self-assigned this Nov 29, 2023
x/supplier/keeper/message_create_claim_test.go Outdated Show resolved Hide resolved
x/supplier/keeper/msg_server_create_claim_test.go Outdated Show resolved Hide resolved
x/supplier/keeper/msg_server_create_claim_test.go Outdated Show resolved Hide resolved
x/supplier/keeper/keeper.go Outdated Show resolved Hide resolved
app/app.go Outdated Show resolved Hide resolved
e2e/tests/session_steps_test.go Outdated Show resolved Hide resolved
e2e/tests/session_steps_test.go Outdated Show resolved Hide resolved
e2e/tests/session_steps_test.go Outdated Show resolved Hide resolved
e2e/tests/session_steps_test.go Outdated Show resolved Hide resolved
e2e/tests/session.feature Outdated Show resolved Hide resolved
Copy link

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

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Nov 29, 2023
@bryanchriswhite bryanchriswhite force-pushed the issues/140/chore/claim-msg-validation branch from c7e0fdd to 61c08c7 Compare November 29, 2023 11:36
@bryanchriswhite bryanchriswhite force-pushed the issues/140/chore/claim-msg-validation branch from 61c08c7 to a74863c Compare November 29, 2023 11:41
testutil/testkeyring/accounts.go Outdated Show resolved Hide resolved
testutil/network/network.go Outdated Show resolved Hide resolved
@bryanchriswhite bryanchriswhite force-pushed the issues/140/chore/claim-msg-validation branch from caa24cd to 17fb3f1 Compare November 30, 2023 19:47
@bryanchriswhite bryanchriswhite changed the base branch from main to issues/140/chore/testkeyring November 30, 2023 19:47
@Olshansk Olshansk self-requested a review November 30, 2023 22:25
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.

Posting a partial review and will finish tomorrow.

app/app.go Show resolved Hide resolved
e2e/tests/session.feature Show resolved Hide resolved
x/supplier/keeper/keeper.go Show resolved Hide resolved
x/supplier/client/cli/query_claim_test.go Outdated Show resolved Hide resolved
x/supplier/client/cli/query_claim_test.go Outdated Show resolved Hide resolved
e2e/tests/session_steps_test.go Outdated Show resolved Hide resolved
testutil/keeper/supplier.go Outdated Show resolved Hide resolved
testutil/keeper/supplier.go Outdated Show resolved Hide resolved
testutil/keeper/supplier.go Outdated Show resolved Hide resolved
testutil/network/network.go Outdated Show resolved Hide resolved
//
// TODO_IMPROVE: It would be nice if the value could be set correctly based
// on whether the test using it is running in tilt or not.
const CometLocalWebsocketURL = "ws://sequencer-poktroll-sequencer:36657/websocket"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@okdas Does this look right to you?

Copy link
Member

Choose a reason for hiding this comment

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

@bryanchriswhite yep! That hostname will now resolve to sequencer on both LocalNet and DevNet!

Copy link
Member

Choose a reason for hiding this comment

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

@okdas Bump

@bryanchriswhite bryanchriswhite marked this pull request as ready for review December 4, 2023 12:11
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.

The PR is looking really good overall. Really appreciate both the changes, and comments to set up followup work.

Left a few lingering comments but should be g2g right after!

e2e/tests/session.feature Show resolved Hide resolved
e2e/tests/session_steps_test.go Outdated Show resolved Hide resolved
e2e/tests/session_steps_test.go Show resolved Hide resolved
pkg/client/tx/client.go Outdated Show resolved Hide resolved
x/supplier/keeper/msg_server_create_claim.go Outdated Show resolved Hide resolved
testutil/supplier/fixtures.go Outdated Show resolved Hide resolved
testutil/supplier/fixtures.go Show resolved Hide resolved
testutil/supplier/fixtures.go Show resolved Hide resolved
x/supplier/client/cli/helpers_test.go Show resolved Hide resolved
sessionQueryClient := types2.NewQueryClient(net.Validators[0].ClientCtx)
res, err := sessionQueryClient.GetSession(ctx, &types2.QueryGetSessionRequest{
ApplicationAddress: appAddr,
Service: &sharedtypes.Service{Id: testServiceId},
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on having the caller pass in this local constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely have thoughts 😅. This is related to #236 (comment).

TL;DR, I would hold off for now.

It might be better to take a step back and think about how we would like multi-service integration tests to be designed, and then evaluate if it's compatible with our current direction (i.e. refactor and/or reuse what we have) or if we need to do that in a new test suite with more comprehensive helpers. Wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

I think holding off and seeing what/when we need from multi-service integration makes sense.

Let's hold off 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙏

bryanchriswhite and others added 4 commits December 5, 2023 11:02
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.

LGTM. The last round of comments & cleanup really put the :bowtie: on it!

Note that the E2E tests are failing and wanted to make sure you remember the base branch here is not main (should it be?), but otherwise g2g!

type TxResult struct {
Events []abciTypes.Event `json:"events"`
}
//
Copy link
Member

Choose a reason for hiding this comment

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

So much cleaner!

@@ -21,6 +21,12 @@ const (
// application address and the value is the session fixture.
type SessionsByAppAddress map[string]sessiontypes.Session

// AppSupplierPair is a pairing of an application and a supplier address.
Copy link
Member

Choose a reason for hiding this comment

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

Ty for making the change!

sessionQueryClient := types2.NewQueryClient(net.Validators[0].ClientCtx)
res, err := sessionQueryClient.GetSession(ctx, &types2.QueryGetSessionRequest{
ApplicationAddress: appAddr,
Service: &sharedtypes.Service{Id: testServiceId},
Copy link
Member

Choose a reason for hiding this comment

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

I think holding off and seeing what/when we need from multi-service integration makes sense.

Let's hold off 👍

@bryanchriswhite
Copy link
Contributor Author

Note that the E2E tests are failing and wanted to make sure you remember the base branch here is not main (should it be?), but otherwise g2g!

Thanks for calling this out! I typically intentionally keep the github base of PR branches the same as the git (actual) base until after approval to avoid cluttering the commit list during review. I always take note of the +/- LOC diff before and after re-github-basing (not an actual rebase operation). In the event of discrepancies and/or merge conflict resolutions I double-check everything before merging and would ask for re-review if something unexpected arises or changes since approval.

…yring

* pokt/main:
  [Off-chain, Polylog] refactor: replace std logger usage in pkg/... with polylog (#219)
  [Off-chain, Polylog] feat: polylog context integration (#218)
  [Off-chain, Polylog] chore: add zerolog logger implementation (#211)
  [Off-chain, Polylog] test: add testutils (#209)
  [Testing] chore: add testkeyring pkg (#237)
…im-msg-validation

* issues/140/chore/testkeyring:
  [Off-chain, Polylog] refactor: replace std logger usage in pkg/... with polylog (#219)
  [Off-chain, Polylog] feat: polylog context integration (#218)
  [Off-chain, Polylog] chore: add zerolog logger implementation (#211)
  [Off-chain, Polylog] test: add testutils (#209)
  [Testing] chore: add testkeyring pkg (#237)
(cherry picked from commit 358cb0ae8ffed76a75d83f42ef0a4ea94d185189)
@bryanchriswhite bryanchriswhite force-pushed the issues/140/chore/claim-msg-validation branch from 893b9db to e58cd33 Compare December 6, 2023 09:29
…msg-validation

* pokt/main:
  [RelayerProxy] Test relayer proxy startup (#199)
  [CI] Pin ignite version to 0.27.2 (#249)
  fix: localnet output broken 🙄 (#247)
  Make Relay{Request,Response}.GetSignableBytes return the signable hash (#245)
@bryanchriswhite bryanchriswhite changed the base branch from issues/140/chore/testkeyring to main December 7, 2023 10:58
@bryanchriswhite bryanchriswhite merged commit 7d0c1c9 into main Dec 7, 2023
5 checks passed
@bryanchriswhite bryanchriswhite deleted the issues/140/chore/claim-msg-validation branch December 7, 2023 11:10
@bryanchriswhite bryanchriswhite removed push-image CI related - pushes images to ghcr.io devnet-test-e2e labels May 16, 2024
@github-actions github-actions bot removed the devnet label May 16, 2024
okdas pushed a commit that referenced this pull request Nov 14, 2024
* chore: add testkeyring pkg

* chore: update go.mod

* refactor: add session keeper dependency to supplier keeper

* refactor: add mock session keeper to supplier keeper testutil

* refactor: supplier keeper testutil usage

* chore: add claim session validation

* test: claim message validation unit coverage

* test: e2e session lifecycle

* chore: add `ApplicationModuleGenesisStateWithAccounts` testutil

* wip: fix claims show/list tests

* fix: bug in session supplier hydration

* wip: fixing tests

* wip: fixing tests

* chore: update mock node flag with in-tilt host

* wip: debugging

* wip: debugging

* chore: self-review improvements

* chore: review feedback improvements

* chore: add TODO

Co-authored-by: Daniel Olshansky <[email protected]>

* fixup! chore: update mock node flag with in-tilt host

* chore: review feedback improvements

* chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* wip

* chore: chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* fix: post-merge

* chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* chore: remove todo

* chore: self-review improvements

* chore: re

Co-authored-by: Daniel Olshansky <[email protected]>

* chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* chore: chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* fix: test

* fix: disambiguate `CometLocalWebsocketURL` & `CometLocalTCPURL`

(cherry picked from commit 358cb0ae8ffed76a75d83f42ef0a4ea94d185189)

---------

Co-authored-by: Daniel Olshansky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-chain On-chain business logic relayminer Changes related to the Relayminer
Projects
Status: ✅ Done
3 participants