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

Get target rate per minute from smart contract #610

Draft
wants to merge 1 commit into
base: 03-10-calculate_congestion_from_last_5_minutes_of_data
Choose a base branch
from

Conversation

neekolas
Copy link
Contributor

@neekolas neekolas commented Mar 10, 2025

TL;DR

Added target rate per minute parameter to the rates manager contract and related components.

What changed?

  • Added TargetRatePerMinute field to the RatesManagerRates struct
  • Updated addRates() function signature to accept the new parameter
  • Modified the RatesAdded event to include target rate
  • Updated CLI options to accept --target-rate flag
  • Added target rate handling in fees package and tests
  • Updated contract tests to verify target rate functionality

How to test?

  1. Deploy updated contract
  2. Add new rates using CLI with target rate parameter:
./cli add-rates --message-fee 100 --storage-fee 200 --congestion-fee 300 --target-rate 6000
  1. Verify rates are stored correctly by querying the contract
  2. Check that target rate is included in emitted events

Why make this change?

To support rate limiting functionality by allowing configuration of target message processing rates per minute for each node. This enables better control over network congestion and resource utilization.

Summary by CodeRabbit

  • New Features

    • Added a new "target rate per minute" parameter to enhance rates management across the platform.
    • Updated user configuration options and on-chain events to support the new rate setting.
  • Tests

    • Expanded test coverage to ensure the new target rate functionality works as expected for all components.

Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

This pull request adds a new field, TargetRatePerMinute, across several parts of the project. The new field is included in the rate structures and passed as an additional parameter in various functions, such as AddRates, in both the CLI and blockchain contract code. Corresponding updates have been made to event declarations, ABI definitions, tests, and configuration options to ensure consistent handling of the additional rate parameter.

Changes

Files Change Summary
cmd/cli/main.go
pkg/config/cliOptions.go
Added new field in CLI data structures: TargetRatePerMinute is initialized in the rates struct and introduced as TargetRate in CLI options with an associated CLI flag.
contracts/pkg/ratesmanager/RatesManager.go
contracts/src/RatesManager.sol
Updated the rates struct definitions to include TargetRatePerMinute. Modified the addRates function signatures in Go and Solidity contracts to accept this new parameter. Updated ABI, event declarations, filter/watch methods, and parsing functions to incorporate the additional field.
contracts/test/RatesManager.t.sol Introduced a new constant for targetRatePerMinute and adjusted tests (testAddRatesValid and testAddRatesUnauthorized) to use and verify the new parameter in the rates addition process.
pkg/blockchain/ratesAdmin.go
pkg/blockchain/ratesAdmin_test.go
Updated the AddRates method to forward the additional parameter (TargetRatePerMinute) from the rates struct and adjusted tests to include and validate this field when constructing the RatesManagerRates instance.
pkg/fees/contractRates.go
pkg/fees/contractRates_test.go
pkg/fees/interface.go
Modified the transformation functions and interfaces by adding the TargetRatePerMinute field to the corresponding rate structs. Updated the test assertions to verify the inclusion and proper value assignment of the new field.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI Application
    participant Admin as RatesAdmin
    participant RM as RatesManager Contract
    participant BC as Blockchain

    CLI->>Admin: Prepare rates including TargetRatePerMinute via CLI options
    Admin->>RM: Call AddRates(messageFee, storageFee, congestionFee, startTime, targetRatePerMinute)
    RM-->>BC: Execute transaction with all rate parameters
    BC-->>RM: Return transaction confirmation
    RM->>Admin: Confirm rates addition (emit RatesAdded with targetRatePerMinute)
    Admin->>CLI: Return success/failure status
Loading

Possibly related PRs

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.62.2)

Error: can't load config: the Go language version (go1.23) used to build golangci-lint is lower than the targeted Go version (1.24)
Failed executing command with error: can't load config: the Go language version (go1.23) used to build golangci-lint is lower than the targeted Go version (1.24)

✨ 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.
    • 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.

Copy link
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@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 (5)
contracts/src/RatesManager.sol (5)

18-18: Inconsistent ordering of fields in event declaration

The order of parameters in the RatesAdded event (targetRatePerMinute before startTime) doesn't match the order in the Rates struct declaration (where startTime is before targetRatePerMinute). This inconsistency could lead to confusion during maintenance.

Consider keeping the order consistent between the event parameters and struct fields:

- event RatesAdded(uint64 messageFee, uint64 storageFee, uint64 congestionFee, uint64 targetRatePerMinute, uint64 startTime);
+ event RatesAdded(uint64 messageFee, uint64 storageFee, uint64 congestionFee, uint64 startTime, uint64 targetRatePerMinute);

35-35: Missing documentation for new field

The targetRatePerMinute field has been added without any documentation explaining its purpose or constraints.

Consider adding a comment to explain what this field represents and any constraints on its values.


77-78: Parameter order inconsistency

The parameter order in the function signature (startTime then targetRatePerMinute) doesn't match the order in the struct initialization in lines 91-92 (where startTime is assigned before targetRatePerMinute).

To maintain consistency, consider either:

- function addRates(uint64 messageFee, uint64 storageFee, uint64 congestionFee, uint64 startTime, uint64 targetRatePerMinute)
+ function addRates(uint64 messageFee, uint64 storageFee, uint64 congestionFee, uint64 targetRatePerMinute, uint64 startTime)

Or rearrange the field assignments in the struct initialization to match the parameter order.


86-94: Inconsistent field order in struct initialization

The order of fields in this struct initialization doesn't match the order of parameters in the function signature. In the function parameters, startTime comes before targetRatePerMinute, but in the initialization, startTime is assigned before targetRatePerMinute.

To maintain consistency, consider rearranging the field assignments to match the parameter order:

Rates({
    messageFee: messageFee,
    storageFee: storageFee,
    congestionFee: congestionFee,
-   startTime: startTime,
-   targetRatePerMinute: targetRatePerMinute
+   targetRatePerMinute: targetRatePerMinute,
+   startTime: startTime
})

This would match the parameter order in the function signature.


96-96: Event emission parameter order inconsistency

The order of parameters in the RatesAdded event emission (targetRatePerMinute before startTime) is inconsistent with the parameter order in the function signature (where startTime is before targetRatePerMinute).

Consider adjusting the event emission to maintain consistent parameter ordering:

- emit RatesAdded(messageFee, storageFee, congestionFee, targetRatePerMinute, startTime);
+ emit RatesAdded(messageFee, storageFee, congestionFee, startTime, targetRatePerMinute);

This would match the parameter order in the function signature.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2ecea2e and b4baa55.

📒 Files selected for processing (10)
  • cmd/cli/main.go (1 hunks)
  • contracts/pkg/ratesmanager/RatesManager.go (8 hunks)
  • contracts/src/RatesManager.sol (4 hunks)
  • contracts/test/RatesManager.t.sol (3 hunks)
  • pkg/blockchain/ratesAdmin.go (1 hunks)
  • pkg/blockchain/ratesAdmin_test.go (1 hunks)
  • pkg/config/cliOptions.go (1 hunks)
  • pkg/fees/contractRates.go (1 hunks)
  • pkg/fees/contractRates_test.go (2 hunks)
  • pkg/fees/interface.go (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Test
contracts/test/RatesManager.t.sol

[error] 1-1: Tests failed: 3 tests failed (testAddRatesChronologicalOrder, testAddRatesValid, testGetRatesPagination) with errors related to InvalidStartTime and log mismatch.

🪛 GitHub Actions: Solidity
contracts/test/RatesManager.t.sol

[error] 1-1: Test failed: InvalidStartTime() in testAddRatesChronologicalOrder()


[error] 1-1: Test failed: log != expected log in testAddRatesValid()


[error] 1-1: Test failed: InvalidStartTime() in testGetRatesPagination()

🔇 Additional comments (21)
pkg/config/cliOptions.go (1)

46-46: LGTM - Field added for target rate per minute

The addition of the TargetRate field to the AddRatesOptions struct is clean and follows the same pattern as other rate-related fields in the struct.

pkg/fees/interface.go (1)

12-15: LGTM - New field for target rate per minute added

The TargetRatePerMinute field has been properly added to the Rates struct with an appropriate type and descriptive comment. The formatting changes to align the field types and comments also improve readability.

pkg/blockchain/ratesAdmin_test.go (1)

39-45: LGTM - Test updated with target rate per minute

The test has been properly updated to include the new TargetRatePerMinute field with a reasonable test value of 100 * 60 (which appears to convert a per-second rate to per-minute).

pkg/fees/contractRates.go (1)

211-214: LGTM - Transform function updated with target rate per minute

The transformRates function has been properly updated to include the new TargetRatePerMinute field when creating a Rates struct from the contract data.

contracts/test/RatesManager.t.sol (3)

22-22: Good addition of targetRatePerMinute constant

The new constant is appropriately defined with a clear value calculation (100 * 60).


65-65: Function call parameters updated correctly

The direct call to ratesManager.addRates includes the new targetRatePerMinute parameter, which is consistent with other changes.


41-41:

✅ Verification successful

Verify event signature matches implementation

The expected event now includes targetRatePerMinute. Ensure this matches the actual event definition in the contract.


🏁 Script executed:

#!/bin/bash
# Verify the RatesAdded event signature in the RatesManager contract
grep -A 3 "event RatesAdded" contracts/src/RatesManager.sol

Length of output: 302


Verified: RatesAdded event signature is correctly updated

The event definition in contracts/src/RatesManager.sol matches the emitted parameters in the test file. The expected targetRatePerMinute is present and its type aligns with the implementation.

cmd/cli/main.go (1)

425-431:

✅ Verification successful

Properly updated struct initialization with new field

The RatesManagerRates struct initialization now includes the TargetRatePerMinute field, which is set from options.AddRates.TargetRate. This is consistent with the changes in other files.


🏁 Script executed:

#!/bin/bash
# Verify that the TargetRate option is defined in the AddRatesOptions struct
grep -A 10 "type AddRatesOptions struct" pkg/config/cliOptions.go

Length of output: 807


Updated Struct Initialization Verified

The updated initialization in cmd/cli/main.go correctly maps the TargetRate from options.AddRates to the new TargetRatePerMinute field in the RatesManagerRates struct. Verification confirms that the TargetRate field is properly defined in the AddRatesOptions struct in pkg/config/cliOptions.go.

No further changes are necessary.

pkg/fees/contractRates_test.go (2)

34-42: Good update to test helper function

The buildRates function has been properly updated to include the new TargetRatePerMinute field with a consistent value (100 * 60).


58-59: Good test coverage for new field

The test assertions for the new TargetRatePerMinute field ensure that the value is correctly set in the rates fetched from the contract.

pkg/blockchain/ratesAdmin.go (1)

54-69: Function implementation updated correctly

The AddRates method has been properly updated to include the new rates.TargetRatePerMinute parameter in the contract call, which is consistent with the changes in other files.

contracts/pkg/ratesmanager/RatesManager.go (10)

33-39: Struct update looks good

The RatesManagerRates struct has been correctly updated to include the new TargetRatePerMinute field in line with the Solidity contract changes.


43-43: ABI string updated correctly

The ABI string has been properly updated to reflect the changes in the contract interface including the new parameter.


538-543: Function signature update looks good

The AddRates function signature has been correctly updated to include the new targetRatePerMinute parameter, matching the changes in the Solidity contract.


547-550: Session method signature update looks good

The RatesManagerSession.AddRates method signature has been properly updated to match the contract changes.


554-557: TransactorSession method signature update looks good

The RatesManagerTransactorSession.AddRates method signature has been properly updated to match the contract changes.


1043-1049: Event struct update looks good

The RatesManagerRatesAdded event struct has been correctly updated to include the new TargetRatePerMinute field.


1051-1054: Event filter method update looks good

The FilterRatesAdded method comment has been updated correctly to reflect the new event signature.


1063-1066: Event watch method update looks good

The WatchRatesAdded method comment has been updated correctly to reflect the new event signature.


1100-1103: Event parse method update looks good

The ParseRatesAdded method comment has been updated correctly to reflect the new event signature.


1-2: Be cautious with auto-generated code

This file is auto-generated and manual changes could be overwritten. Ensure that the source code generation templates have been updated to include the new field, as indicated at the top of the file.

Verify that the code generation process has been updated to include the new field by checking if there are changes to the generation templates or configurations in the PR.

@@ -30,14 +31,14 @@ contract RatesTest is Test {
}

function addRate(uint64 startTime) internal {
ratesManager.addRates(messageFee, storageFee, congestionFee, startTime);
ratesManager.addRates(messageFee, storageFee, congestionFee, targetRatePerMinute, startTime);
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify function signature matches contract implementation

The addRate function has been updated to include targetRatePerMinute parameter. The pipeline failures suggest there might be issues with parameter ordering or event signatures.


🏁 Script executed:

#!/bin/bash
# Verify the addRates function signature in the RatesManager contract
grep -A 5 "function addRates" contracts/src/RatesManager.sol

Length of output: 380


Action: Correct parameter ordering in addRates call

The function signature in contracts/src/RatesManager.sol is defined as:

function addRates(
    uint64 messageFee,
    uint64 storageFee,
    uint64 congestionFee,
    uint64 startTime,
    uint64 targetRatePerMinute
)

However, the test in contracts/test/RatesManager.t.sol (line 34) calls the function as follows:

ratesManager.addRates(messageFee, storageFee, congestionFee, targetRatePerMinute, startTime);

This is passing targetRatePerMinute before startTime, which does not match the contract implementation. Please update the test call to:

ratesManager.addRates(messageFee, storageFee, congestionFee, startTime, targetRatePerMinute);

This should resolve the pipeline failures.

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