Skip to content

Conversation

@mkysel
Copy link
Collaborator

@mkysel mkysel commented May 23, 2025

Implement V4 rates contract integration by adding rate management functionality to CLI and blockchain packages

  • Adds new add-rates CLI command in main.go for managing fee rates through the rate registry
  • Expands RatesAdmin struct in ratesAdmin.go with parameter contract integration and rate validation
  • Implements incremental rate fetching in contractRates.go using currentIndex tracking
  • Adds comprehensive test coverage for rate management in ratesAdmin_test.go
  • Updates configuration structures in cliOptions.go to support rate registry administration

📍Where to Start

Start with the addRates function in main.go which implements the new CLI command functionality and shows the high-level flow of rate management.


Macroscope summarized f7e022b.

Summary by CodeRabbit

  • New Features
    • Introduced a new CLI command to add fee rates to the rates manager.
    • Enhanced support for setting multiple rate parameters atomically via the parameter registry contract.
  • Bug Fixes
    • Improved pagination handling for rate fetching to support incremental loading of rates.
  • Refactor
    • Updated CLI and configuration structures for better management of admin options and required fields.
    • Streamlined internal admin setup and contract management for rate registry operations.
  • Tests
    • Added comprehensive tests for rate addition, validation, and pagination behaviors.

@mkysel mkysel requested a review from a team as a code owner May 23, 2025 13:43
@graphite-app
Copy link

graphite-app bot commented May 23, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Queue - adds this PR to the back of the merge queue
  • Hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 23, 2025

"""

Walkthrough

This update introduces a new CLI command "add-rates" for setting fee rates, extends the RatesAdmin component to support atomic multi-parameter updates via a parameter registry contract, adds encoding helpers and detailed event parsing, refactors CLI options for rate administration, and enhances contract rate fetching with persistent pagination state. It also adds comprehensive tests for the new rate addition functionality and improves event logging in registry admin.

Changes

File(s) Change Summary
cmd/cli/main.go Adds "add-rates" CLI command with handler; introduces addRates and setupRateRegistryAdmin; renames/refactors node registry admin setup.
pkg/blockchain/ratesAdmin.go Extends RatesAdmin with parameter registry contract; adds AddRates method for atomic multi-parameter update; adds encoding helpers; removes old contract accessor.
pkg/blockchain/ratesAdmin_test.go Adds tests for RatesAdmin.AddRates covering positive, negative, zero, large, and repeated rate additions with test blockchain setup.
pkg/blockchain/registryAdmin.go Updates event logging in SetMaxCanonical to decode full uint64 from 32-byte array instead of single byte.
pkg/config/cliOptions.go Adds RateRegistryAdminOptions; refactors AddRatesOptions to embed admin options; changes fee fields to currency.PicoDollar with required tags; removes DelayDays.
pkg/fees/contractRates.go Adds persistent currentIndex field to ContractRatesFetcher for pagination; updates refresh logic to use it.
pkg/fees/contractRates_test.go Updates fetcher test setup to initialize currentIndex; adds test for incremental rate loading; modifies existing tests to use refreshData.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant RatesAdmin
    participant ParameterContract
    participant RatesContract

    User->>CLI: invoke "add-rates" with fees
    CLI->>RatesAdmin: AddRates(fees)
    RatesAdmin->>ParameterContract: set message, storage, congestion, target rates
    ParameterContract-->>RatesAdmin: emit ParameterSet events
    RatesAdmin->>RatesContract: UpdateRates(fees)
    RatesContract-->>RatesAdmin: emit RatesUpdated event
    RatesAdmin-->>CLI: success or error
    CLI-->>User: output result
Loading

Possibly related PRs

  • xmtp/xmtpd#608: Improves robustness of AddRates tests with retry logic around contract calls, related to this PR's expanded AddRates tests.
  • xmtp/xmtpd#575: Initial implementation of RatesAdmin functionality, which this PR extends with parameter registry support and CLI integration.
  • xmtp/xmtpd#610: Adds TargetRatePerMinute support in rates management, now integrated into this PR's CLI and RatesAdmin logic.

Suggested reviewers

  • fbac
    """

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)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 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 05df6bd and c4b4a7b.

📒 Files selected for processing (1)
  • cmd/cli/main.go (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/cli/main.go
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Test (Node)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
  • GitHub Check: Upgrade Tests
  • GitHub Check: Code Review
✨ 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.

return err
}

fromIndex := big.NewInt(0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not starting from 0 is an optimization that was not possible before I believe.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (3)
pkg/blockchain/registryAdmin.go (1)

258-258: Verify logging consistency with stored value.

The code stores a uint8 value in the last byte of the 32-byte array (line 241: value[31] = limit), but the logging decodes the entire 32-byte array as a uint64. While this may be technically correct for the new encoding scheme, ensure this logging approach accurately represents the stored value to avoid confusion in logs.

pkg/fees/contractRates.go (1)

113-140: Good pagination logic with minor optimization opportunity.

The pagination implementation correctly uses persistent currentIndex to enable incremental loading. However, line 140 has a redundant assignment since big.Int.Add() modifies the receiver in-place.

Consider simplifying line 140:

-		c.currentIndex = c.currentIndex.Add(c.currentIndex, toFetch)
+		c.currentIndex.Add(c.currentIndex, toFetch)

Note: This implementation assumes rates are append-only (never modified or removed). This is reasonable for typical rate contracts where rates represent historical periods.

pkg/blockchain/ratesAdmin.go (1)

93-101: Minor: Error message accuracy.

The error messages say "must be positive" but the validation allows zero values. Consider updating for clarity.

 if rates.MessageFee < 0 {
-  return nil, errors.New("rates.messageFee must be positive")
+  return nil, errors.New("rates.messageFee must be non-negative")
 }
 if rates.StorageFee < 0 {
-  return nil, errors.New("rates.storageFee must be positive")
+  return nil, errors.New("rates.storageFee must be non-negative")
 }
 if rates.CongestionFee < 0 {
-  return nil, errors.New("rates.congestionFee must be positive")
+  return nil, errors.New("rates.congestionFee must be non-negative")
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 464ae0f and f7e022b.

📒 Files selected for processing (7)
  • cmd/cli/main.go (13 hunks)
  • pkg/blockchain/ratesAdmin.go (2 hunks)
  • pkg/blockchain/ratesAdmin_test.go (1 hunks)
  • pkg/blockchain/registryAdmin.go (1 hunks)
  • pkg/config/cliOptions.go (2 hunks)
  • pkg/fees/contractRates.go (3 hunks)
  • pkg/fees/contractRates_test.go (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/fees/contractRates_test.go (1)
pkg/abi/rateregistry/RateRegistry.go (1)
  • IRateRegistryRates (33-39)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Code Review
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
  • GitHub Check: Upgrade Tests
  • GitHub Check: Test (Node)
🔇 Additional comments (21)
pkg/config/cliOptions.go (2)

14-18: LGTM! Consistent pattern implementation.

The new RateRegistryAdminOptions struct follows the same pattern as NodeRegistryAdminOptions, maintaining consistency in the codebase.


60-65: LGTM! Improved structure and validation.

The refactoring properly embeds the admin options and makes all fee fields required, which improves input validation and follows CLI best practices.

pkg/fees/contractRates_test.go (3)

30-30: LGTM! Proper initialization for new pagination field.

The addition of currentIndex: big.NewInt(0) correctly initializes the new pagination state field.


57-57: LGTM! Appropriate test method changes.

Changing from fetcher.Start() to fetcher.refreshData() allows direct testing of the data fetching logic without the background goroutine, which is more appropriate for unit tests.

Also applies to: 83-83, 109-109, 144-144, 162-162, 194-194, 199-199


177-201: LGTM! Comprehensive test for incremental loading.

The new TestCanContinue test effectively validates the incremental loading behavior when the total rate count increases, ensuring the pagination logic works correctly across multiple refresh cycles.

pkg/fees/contractRates.go (2)

50-50: LGTM! Proper field addition for pagination state.

The addition of the currentIndex field and its initialization enables persistent pagination state across multiple refresh calls.

Also applies to: 74-74


111-111: LGTM! Preserves existing rates during incremental loading.

Appending existing rates ensures that previously loaded data is preserved when fetching additional rates incrementally.

pkg/blockchain/ratesAdmin_test.go (6)

15-34: LGTM! Well-structured test helper.

The helper function properly sets up the test environment with appropriate error handling.


36-48: LGTM! Good coverage of the happy path.

The test validates successful rate addition with reasonable values.


50-67: LGTM! Comprehensive validation testing.

The test properly validates that negative fees are rejected with appropriate error messages.


69-79: LGTM! Validates zero rates are acceptable.

Good edge case testing - zero rates should be allowed as they may represent free operations.


81-91: LGTM! Excellent boundary value testing.

Tests maximum values to ensure the system handles large numbers without overflow issues.


93-108: LGTM! Good idempotency testing.

Tests that rates can be added multiple times without errors, which is important for system resilience.

cmd/cli/main.go (4)

9-9: LGTM! Appropriate imports for fee validation and currency conversion.

The imports support the new rate management functionality.

Also applies to: 16-17


103-105: LGTM! CLI command properly integrated.

The new "add-rates" command follows the existing CLI pattern.

Also applies to: 650-652


665-699: LGTM! Clear function naming and consistent parameter usage.

The rename to setupNodeRegistryAdmin better distinguishes it from the new setupRateRegistryAdmin function.


701-736: LGTM! Well-structured helper function.

The function properly sets up the rate registry admin with appropriate error handling.

pkg/blockchain/ratesAdmin.go (4)

20-25: LGTM! Well-defined parameter key constants.

The constants follow a consistent naming pattern and clearly identify rate registry parameters.


32-69: LGTM! Proper multi-contract initialization.

The struct and constructor correctly support the two-contract architecture for parameter and rate management.


71-174: LGTM! Robust two-phase transaction implementation.

The method properly handles the parameter setting and rate update sequence with comprehensive event logging and graceful "NoChange" error handling.


176-184: LGTM! Correct encoding/decoding implementation.

The helper functions properly handle uint64 values in 32-byte arrays using big-endian encoding, which is standard for Ethereum parameter storage.

@macroscopeapp
Copy link

macroscopeapp bot commented May 23, 2025

Add V4 rates contract support by implementing add-rates CLI command and RatesAdmin functionality for managing blockchain rate configurations

  • Implements new add-rates CLI command in main.go for managing rate configurations
  • Creates new RatesAdmin implementation in ratesAdmin.go with methods for setting message fees, storage fees, congestion fees, and target rates
  • Updates ContractRatesFetcher in contractRates.go to track rate fetch state and incrementally append new rates
  • Adds comprehensive test coverage in ratesAdmin_test.go for rate management functionality
  • Modifies cliOptions.go to use currency.PicoDollar types for fee values

📍Where to Start

Start with the parseOptions function in main.go which adds the new add-rates command, then review the core implementation in the RatesAdmin struct within ratesAdmin.go.

Changes since #833 opened

  • Modified error handling in blockchain client initialization functions [c4b4a7b]

Macroscope summarized c4b4a7b.

@mkysel mkysel merged commit 15f572e into main May 23, 2025
10 checks passed
@mkysel mkysel deleted the mkysel/rates branch May 23, 2025 15:11
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.

3 participants