Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.

use same recipe<>schema validation on verifier and plugin#126

Merged
webpiratt merged 2 commits into
mainfrom
refactor-validation
Jul 10, 2025
Merged

use same recipe<>schema validation on verifier and plugin#126
webpiratt merged 2 commits into
mainfrom
refactor-validation

Conversation

@webpiratt

@webpiratt webpiratt commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

Ref: #124

Summary by CodeRabbit

  • New Features

    • Centralized policy validation logic for plugins, improving consistency and maintainability.
  • Refactor

    • Updated several plugin methods to use pointer return types for recipe specifications.
    • Delegated plugin policy validation to a shared utility, replacing custom validation in multiple plugins.
    • Removed the NonceManager and related nonce management logic from the payroll plugin.
  • Bug Fixes

    • Improved error handling during transaction rollback to avoid unnecessary logging for closed transactions.
  • Chores

    • Updated and reorganized module dependencies for improved reliability and compatibility.
  • Style

    • Removed unused constants from the payroll plugin.

@coderabbitai

coderabbitai Bot commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update centralizes plugin policy validation by introducing a generic ValidatePluginPolicy function in a new internal package. All plugin-specific policy validation methods now delegate to this function, replacing custom logic. Several GetRecipeSpecification methods are updated to return pointers. Dependency versions and requirements in go.mod are reorganized and updated.

Changes

File(s) Change Summary
go.mod Updated and reorganized dependencies: removed/added direct and indirect requirements, updated module versions.
internal/plugin/plugin.go Added new plugin package with a generic ValidatePluginPolicy function for plugin policy validation.
plugin/fees/policy.go
plugin/payroll/policy.go
Replaced custom policy validation logic with a call to the new plugin.ValidatePluginPolicy function.
plugin/dca/dca.go
plugin/fees/policy.go
plugin/payroll/transaction.go
Changed GetRecipeSpecification methods to return pointers instead of values.
plugin/payroll/constants.go Removed the erc20ABI constant, leaving only the PLUGIN_TYPE constant.
plugin/payroll/nonce.go Deleted the NonceManager struct and all associated methods for nonce management.
service/policy.go Improved error handling in handleRollback to suppress specific rollback errors.

Sequence Diagram(s)

sequenceDiagram
    participant Plugin as Plugin (e.g., FeePlugin, PayrollPlugin)
    participant InternalPlugin as internal/plugin
    participant Engine as Engine
    participant Schema as RecipeSchema

    Plugin->>InternalPlugin: ValidatePluginPolicy(policyDoc, GetRecipeSpecification())
    InternalPlugin->>Engine: Validate(policy, schema)
    Engine-->>InternalPlugin: Validation result
    InternalPlugin-->>Plugin: error or nil
Loading

Possibly related PRs

Suggested reviewers

  • RaghavSood
  • garry-sharp
  • johnnyluo

Poem

In the warren of code, a new path we tread,
Validation centralized, old logic has fled.
Plugins now point to a single wise hare,
Who checks every policy with diligent care.
Dependencies pruned, pointers now bloom—
Hopping toward clarity, with plenty of room!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f612624 and 000d73d.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (9)
  • go.mod (3 hunks)
  • internal/plugin/plugin.go (1 hunks)
  • plugin/dca/dca.go (1 hunks)
  • plugin/fees/policy.go (2 hunks)
  • plugin/payroll/constants.go (0 hunks)
  • plugin/payroll/nonce.go (0 hunks)
  • plugin/payroll/policy.go (2 hunks)
  • plugin/payroll/transaction.go (1 hunks)
  • service/policy.go (2 hunks)
💤 Files with no reviewable changes (2)
  • plugin/payroll/constants.go
  • plugin/payroll/nonce.go
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: garry-sharp
PR: vultisig/plugin#117
File: plugin/fees/policy.go:46-47
Timestamp: 2025-07-04T10:47:47.927Z
Learning: For the fee plugin in plugin/fees/policy.go, the resource validation and recipe specification are intentionally configured to accept only USDC transfers ("ethereum.usdc.transfer"), not general ERC20 transfers ("ethereum.erc20.transfer"), as fees are only collected in USDC.
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/policy.go:160-160
Timestamp: 2025-07-09T22:23:17.348Z
Learning: In plugin/payroll/policy.go, the "token" case in the checkRule method intentionally does not call validateToken() as this is a temporary implementation that will be replaced with generic schema validation. The missing validation call is expected behavior during this transition period.
internal/plugin/plugin.go (3)
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/policy.go:160-160
Timestamp: 2025-07-09T22:23:17.348Z
Learning: In plugin/payroll/policy.go, the "token" case in the checkRule method intentionally does not call validateToken() as this is a temporary implementation that will be replaced with generic schema validation. The missing validation call is expected behavior during this transition period.
Learnt from: garry-sharp
PR: vultisig/plugin#117
File: plugin/fees/policy.go:46-47
Timestamp: 2025-07-04T10:47:47.927Z
Learning: For the fee plugin in plugin/fees/policy.go, the resource validation and recipe specification are intentionally configured to accept only USDC transfers ("ethereum.usdc.transfer"), not general ERC20 transfers ("ethereum.erc20.transfer"), as fees are only collected in USDC.
plugin/payroll/policy.go (9)
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/policy.go:160-160
Timestamp: 2025-07-09T22:23:17.348Z
Learning: In plugin/payroll/policy.go, the "token" case in the checkRule method intentionally does not call validateToken() as this is a temporary implementation that will be replaced with generic schema validation. The missing validation call is expected behavior during this transition period.
Learnt from: garry-sharp
PR: vultisig/plugin#117
File: plugin/fees/policy.go:46-47
Timestamp: 2025-07-04T10:47:47.927Z
Learning: For the fee plugin in plugin/fees/policy.go, the resource validation and recipe specification are intentionally configured to accept only USDC transfers ("ethereum.usdc.transfer"), not general ERC20 transfers ("ethereum.erc20.transfer"), as fees are only collected in USDC.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:0-0
Timestamp: 2025-06-18T18:23:20.077Z
Learning: In the payroll plugin (plugin/payroll/transaction.go), signRequest.Transaction is stored with the "0x" prefix, making it compatible with gcommon.FromHex which requires 0x-prefixed hex strings.
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:510-514
Timestamp: 2025-06-18T18:20:59.510Z
Learning: The erc20ABI constant is defined in plugin/payroll/constants.go within the payroll package, making it accessible to other files in the same package like transaction.go.
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/transaction.go:186-197
Timestamp: 2025-07-09T22:22:36.651Z
Learning: In plugin/payroll/transaction.go, the getTokenID function is designed to return evm.ZeroAddress.Hex() when no "token" parameter constraint is found, rather than returning an error. This is expected behavior according to the team's design intent, even though the token parameter is marked as required in the recipe specification.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:43-44
Timestamp: 2025-06-18T18:22:06.358Z
Learning: In the vultisig/plugin codebase, the hardcoded ethereumEvmChainID = big.NewInt(1) in plugin/payroll/transaction.go is intentional for the current implementation phase. The team is implementing ETH first, with plans to add other EVM chains later. The functions/methods are already designed to work with all EVM chains.
Learnt from: johnnyluo
PR: vultisig/plugin#108
File: cmd/payroll/worker/main.go:84-84
Timestamp: 2025-07-02T04:58:30.139Z
Learning: VaultServiceConfig is defined as a field of type vault_config.Config from the external package "github.com/vultisig/verifier/vault_config" in worker configuration structs across the vultisig/plugin codebase (cmd/payroll/worker/config.go, cmd/fees/worker/config.go, cmd/dca/worker/config.go). The vault_config.Config struct contains an EncryptionSecret field that can be accessed via cfg.VaultServiceConfig.EncryptionSecret.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:178-183
Timestamp: 2025-06-18T18:28:19.759Z
Learning: In the payroll plugin, the Hash field in PluginKeysignRequest is intentionally set to the unsigned transaction hex (same as Message field) because computing a hash with empty V,R,S signature fields doesn't make sense, and it's documented as "not on-chain hash without signature". This is a deliberate placeholder approach.
plugin/payroll/transaction.go (3)
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:0-0
Timestamp: 2025-06-18T18:23:20.077Z
Learning: In the payroll plugin (plugin/payroll/transaction.go), signRequest.Transaction is stored with the "0x" prefix, making it compatible with gcommon.FromHex which requires 0x-prefixed hex strings.
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/policy.go:160-160
Timestamp: 2025-07-09T22:23:17.348Z
Learning: In plugin/payroll/policy.go, the "token" case in the checkRule method intentionally does not call validateToken() as this is a temporary implementation that will be replaced with generic schema validation. The missing validation call is expected behavior during this transition period.
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/transaction.go:186-197
Timestamp: 2025-07-09T22:22:36.651Z
Learning: In plugin/payroll/transaction.go, the getTokenID function is designed to return evm.ZeroAddress.Hex() when no "token" parameter constraint is found, rather than returning an error. This is expected behavior according to the team's design intent, even though the token parameter is marked as required in the recipe specification.
go.mod (3)
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:43-44
Timestamp: 2025-06-18T18:22:06.358Z
Learning: In the vultisig/plugin codebase, the hardcoded ethereumEvmChainID = big.NewInt(1) in plugin/payroll/transaction.go is intentional for the current implementation phase. The team is implementing ETH first, with plans to add other EVM chains later. The functions/methods are already designed to work with all EVM chains.
Learnt from: johnnyluo
PR: vultisig/plugin#108
File: Dockerfile.Payroll.server:14-19
Timestamp: 2025-07-02T04:55:36.331Z
Learning: In the vultisig/plugin repository, the team maintains both the main repository and the go-wrappers dependency repository, so they are comfortable downloading from the master branch rather than pinning to specific commits.
plugin/fees/policy.go (7)
Learnt from: garry-sharp
PR: vultisig/plugin#117
File: plugin/fees/policy.go:46-47
Timestamp: 2025-07-04T10:47:47.927Z
Learning: For the fee plugin in plugin/fees/policy.go, the resource validation and recipe specification are intentionally configured to accept only USDC transfers ("ethereum.usdc.transfer"), not general ERC20 transfers ("ethereum.erc20.transfer"), as fees are only collected in USDC.
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/policy.go:160-160
Timestamp: 2025-07-09T22:23:17.348Z
Learning: In plugin/payroll/policy.go, the "token" case in the checkRule method intentionally does not call validateToken() as this is a temporary implementation that will be replaced with generic schema validation. The missing validation call is expected behavior during this transition period.
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
Learnt from: garry-sharp
PR: vultisig/plugin#117
File: plugin/fees/constraints.go:3-3
Timestamp: 2025-07-04T10:50:42.832Z
Learning: For the vultisig/plugin project, use "fee" (singular) throughout the codebase wherever possible, not "fees" (plural). This applies to all naming conventions including plugin types, variable names, function names, comments, and documentation.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:0-0
Timestamp: 2025-06-18T18:23:20.077Z
Learning: In the payroll plugin (plugin/payroll/transaction.go), signRequest.Transaction is stored with the "0x" prefix, making it compatible with gcommon.FromHex which requires 0x-prefixed hex strings.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:510-514
Timestamp: 2025-06-18T18:20:59.510Z
Learning: The erc20ABI constant is defined in plugin/payroll/constants.go within the payroll package, making it accessible to other files in the same package like transaction.go.
Learnt from: webpiratt
PR: vultisig/plugin#125
File: plugin/payroll/transaction.go:186-197
Timestamp: 2025-07-09T22:22:36.651Z
Learning: In plugin/payroll/transaction.go, the getTokenID function is designed to return evm.ZeroAddress.Hex() when no "token" parameter constraint is found, rather than returning an error. This is expected behavior according to the team's design intent, even though the token parameter is marked as required in the recipe specification.
🧬 Code Graph Analysis (3)
internal/plugin/plugin.go (1)
service/policy.go (1)
  • Policy (17-23)
plugin/payroll/policy.go (1)
internal/plugin/plugin.go (1)
  • ValidatePluginPolicy (13-30)
plugin/payroll/transaction.go (1)
plugin/payroll/payroll.go (1)
  • PayrollPlugin (19-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: migration-test
🔇 Additional comments (15)
service/policy.go (2)

5-5: LGTM! Adding the errors package for enhanced error checking.

The import enables the improved error handling in the handleRollback method.


45-45: Excellent improvement to error handling logic.

Suppressing log messages for pgx.ErrTxClosed prevents unnecessary noise in logs since attempting to rollback an already-closed transaction is not a genuine error condition.

plugin/dca/dca.go (1)

777-778: LGTM! Method signature updated to support centralized validation.

The change from returning a value to a pointer aligns with the new plugin.ValidatePluginPolicy function signature and maintains consistency across plugins.

plugin/payroll/transaction.go (1)

355-356: LGTM! Consistent method signature update.

The change to return a pointer instead of a value aligns with the centralized validation pattern and maintains consistency with other plugins.

internal/plugin/plugin.go (1)

13-30: Excellent centralization of policy validation logic.

This function effectively consolidates validation steps that were previously duplicated across plugins:

  1. Base64 decoding with proper error context
  2. Protobuf unmarshaling with error handling
  3. Engine-based schema validation

The error wrapping provides clear context for debugging validation failures.

plugin/payroll/policy.go (2)

7-7: LGTM! Adding import for centralized validation.

The import enables the use of the new centralized ValidatePluginPolicy function.


53-53: Excellent refactoring to use centralized validation.

Based on the retrieved learnings, this replaces the temporary validation implementation with the proper centralized approach, improving consistency across plugins while maintaining the same validation capabilities.

go.mod (5)

19-19: LGTM: Testify moved to direct dependency

Moving testify from indirect to direct dependency is appropriate given its likely increased usage in the codebase.


22-23: LGTM: Recipe and verifier dependency updates

The version updates to newer commits for recipes and verifier packages align with the centralized validation refactoring.


25-26: LGTM: Sync and protobuf moved to direct dependencies

Moving golang.org/x/sync and google.golang.org/protobuf to direct dependencies is appropriate as they're now used directly in the new centralized plugin validation logic.


90-90: LGTM: Protobuf reorganization

Moving github.com/golang/protobuf to indirect while promoting google.golang.org/protobuf to direct is consistent with using the newer protobuf library directly.


133-133: LGTM: New indirect dependency

Adding github.com/stretchr/objx as an indirect dependency is consistent with the testify package reorganization.

plugin/fees/policy.go (3)

4-4: LGTM: Internal plugin package import

The import of the internal plugin package is appropriate for accessing the centralized validation function.


19-19: LGTM: Centralized validation delegation

The refactoring to delegate policy validation to the generic plugin.ValidatePluginPolicy function reduces code duplication and centralizes validation logic.


22-23: LGTM: Return pointer for consistency

Changing the return type to *rtypes.RecipeSchema is consistent with similar changes in other plugins and follows Go best practices for potentially large structs.

Comment thread plugin/fees/policy.go

func (p *PayrollPlugin) GetRecipeSpecification() rtypes.RecipeSchema {
return rtypes.RecipeSchema{
func (p *PayrollPlugin) GetRecipeSpecification() *rtypes.RecipeSchema {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why changed to pointer everywhere? Any proto generated structs should be used as pointers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yup, thanks

@webpiratt
webpiratt enabled auto-merge July 10, 2025 20:41
@webpiratt webpiratt changed the title fix data & validation use same recipe<>schema validation on verifier and plugin Jul 10, 2025

@johnnyluo johnnyluo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants