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

feat(platform)!: matched withdrawal fees to actual processing cost #2186

Merged
merged 3 commits into from
Sep 30, 2024

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Sep 30, 2024

Issue being fixed or feature implemented

This PR addresses the need to better match withdrawal fees to the actual processing costs, ensuring that fees reflect the workload incurred by the platform when processing withdrawals. It solves discrepancies between the previously estimated fees and the actual cost incurred during the withdrawal process, leading to a more accurate and fair fee calculation.

What was done?

Added a fee of around 2.5 cents at a Dash price of 25$ for withdrawals.

How Has This Been Tested?

Needs testing on Testnet, not yet tested.

Breaking Changes

Since fees change it is is a breaking change that will take effect in v4 of the protocol.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced a new validation operation for network threshold signing.
    • Enhanced validation logic for identity credit withdrawals to ensure sufficient balance checks.
  • Bug Fixes

    • Updated processing fees for identity credit withdrawal operations to reflect new fee structures.
  • Documentation

    • Updated tests to ensure equality checks account for new fields in fee structures and validation operations.
  • Refactor

    • Improved method signatures and logic to incorporate execution context for better state transition handling.

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 41 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between f57a0b3 and 9e17bae.

Walkthrough

The changes introduce several new features and modifications to existing structures within the codebase. A new variant, PerformNetworkThresholdSigning, is added to the ValidationOperation enum, enhancing fee calculation for network threshold signing operations. Additionally, a new trait for validating identity credit transfers is introduced, improving balance checks. Method signatures across various modules are updated to include an execution_context, allowing for more integrated state transition handling. Fee structures are also modified, particularly for credit withdrawals, reflecting significant cost adjustments.

Changes

File Path Change Summary
packages/rs-drive-abci/src/execution/types/execution_operation/mod.rs Added PerformNetworkThresholdSigning variant to ValidationOperation enum and updated fee calculation logic.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/balance/v0/mod.rs Introduced IdentityCreditTransferTransitionBalanceValidationV0 trait with a new balance validation method.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/mod.rs Updated method signatures in IdentityCreditWithdrawalTransition to include execution_context.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/state/v0/mod.rs Modified validate_state_v0 and transform_into_action_v0 methods to include execution_context.
packages/rs-platform-version/src/version/fee/mod.rs Updated FeeProcessingVersion struct, added perform_network_threshold_signing, and modified existing fields.
packages/rs-platform-version/src/version/fee/processing/mod.rs Added perform_network_threshold_signing field to FeeProcessingVersion struct.
packages/rs-platform-version/src/version/fee/processing/v1.rs Introduced constant perform_network_threshold_signing with a value of 100000000.
packages/rs-platform-version/src/version/fee/state_transition_min_fees/v1.rs Updated credit_withdrawal fee value from 100000 to 400000000.

Suggested reviewers

  • shumkov
  • lklimek

🐰 In fields of code where rabbits play,
New features hop in, brightening the day!
With fees adjusted and checks so fine,
Our system's ready, it's truly divine!
So let’s celebrate with a joyful cheer,
For every change brings us closer, my dear! 🥕


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

@QuantumExplorer QuantumExplorer added this to the v1.4.0 milestone Sep 30, 2024
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: 4

🧹 Outside diff range and nitpick comments (7)
packages/rs-platform-version/src/version/fee/processing/mod.rs (2)

13-13: LGTM. Consider adding documentation for the new field.

The addition of perform_network_threshold_signing aligns with the PR objective of updating the fee structure. This new field likely represents the cost associated with performing network threshold signing operations.

Consider adding a doc comment to explain the purpose and unit of measurement for this new field. For example:

/// Cost of performing network threshold signing operations, measured in [unit].
pub perform_network_threshold_signing: u64,

30-32: LGTM. Consider updating the test values for clarity.

The test function has been correctly updated to include the new perform_network_threshold_signing field. The equality check remains valid and will help catch any future changes to the struct.

For improved readability and easier maintenance, consider updating the test values to follow a more obvious pattern. For example:

let version1 = FeeProcessingVersion {
    fetch_identity_balance_processing_cost: 1,
    fetch_identity_revision_processing_cost: 2,
    fetch_identity_balance_and_revision_processing_cost: 3,
    fetch_identity_cost_per_look_up_key_by_id: 4,
    fetch_single_identity_key_processing_cost: 5,
    perform_network_threshold_signing: 6,
    validate_key_structure: 7,
    fetch_prefunded_specialized_balance_processing_cost: 8,
};

let version2 = FeeProcessingVersion {
    fetch_identity_balance_processing_cost: 1,
    fetch_identity_revision_processing_cost: 2,
    fetch_identity_balance_and_revision_processing_cost: 3,
    fetch_identity_cost_per_look_up_key_by_id: 4,
    fetch_single_identity_key_processing_cost: 5,
    perform_network_threshold_signing: 6,
    validate_key_structure: 7,
    fetch_prefunded_specialized_balance_processing_cost: 8,
};

This makes it easier to spot any discrepancies at a glance.

Also applies to: 41-43

packages/rs-platform-version/src/version/fee/mod.rs (1)

Line range hint 1-174: Overall assessment: Changes align with PR objectives, but consider broader implications.

The modifications to the FeeProcessingVersion struct and the corresponding test updates are well-implemented and align with the PR objective of matching withdrawal fees to actual processing costs. However, consider the following recommendations:

  1. Document the rationale behind the specific cost changes, especially the increase in fetch_prefunded_specialized_balance_processing_cost.
  2. Assess the impact of these changes on overall fee calculations in the platform.
  3. Ensure that any dependent modules or services are updated to accommodate these changes.
  4. Consider adding more granular tests to verify the behavior of individual fee components.

To ensure a smooth transition and maintain system integrity:

  1. Review and update any documentation related to fee structures.
  2. Conduct thorough integration testing to verify that these changes don't introduce unexpected behavior in other parts of the system.
  3. Consider implementing a feature flag or gradual rollout strategy to monitor the impact of these fee changes in production.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/balance/v0/mod.rs (3)

Line range hint 15-22: Inconsistent naming: 'Transfer' vs 'Withdrawal' in trait name

The trait is named IdentityCreditTransferTransitionBalanceValidationV0, but it is implemented for IdentityCreditWithdrawalTransition. To maintain consistency and avoid confusion, consider renaming the trait to IdentityCreditWithdrawalTransitionBalanceValidationV0.


Line range hint 24-46: Add unit tests for the new validation method

It's important to add unit tests for the validate_advanced_minimum_balance_pre_check_v0 method to ensure its correctness and prevent future regressions.

Would you like me to help generate the unit tests or open a new GitHub issue to track this task?


Line range hint 37-37: Simplify the condition to improve readability

The condition within the if statement is complex and can be simplified for better readability. Consider breaking down the expression into intermediate variables.

Here's a suggestion:

let required_balance = self.amount()
    .checked_add(platform_version.fee_version.state_transition_min_fees.credit_withdrawal)
    .ok_or(Error::Execution(ExecutionError::Overflow(
        "overflow when adding amount and min_leftover_credits_before_processing in identity credit withdrawal",
    )))?;

if balance < required_balance {
    return Ok(SimpleConsensusValidationResult::new_with_error(
        IdentityInsufficientBalanceError::new(self.identity_id(), balance, self.amount()).into(),
    ));
}
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/mod.rs (1)

Line range hint 75-83: Update known_versions to include all supported versions

In the error handling of the validate_basic_structure method, the known_versions vector currently includes only version 0. Since version 1 is also handled in this method (as seen with Some(1)), the known_versions should be updated to include both versions for accurate error reporting.

Apply this diff to update the known_versions:

                 Some(version) => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
                     method: "identity credit withdrawal transition: validate_basic_structure"
                         .to_string(),
-                    known_versions: vec![0],
+                    known_versions: vec![0, 1],
                     received: version,
                 })),
                 None => Err(Error::Execution(ExecutionError::VersionNotActive {
                     method: "identity credit withdrawal transition: validate_basic_structure"
                         .to_string(),
-                    known_versions: vec![0],
+                    known_versions: vec![0, 1],
                 })),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 404d6d7 and f57a0b3.

📒 Files selected for processing (8)
  • packages/rs-drive-abci/src/execution/types/execution_operation/mod.rs (2 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/balance/v0/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/mod.rs (4 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/state/v0/mod.rs (6 hunks)
  • packages/rs-platform-version/src/version/fee/mod.rs (2 hunks)
  • packages/rs-platform-version/src/version/fee/processing/mod.rs (3 hunks)
  • packages/rs-platform-version/src/version/fee/processing/v1.rs (1 hunks)
  • packages/rs-platform-version/src/version/fee/state_transition_min_fees/v1.rs (1 hunks)
🔇 Additional comments (16)
packages/rs-platform-version/src/version/fee/state_transition_min_fees/v1.rs (3)

5-5: Significant increase in credit withdrawal fee requires explanation and documentation.

The credit_withdrawal fee has been increased from 100000 to 400000000, which is a 4000x increase. While the comment indicates that credit withdrawals are more expensive than other operations, this substantial change warrants further explanation and documentation.

Could you please provide more context on this change?

  1. What are the actual processing costs that justify this increase?
  2. How will this affect users of the platform?
  3. Are there any plans to communicate this change to users?

Additionally, consider updating the documentation to reflect this significant change and its rationale. This will help maintain transparency and avoid potential user confusion or dissatisfaction.

Given the magnitude of this change, consider implementing a more flexible fee structure that can be adjusted without code changes, such as:

  1. Storing fee values in a database or configuration file.
  2. Implementing a fee calculation algorithm that takes into account various factors (e.g., network load, transaction volume).

This would allow for easier future adjustments and potentially a more nuanced fee structure.


5-5: Update PR description with specific details about the fee change.

The change aligns with the PR title "feat(platform)!: matched withdrawal fees to actual processing cost". However, the PR description lacks specific details about this significant fee increase.

Please update the PR description to include:

  1. The specific issue being addressed (e.g., discrepancy between previous fees and actual costs).
  2. Detailed explanation of the changes implemented (e.g., why 400000000 was chosen as the new fee).
  3. Any potential impact on users or the system.
  4. Testing procedures to ensure the new fee structure works as intended.

This information will help reviewers and future maintainers understand the rationale behind this significant change.


Line range hint 3-11: Consider reviewing the entire fee structure for consistency.

While the credit withdrawal fee has been significantly increased, all other fees remain at 100000. This large discrepancy raises questions about the overall fee structure.

  1. Have the processing costs for other operations been reviewed as well?
  2. Is there a reason why only the credit withdrawal fee needed such a significant adjustment?
  3. Should we consider adjusting other fees to maintain a consistent ratio or relationship between different operation costs?

Consider conducting a comprehensive review of all fees to ensure they accurately reflect current processing costs and maintain a logical relationship to each other.

packages/rs-platform-version/src/version/fee/processing/mod.rs (1)

Line range hint 1-49: Consider broader implications and update documentation.

The changes to FeeProcessingVersion align well with the PR objective of updating the fee structure. However, there are a few additional considerations:

  1. Ensure that all components using FeeProcessingVersion are updated to handle the new perform_network_threshold_signing field.
  2. Update any relevant documentation or API references to reflect this change in the fee structure.
  3. Consider adding unit tests that specifically validate the behavior of the new perform_network_threshold_signing field in various scenarios.

To verify the impact of these changes, you can run the following script:

This script will help identify areas of the codebase that might need attention due to the changes in FeeProcessingVersion.

packages/rs-platform-version/src/version/fee/mod.rs (2)

133-135: LGTM: Test case updated correctly.

The test_fee_version_equality test case has been properly updated to reflect the changes in the FeeProcessingVersion struct. This is crucial for maintaining the integrity of the FeeVersion equality checks.

Some points to consider:

  1. The test now includes the new perform_network_threshold_signing field.
  2. The order of fields in the test matches the new order in the struct.
  3. The updated value for fetch_prefunded_specialized_balance_processing_cost is correctly reflected.

This update helps ensure that any future changes to the FeeVersion struct will be caught by the test, preventing potential bugs related to fee calculations or comparisons.


75-77: Verify the updated fee structure and its implications.

The changes to the FeeProcessingVersion struct align with the PR objective of matching withdrawal fees to actual processing costs. However, please consider the following:

  1. The addition of perform_network_threshold_signing suggests a new operation being accounted for in fee calculations. Ensure this is documented and its impact on overall fees is understood.
  2. The fetch_prefunded_specialized_balance_processing_cost has increased from 7 to 8. Verify if this increase is justified and its potential impact on users.
  3. The reordering of fields might affect serialization/deserialization if not handled carefully.

To ensure these changes are consistently applied and don't introduce breaking changes:

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/state/v0/mod.rs (8)

12-15: Added necessary imports for execution context handling

The imports for ValidationOperation, StateTransitionExecutionContext, and StateTransitionExecutionContextMethodsV0 are correctly added to support the execution context functionality introduced in this update.


26-26: Updated method signature to include execution context

The validate_state_v0 method in the trait now includes execution_context: &mut StateTransitionExecutionContext as a parameter. This allows state validation to interact with the execution context, which is essential for tracking operations during the execution flow.


35-35: Updated method signature to include execution context

Similarly, the transform_into_action_v0 method now accepts execution_context: &mut StateTransitionExecutionContext. This inclusion enables the method to modify the execution context based on the transformation outcome.


48-48: Implemented updated validate_state_v0 method with execution context

In the implementation of validate_state_v0 for IdentityCreditWithdrawalTransition, the added execution_context parameter is correctly propagated, ensuring that the execution context can be utilized within the method.


75-81: Correctly passing execution context to transform_into_action_v0

The call to self.transform_into_action_v0 within validate_state_v0 now includes the execution_context parameter. This ensures that any modifications to the execution context within transform_into_action_v0 are reflected in the overall execution flow.


88-88: Implemented updated transform_into_action_v0 method with execution context

The method signature for transform_into_action_v0 now includes execution_context: &mut StateTransitionExecutionContext, allowing it to add operations to the execution context as needed.


103-107: Adding operation to execution context upon successful validation

When the consensus_validation_result is valid, the code correctly adds ValidationOperation::PerformNetworkThresholdSigning to the execution_context. This ensures that the network threshold signing operation is scheduled only when the validation passes.


26-26: Verify updates to method signatures across the codebase

The method signatures for validate_state_v0 and transform_into_action_v0 now include the execution_context parameter. Please ensure that all implementations and invocations of these methods across the codebase have been updated to match the new signatures to prevent potential compilation errors.

Run the following script to identify any usages of these methods that may need updating:

Also applies to: 35-35, 48-48, 88-88

packages/rs-drive-abci/src/execution/types/execution_operation/mod.rs (1)

70-70: Addition of PerformNetworkThresholdSigning variant

The new PerformNetworkThresholdSigning variant is appropriately added to the ValidationOperation enum and follows the existing naming conventions.

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/mod.rs (1)

36-36: Ensure execution_context is utilized appropriately

The execution_context parameter has been added to the method signature. Please verify that it is being used within the method as intended and that any necessary modifications to the execution context are performed.

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.

2 participants