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

fix: update return types in database and policy methods to use pointe…#121

Merged
RaghavSood merged 5 commits into
mainfrom
fix-return-value
Jul 8, 2025
Merged

fix: update return types in database and policy methods to use pointe…#121
RaghavSood merged 5 commits into
mainfrom
fix-return-value

Conversation

@johnnyluo

@johnnyluo johnnyluo commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

…rs for better error handling

Summary by CodeRabbit

  • Refactor
    • Improved consistency in handling policy and fee run data by updating methods to return references.
    • Streamlined error handling and simplified retrieval of policy and fee run information.
    • Enhanced reliability of transaction management during fee run creation.
    • Removed deprecated transaction broadcast strategies and error code constants for cleaner internal error handling.

No changes to user-facing features or functionality.

Copilot AI review requested due to automatic review settings July 8, 2025 00:24
@coderabbitai

coderabbitai Bot commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This set of changes standardizes the handling of the PluginPolicy and FeeRun types throughout the codebase by updating function signatures and method implementations to use pointers rather than value types. Related error handling and method return values are adjusted accordingly, and minor import and comment formatting improvements are included. Additionally, several constant declarations related to broadcast strategies and transaction errors were removed.

Changes

Files/Paths Change Summary
api/plugin.go Updated calls to dereference policy pointer before passing to functions.
plugin/fees/fees.go Changed argument to executeFeeCollection from pointer to value; reordered imports and minor comment fix.
plugin/payroll/transaction.go Dereferenced pluginPolicy before passing to ProposeTransactions and initSign; reordered imports.
service/policy.go Updated GetPluginPolicy to return pointer; simplified error handling and return logic.
storage/db.go Changed interface methods to return pointers for GetPluginPolicy and CreateFeeRun.
storage/postgres/fees.go Changed CreateFeeRun to return pointer; added deferred rollback; adjusted error returns.
storage/postgres/policy.go Changed GetPluginPolicy to return pointer; adjusted error returns and return values.
internal/types/broadcast.go Removed constant declarations for broadcast strategies and transaction error codes.

Sequence Diagram(s)

sequenceDiagram
    participant API
    participant Service
    participant Storage

    API->>Service: GetPluginPolicy(policyID)
    Service->>Storage: GetPluginPolicy(policyID)
    Storage-->>Service: *PluginPolicy
    Service-->>API: *PluginPolicy

    API->>Service: DeletePluginPolicyById(policy)
    Service->>API: verifyPolicySignature(*policy)
Loading

Possibly related PRs

Poem

In the warren of code, we hop and we tweak,
Pointers now guide us, no values we seek.
With signatures neat and returns all aligned,
The PluginPolicy’s journey is clearly defined.
A hop, a deref, a rollback so sly—
The code runs much smoother, oh my, oh my!
🐇✨


📜 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 bea555e and 00ce63b.

📒 Files selected for processing (1)
  • internal/types/broadcast.go (0 hunks)
💤 Files with no reviewable changes (1)
  • internal/types/broadcast.go
⏰ 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). (1)
  • GitHub Check: build
✨ 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.
    • 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.

Copilot AI 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.

Pull Request Overview

This PR updates database and service methods to return pointers for improved error handling, and adjusts all callers accordingly.

  • Changed GetPluginPolicy and CreateFeeRun signatures in storage and interface to return pointers.
  • Updated service layer and API/plugin code to handle new pointer return types.
  • Simplified service implementations by delegating directly to the database calls.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
storage/postgres/policy.go Changed GetPluginPolicy to return *PluginPolicy and updated returns.
storage/postgres/fees.go Changed CreateFeeRun to return *FeeRun, added defer tx.Rollback, and updated returns.
storage/db.go Updated DatabaseStorage interface method signatures to use pointers.
service/policy.go Updated service interface and methods to return pointers and delegate directly.
plugin/payroll/transaction.go Updated calls to dereference *PluginPolicy when calling methods.
plugin/fees/fees.go Updated call to dereference *PluginPolicy and adjusted import grouping.
api/plugin.go Updated calls to dereference *PluginPolicy for validation and signature checks.

Comment thread storage/postgres/fees.go Outdated
Comment thread storage/postgres/fees.go Outdated
Comment thread service/policy.go
Comment thread service/policy.go
johnnyluo and others added 2 commits July 8, 2025 10:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@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

🧹 Nitpick comments (1)
storage/postgres/fees.go (1)

35-35: Standardize error formatting for consistency.

The error messages use both %w and %s formatters inconsistently. For better error handling and debugging, consider using %w for error wrapping consistently.

-		return nil, fmt.Errorf("failed to insert fee: %s", err)
+		return nil, fmt.Errorf("failed to insert fee: %w", err)
-		return nil, fmt.Errorf("failed to commit transaction: %s", err)
+		return nil, fmt.Errorf("failed to commit transaction: %w", err)
-		return nil, fmt.Errorf("failed to get fee run (post commit): %s", err)
+		return nil, fmt.Errorf("failed to get fee run (post commit): %w", err)

Also applies to: 41-41, 47-47, 53-53

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 33a4336 and 244b62b.

📒 Files selected for processing (7)
  • api/plugin.go (2 hunks)
  • plugin/fees/fees.go (3 hunks)
  • plugin/payroll/transaction.go (3 hunks)
  • service/policy.go (2 hunks)
  • storage/db.go (2 hunks)
  • storage/postgres/fees.go (1 hunks)
  • storage/postgres/policy.go (2 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 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: 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: 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: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.
plugin/payroll/transaction.go (6)
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#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.
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.
api/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: 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.
storage/postgres/policy.go (2)
Learnt from: RaghavSood
PR: vultisig/plugin#75
File: storage/postgres/db_plugin.go:25-40
Timestamp: 2025-05-30T02:44:31.711Z
Learning: The embed.FS directive `//go:embed migrations/plugin/*.sql` in storage/postgres/db_plugin.go correctly embeds plugin migration files that exist in the storage/postgres/migrations/plugin/ directory. The path "migrations/plugin" passed to goose.Up() references the embedded filesystem structure, not the physical file system path.
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.
storage/postgres/fees.go (1)
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.
service/policy.go (1)
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.
storage/db.go (2)
Learnt from: RaghavSood
PR: vultisig/plugin#75
File: storage/postgres/db_plugin.go:25-40
Timestamp: 2025-05-30T02:44:31.711Z
Learning: The embed.FS directive `//go:embed migrations/plugin/*.sql` in storage/postgres/db_plugin.go correctly embeds plugin migration files that exist in the storage/postgres/migrations/plugin/ directory. The path "migrations/plugin" passed to goose.Up() references the embedded filesystem structure, not the physical file system path.
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/fees/fees.go (6)
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: 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: 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: 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 in worker configuration structs across the vultisig/plugin codebase (cmd/payroll/worker/config.go, cmd/fees/worker/config.go, cmd/dca/worker/config.go). It contains an EncryptionSecret field that can be accessed via cfg.VaultServiceConfig.EncryptionSecret.
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.
🧬 Code Graph Analysis (3)
api/plugin.go (1)
internal/types/keysign.go (1)
  • PluginKeysignRequest (7-12)
storage/postgres/policy.go (1)
storage/postgres/db.go (1)
  • PostgresBackend (15-17)
storage/db.go (2)
internal/types/fees.go (2)
  • FeeRunState (11-11)
  • FeeRun (27-36)
internal/verifierapi/fees.go (1)
  • FeeDto (11-20)
⏰ 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). (1)
  • GitHub Check: build
🔇 Additional comments (19)
plugin/fees/fees.go (3)

19-19: LGTM: Import reordering for clarity.

The vault import reordering improves code organization without functional changes.


165-165: LGTM: Correct pointer dereferencing.

The change from policy to *policy correctly dereferences the pointer returned by GetPluginPolicy to pass the value to executeFeeCollection, which expects a vtypes.PluginPolicy value rather than a pointer.


233-233: LGTM: Minor comment formatting improvement.

The formatting adjustment improves comment readability.

api/plugin.go (2)

62-62: LGTM: Correct pointer dereferencing for validation.

The change from policy to *policy correctly dereferences the pointer returned by GetPluginPolicy before passing it to ValidateProposedTransactions, which expects a vtypes.PluginPolicy value.


264-264: LGTM: Correct pointer dereferencing for signature verification.

The change from policy to *policy correctly dereferences the pointer returned by GetPluginPolicy before passing it to verifyPolicySignature, maintaining consistency with the updated return types.

plugin/payroll/transaction.go (3)

22-25: LGTM: Import reordering for clarity.

The import statement reordering improves code organization without affecting functionality.


62-62: LGTM: Correct pointer dereferencing for transaction proposal.

The change from pluginPolicy to *pluginPolicy correctly dereferences the pointer returned by GetPluginPolicy before passing it to ProposeTransactions, which expects a vtypes.PluginPolicy value.


72-72: LGTM: Correct pointer dereferencing for signing initialization.

The change from pluginPolicy to *pluginPolicy correctly dereferences the pointer before passing it to initSign, maintaining consistency with the updated return types.

storage/postgres/policy.go (3)

14-14: LGTM: Method signature updated to return pointer.

The method signature change from vtypes.PluginPolicy to *vtypes.PluginPolicy enables better error handling by distinguishing between "not found" (nil) and "found but empty" (zero value).


16-16: LGTM: Consistent nil returns for error cases.

Returning nil instead of zero values on errors aligns with the pointer return type and provides clearer error semantics.

Also applies to: 36-36


38-38: LGTM: Safe return of local variable address.

Returning &policy is safe here because the policy variable contains data copied during the database scan operation, not a reference to external memory.

service/policy.go (3)

21-21: LGTM: Interface updated to return pointer.

The interface method signature change to return *vtypes.PluginPolicy maintains consistency with the storage layer changes and enables better error handling.


129-129: LGTM: Simplified implementation.

Directly returning the database result eliminates unnecessary intermediate error handling while maintaining the same error propagation behavior.


132-134: LGTM: Consistent pointer return implementation.

The simplified implementation directly returns the pointer from the database layer, maintaining consistency with the updated return types and eliminating unnecessary error wrapping.

storage/postgres/fees.go (3)

14-14: LGTM: Function signature update improves error handling.

The change from returning a value type to a pointer type aligns with the PR objective of improving error handling and is consistent with the interface definition in storage/db.go.


29-31: LGTM: Improved transaction handling with deferred rollback.

The addition of defer tx.Rollback(ctx) is a good practice that ensures the transaction is rolled back on early returns or panics. The rollback will be a no-op if the transaction has already been committed.


56-56: LGTM: Return statement correctly returns pointer.

The change from return run, nil to return &run, nil is consistent with the updated function signature and provides better error handling semantics.

storage/db.go (2)

18-18: LGTM: Interface method signature update is consistent.

The change from (vtypes.PluginPolicy, error) to (*vtypes.PluginPolicy, error) aligns with the implementation changes and improves error handling by allowing nil returns on errors.


33-33: LGTM: Interface method signature update matches implementation.

The change from (types.FeeRun, error) to (*types.FeeRun, error) is consistent with the implementation in storage/postgres/fees.go and follows the same pattern as other pointer return types in the interface.

Comment thread storage/postgres/fees.go
@RaghavSood
RaghavSood merged commit 80db263 into main Jul 8, 2025
3 checks passed
@RaghavSood
RaghavSood deleted the fix-return-value branch July 8, 2025 04:01
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.

3 participants