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

Removing double validation #220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blockiosaurus
Copy link
Contributor

@blockiosaurus blockiosaurus commented Mar 1, 2025

After reviewing the asset validation code it seems like we're unnecessarily performing separate validations on both Asset and Collection plugins. Deduplication is already handled by the checks BtreeMap so I don't believe we actually need to do these separately

If that's not the case then we need to update the tests to appropriately prove out why these validations should be separate.

Summary by CodeRabbit

  • Refactor
    • Streamlined the validation process for plugin and permission checks by eliminating redundant comparison steps.
    • Optimized the handling of asset and collection permissions to ensure a more direct and efficient evaluation.

Copy link

vercel bot commented Mar 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mpl-core-js-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 1, 2025 3:42pm

Copy link

coderabbitai bot commented Mar 1, 2025

Walkthrough

The changes simplify the validation logic. In programs/mpl-core/src/plugins/lifecycle.rs, the key: Key parameter has been removed from the validation functions, and the associated match statements were updated to use check_key directly with check_result. In programs/mpl-core/src/utils/mod.rs, the validation calls for the Key::CollectionV1 variant have been removed from both asset and collection permission functions, while validations for Key::AssetV1 remain unchanged.

Changes

File(s) Change Summary
programs/mpl-core/src/plugins/lifecycle.rs Removed the key: Key parameter from validate_plugin_checks and validate_external_plugin_adapter_checks; adjusted match statements to use check_key.
programs/mpl-core/src/utils/mod.rs Removed calls to validate_plugin_checks and validate_external_plugin_adapter_checks for Key::CollectionV1 in both validate_asset_permissions and validate_collection_permissions; retained logic for Key::AssetV1.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant LifecycleValidator
    participant CheckLogic

    Caller->>LifecycleValidator: Call validate_plugin_checks(params)
    LifecycleValidator->>CheckLogic: Evaluate check_result (approve/reject)
    CheckLogic-->>LifecycleValidator: Return validation status
    LifecycleValidator->>Caller: Return approval or rejection
Loading
sequenceDiagram
    participant Requester
    participant AssetValidator
    participant PluginValidator

    Requester->>AssetValidator: Call validate_asset_permissions(assetKey)
    AssetValidator->>PluginValidator: Validate using AssetV1 logic
    PluginValidator-->>AssetValidator: Return result
    AssetValidator->>Requester: Return permission status
Loading

Poem

I'm a rabbit coding through the night,
Hoping to simplify validations just right.
Keys removed, checks run smooth and free,
A streamlined flow for all to see!
Hoppity-hop with code so light,
Cheers to changes that bring delight! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 661d5e0 and f72daf1.

📒 Files selected for processing (2)
  • programs/mpl-core/src/plugins/lifecycle.rs (2 hunks)
  • programs/mpl-core/src/utils/mod.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • programs/mpl-core/src/utils/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Programs / Test (mpl-core)
  • GitHub Check: Programs / Build
🔇 Additional comments (2)
programs/mpl-core/src/plugins/lifecycle.rs (2)

684-688: Simplified validation logic in plugin checks.

The code now directly checks if the plugin has the capability to approve or reject, without needing to compare with an additional key parameter. This removes redundant validation that was previously happening.


761-761: Simplified validation logic in external plugin adapter checks.

Similar to the previous change, the code now directly checks the plugin's capabilities without comparing with an additional key parameter. This change maintains the same validation behavior while removing unnecessary checks.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Choose a reason for hiding this comment

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

PR Overview

This PR removes redundant validations by eliminating separate key-based checks for Asset and Collection plugins, as deduplication is already managed by the checks BTreeMap.

  • Removed the key parameter and associated equality checks in both plugin validation functions.
  • Updated calls in the utils module to reflect the new function signatures and consolidated validation logic.

Reviewed Changes

File Description
programs/mpl-core/src/plugins/lifecycle.rs Removed key comparisons from validate_plugin_checks and validate_external_plugin_adapter_checks to avoid double validation.
programs/mpl-core/src/utils/mod.rs Updated invocations of plugin validation functions to remove the now-unused key parameter.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

programs/mpl-core/src/plugins/lifecycle.rs:685

  • Ensure that removing the key equality check in validate_plugin_checks does not allow validations for unintended plugin types. Confirm that deduplication using the checks BTreeMap fully prevents processing unrelated checks.
if matches!(check_result, CheckResult::CanApprove | CheckResult::CanReject) {

programs/mpl-core/src/plugins/lifecycle.rs:761

  • Verify that removing the key comparison in validate_external_plugin_adapter_checks does not inadvertently validate checks for unrelated keys. Rely solely on the check_result flags with confidence that the checks map is managed appropriately.
if check_result.can_listen() || check_result.can_approve() || check_result.can_reject() {

programs/mpl-core/src/utils/mod.rs:243

  • [nitpick] Consider adding or updating tests to verify that the new function signatures and consolidated validation logic behave as expected for both asset and collection validations.
match validate_plugin_checks(
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: f72daf1 Previous: 661d5e0 Ratio
CU: create a new, empty asset 11095 Compute Units 11206 Compute Units 0.99
Space: create a new, empty asset 91 Bytes 91 Bytes 1
CU: create a new, empty asset with empty collection 22570 Compute Units 22681 Compute Units 1.00
Space: create a new, empty asset with empty collection 91 Bytes 91 Bytes 1
CU: create a new asset with plugins 35071 Compute Units 35182 Compute Units 1.00
Space: create a new asset with plugins 194 Bytes 194 Bytes 1
CU: create a new asset with plugins and empty collection 41091 Compute Units 41202 Compute Units 1.00
Space: create a new asset with plugins and empty collection 194 Bytes 194 Bytes 1
CU: list an asset 27903 Compute Units 28101 Compute Units 0.99
CU: sell an asset 43944 Compute Units 44473 Compute Units 0.99
CU: list an asset with empty collection 35467 Compute Units 35663 Compute Units 0.99
CU: sell an asset with empty collection 56299 Compute Units 56825 Compute Units 0.99
CU: list an asset with collection royalties 36116 Compute Units 36434 Compute Units 0.99
CU: sell an asset with collection royalties 61287 Compute Units 61909 Compute Units 0.99
CU: transfer an empty asset 6333 Compute Units 6444 Compute Units 0.98
CU: transfer an empty asset with empty collection 8933 Compute Units 9043 Compute Units 0.99
CU: transfer an asset with plugins 14472 Compute Units 14769 Compute Units 0.98
CU: transfer an asset with plugins and empty collection 17072 Compute Units 17368 Compute Units 0.98

This comment was automatically generated by workflow using github-action-benchmark.

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