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

Ongoing fee work#98

Merged
garry-sharp merged 4 commits into
mainfrom
fees4
Jun 20, 2025
Merged

Ongoing fee work#98
garry-sharp merged 4 commits into
mainfrom
fees4

Conversation

@garry-sharp

@garry-sharp garry-sharp commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Introduced a fee plugin system with support for fee collection tasks, configuration options, and integration with a verifier API.
    • Added worker and server executables for managing and processing fee-related operations.
    • Provided new configuration and example files for easier setup and customization of fee-related services.
    • Implemented a command-line tool for creating fee collection policies for plugins.
    • Added API methods and DTOs for retrieving fee histories from the verifier.
  • Improvements

    • Enhanced configuration flexibility with new fields and environment variable overrides.
    • Updated Docker and database initialization scripts for improved reliability and compatibility.
    • Refined logging, error handling, and metrics integration across services.
  • Bug Fixes

    • Improved handling of existing resources in scripts and configuration to prevent errors during setup.
  • Documentation

    • Added example configuration files and in-code documentation for new features and usage scenarios.

Copilot AI review requested due to automatic review settings June 20, 2025 06:59
@coderabbitai

coderabbitai Bot commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update introduces a comprehensive fee collection plugin system for a vault-based application. It adds new configuration modules, a fee plugin with asynchronous task handling, verifier API integration, and supporting scripts for policy creation and testing. The changes also update configuration files, Docker, and SQL scripts, and centralize utility functions for policy encoding and validation.

Changes

Files/Paths Change Summary
.gitignore, docker-compose.yaml, Dockerfile.postgres, config-plugin.yaml, create_buckets.sh, init-scripts/01_create_vultisig_plugin.sql, init-scripts/02_create_vultisig_verifier.sql Updated ignore patterns, Docker image versions, environment variables, and SQL scripts for improved setup and compatibility.
config.example.json, fee_config.example.json Added example configuration files for server and fee plugin settings.
api/plugin.go, common/util.go Centralized policy message encoding in common; removed local helper in API.
api/server_config.go Added VerifierUrl and VaultsFilePath fields to server config.
cmd/fees/server/config.go, cmd/fees/server/main.go, cmd/fees/worker/config.go, cmd/fees/worker/main.go Introduced new server and worker binaries for fee processing, with modular configuration loading.
internal/verifierapi/verifierapi.go, internal/verifierapi/fees.go Added Verifier API client and DTOs for fee history retrieval.
plugin/fees/config.go, plugin/fees/constraints.go, plugin/fees/fees.go, plugin/fees/transaction.go Implemented fee plugin: config structure, task handling, fee collection logic, and transaction construction.
scripts/dev/create_fee_policy/dummy_server.go, scripts/dev/create_fee_policy/main.go Added scripts for creating and testing fee policies, including vault and policy management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FeeWorker
    participant Redis
    participant FeePlugin
    participant VerifierAPI
    participant Vault
    participant Database

    User->>FeeWorker: Enqueue fee collection task (via Asynq)
    FeeWorker->>Redis: Fetch fee collection task
    FeeWorker->>FeePlugin: HandleCollections(task)
    FeePlugin->>VerifierAPI: GetPluginPolicyFees(policyId)
    VerifierAPI-->>FeePlugin: Fee history (pending, collected)
    FeePlugin->>Vault: (if needed) Access vault for signing
    FeePlugin->>Database: (if needed) Update fee collection status
    FeePlugin-->>FeeWorker: Task result (success/failure)
Loading

Possibly related PRs

Poem

In the garden of code where the fee bunnies dwell,
New plugins are hopping, their stories to tell.
With configs and workers, and vaults full of gold,
They chase down the fees, both the new and the old.
As tasks queue up swiftly, and verifiers reply,
The rabbits rejoice—fee logic can fly!
🐇💸

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package session: could not load export data: no export data for "github.com/vultisig/go-wrappers/go-dkls/sessions""
level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package session: could not load export data: no export data for "github.com/vultisig/go-wrappers/go-dkls/sessions""


📜 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 5d607f3 and cfa1025.

📒 Files selected for processing (3)
  • cmd/fees/server/main.go (1 hunks)
  • internal/verifierapi/fees.go (1 hunks)
  • scripts/dev/create_fee_policy/dummy_server.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/verifierapi/fees.go
  • cmd/fees/server/main.go
  • scripts/dev/create_fee_policy/dummy_server.go
✨ 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.

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 establishes the groundwork for a new fee‐collection plugin by adding scripts, server stubs, plugin skeletons, configuration options, and deployment updates.

  • Introduces a create_fee_policy script and a dummy server for local testing
  • Adds a fees plugin skeleton with configuration, task handling, and API integrations
  • Updates deployment artifacts (SQL scripts, Docker, buckets, compose, examples)

Reviewed Changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
scripts/dev/create_fee_policy/main.go CLI to generate and optionally store a fee policy
scripts/dev/create_fee_policy/dummy_server.go Creates a dummy server environment for local tests
plugin/fees/transaction.go Partial buildUSDCEthFeeTransaction implementation
plugin/fees/fees.go Fee plugin core methods and task handler stubs
plugin/fees/constraints.go Fee collection constants and ABI placeholder
plugin/fees/config.go FeeConfig creation helpers and defaults
internal/verifierapi/verifierapi.go Base HTTP client for verifier API calls
internal/verifierapi/fees.go Fetches fee history from verifier service
init-scripts/02_create_vultisig_verifier.sql Add IF NOT EXISTS to DB creation
init-scripts/01_create_vultisig_plugin.sql Add IF NOT EXISTS to DB creation
fee_config.example.json Example JSON for fee plugin configuration
docker-compose.yaml Set POSTGRES_DB to vultisig-plugin
create_buckets.sh mc mb with --ignore-existing
config.example.json Core server config example
config-plugin.yaml Plugin mode and vault path adjustments
common/util.go Shared helpers for policy encoding
cmd/fees/worker/main.go Fee worker Asynq setup and demo enqueue
cmd/fees/worker/config.go Worker config loader
cmd/fees/server/main.go Fee server bootstrap
cmd/fees/server/config.go Server config loader
api/server_config.go Add VerifierUrl and VaultsFilePath to config
api/plugin.go Use common.PolicyToMessageHex for signature check
Dockerfile.postgres Pin to Postgres 17
Comments suppressed due to low confidence (3)

scripts/dev/create_fee_policy/main.go:136

  • The variable name json shadows the imported encoding/json package. Consider renaming the variable (e.g., policyJSON or jsonBytes).
	json, err := json.MarshalIndent(pluginPolicy, "", "  ")

plugin/fees/config.go:94

  • The code calls errors.New but the errors package is not imported. Add import "errors".
	}

plugin/fees/config.go:124

  • The code uses strings.NewReplacer but the strings package is not imported. Add import "strings".
		v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

Comment on lines +89 to +93
defer func() {
if err := client.Close(); err != nil {
fmt.Println("fail to close asynq client,", err)
}
}()

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

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

Deferring client.Close() inside this constructor will close the Asynq client immediately when createDummyServer returns, likely causing the server to operate on a closed client. Remove the defer and handle closing at the appropriate program shutdown point.

Suggested change
defer func() {
if err := client.Close(); err != nil {
fmt.Println("fail to close asynq client,", err)
}
}()

Copilot uses AI. Check for mistakes.
}

//TODO garry
data, err := erc20ABI.Pack("transfer", fp.config.CollectorAddress)

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

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

The ERC-20 transfer ABI requires both a recipient address and an amount to transfer. You are only packing the recipient; you must include the amount parameter.

Suggested change
data, err := erc20ABI.Pack("transfer", fp.config.CollectorAddress)
transferAmount := big.NewInt(int64(amount)) // Convert amount to *big.Int
data, err := erc20ABI.Pack("transfer", fp.config.CollectorAddress, transferAmount)

Copilot uses AI. Check for mistakes.
}

ethFromAddress := ecommon.HexToAddress(ethFromAddressString)
nonce, err := fp.rpcClient.PendingNonceAt(context.Background(), ethFromAddress)

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

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

The error returned by PendingNonceAt is not checked before reassigning err on the next call. Insert an if err != nil check immediately after the nonce retrieval.

Suggested change
nonce, err := fp.rpcClient.PendingNonceAt(context.Background(), ethFromAddress)
nonce, err := fp.rpcClient.PendingNonceAt(context.Background(), ethFromAddress)
if err != nil {
return fmt.Errorf("failed to retrieve nonce: %w", err)
}

Copilot uses AI. Check for mistakes.

@RaghavSood RaghavSood 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.

Broadly LGTM, one nit, non-blocking

Comment thread api/server_config.go
Port int64 `mapstructure:"port" json:"port,omitempty"`
EncryptionSecret string `mapstructure:"encryption_secret" json:"encryption_secret,omitempty"`
VerifierUrl string `mapstructure:"verifier_url" json:"verifier_url,omitempty"` //The url of the verifier (i.e. the counter party to sign transactions).
VaultsFilePath string `mapstructure:"vaults_file_path" json:"vaults_file_path,omitempty"` //This is just for testing locally

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.

Can we create an issue to remove this once s3 testing buckets are available?

Comment thread cmd/fees/worker/main.go
},
)

postgressDB, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)

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.

Suggested change
postgressDB, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)
postgresDB, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)

@garry-sharp
garry-sharp merged commit e8df976 into main Jun 20, 2025
3 checks passed
@garry-sharp
garry-sharp deleted the fees4 branch June 20, 2025 08:10
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