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

Updates to FeeSettings ledger object #758

Merged
merged 10 commits into from
Oct 28, 2024
Merged

Conversation

ckeshava
Copy link
Collaborator

@ckeshava ckeshava commented Oct 16, 2024

High Level Overview of Change

This PR scrubs the xrpl-py client library of any references to "10 drops" as the Base transaction cost. The commits have been organized with the following intent:

  1. Mandate the usage of Client parameter inside the check_fee method: Short of reading the latest validated ledger, I do not know of a way to grab the accurate Fees values.
  2. Re-organize the tests to incorporate point-1
  3. Execute integration tests with non-historical Fees values: I've used arbitrary values to run sanity check on the code. It is difficult to determine the exact value of future FeeSettings ledger objects.

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update CHANGELOG.md?

  • Yes
  • No, this change does not impact library users

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new [voting] section in server configuration with parameters for transaction fees and reserves.
    • Added include_deleted parameter in ledger_entry requests.
    • Enhanced support for transaction fee calculations, including the handling of issued currencies.
  • Bug Fixes

    • Fixed fee settings retrieval to ensure accurate transaction cost calculations.
    • Updated tests to accurately reflect transaction fees in balance calculations.
  • Breaking Changes

    • Removed support for Python 3.7; Python 3.8 is now the default version.
    • Updated default API version to rippled API v2.

- Re-organize the _calculate_fee_per_transaction_type unit test into appropriate file
- Expose a sync-variation of _calculate_fee_per_transaction_type method. This is needed for integration tests concerning SyncClient instances
…the term BaseFee to reflect non-availability of latest data
Update integration tests to validate non-historical transaction cost
@ckeshava ckeshava requested a review from mvadari October 16, 2024 23:44
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces several modifications primarily focused on the configuration of the rippled server, updates to the changelog, and enhancements to the transaction fee calculation logic. Key changes include the addition of a new [voting] section in the configuration file and the removal of support for Python 3.7 in favor of Python 3.8. The test suite has also been updated to include new test cases for fee calculations, while some redundant tests and imports have been removed.

Changes

File Path Change Summary
.ci-config/rippled.cfg Added [voting] section with reference_fee, account_reserve, and owner_reserve. Updated server ports to allow external access. Commented out port_peer.
CHANGELOG.md Updated to include new include_deleted parameter, breaking change for Python version, and various enhancements and fixes.
tests/integration/sugar/test_transaction.py Added test_basic_calculate_fee_per_transaction_type to verify fee calculation for issued currencies. Updated import statements.
tests/unit/core/addresscodec/test_main.py Removed unnecessary imports and test_basic_calculate_fee_per_transaction_type_offline method.
xrpl/asyncio/transaction/init.py Added _calculate_fee_per_transaction_type to imports and __all__ list.
xrpl/asyncio/transaction/main.py Modified fee-checking logic in _check_fee. Updated _calculate_fee_per_transaction_type to require a Client instance.
xrpl/transaction/init.py Added _calculate_fee_per_transaction_type to imports and __all__ list.
xrpl/transaction/main.py Introduced _calculate_fee_per_transaction_type for calculating transaction fees based on network conditions.
tests/integration/transactions/test_xchain_claim.py Updated TestXChainClaim to include transaction fees in balance calculations.

Possibly related PRs

  • Add include_deleted param to ledger_entry API #721: The addition of the include_deleted parameter in the ledger_entry API is related to changes in the configuration and functionality of the server, as both involve enhancements to how ledger data is managed and accessed.

Suggested reviewers

  • shawnxie999
  • pdp2121

Poem

🐇 In the meadow, changes bloom,
Ports now open, dispelling gloom.
Fees calculated, tests in line,
With every hop, our code will shine!
A new section added, oh what a sight,
In the world of rippled, we take flight! 🌼


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.

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: 3

🧹 Outside diff range and nitpick comments (4)
xrpl/transaction/main.py (1)

136-159: Consider alternative to asyncio.run() for better flexibility

The use of asyncio.run() to execute the asynchronous function synchronously is straightforward, but it might cause issues if this function is called from an async context. Consider providing both sync and async versions of this function for more flexibility.

Here's a suggestion to improve flexibility:

import asyncio
from typing import Optional, Union

# ... (other imports)

async def _calculate_fee_per_transaction_type_async(
    transaction: Transaction,
    client: SyncClient,
    signers_count: Optional[int] = None,
) -> str:
    return await main._calculate_fee_per_transaction_type(transaction, client, signers_count)

def _calculate_fee_per_transaction_type(
    transaction: Transaction,
    client: SyncClient,
    signers_count: Optional[int] = None,
) -> str:
    return asyncio.run(_calculate_fee_per_transaction_type_async(transaction, client, signers_count))

This approach provides both synchronous and asynchronous versions of the function, allowing for more flexible usage in different contexts.

Consider using a more specific return type

The current return type hint is str, which is quite generic for a fee value. Consider using a more specific type, such as int or a custom type that represents drops, to make the function's output clearer.

Here's a suggestion for a more specific return type:

from typing import NewType

Drops = NewType('Drops', int)

def _calculate_fee_per_transaction_type(
    transaction: Transaction,
    client: SyncClient,
    signers_count: Optional[int] = None,
) -> Drops:
    # ... (implementation)

Overall implementation looks good

The function is well-implemented and aligns with the PR objectives. It correctly uses the Client parameter as required, and the docstring provides clear information about the function's purpose and parameters.

xrpl/models/base_model.py (1)

180-182: Improved type handling for Any parameters

This change enhances the type checking capabilities of the _from_dict_single_param method. By explicitly checking for param_type is Any, it allows for more flexible handling of parameters without compromising type safety. This modification eliminates the need for a type ignore comment, making the code more robust and easier to maintain.

Consider adding a brief comment explaining the purpose of this condition, such as:

if param_type is Any:
    # Allow any value for parameters typed as Any
    return param_value

This would help future maintainers understand the intention behind this specific check.

tests/integration/sugar/test_transaction.py (2)

196-196: LGTM: Improved clarity in fee calculation comment.

The updated comment provides a clearer explanation of the fee calculation formula. The variable name change from base_fee to net_fee is also an improvement.

Consider adding a brief comment explaining why the fee is calculated this way, if there's a specific reason for this formula.


440-467: New test added for fee calculation with issued currency.

The new test test_basic_calculate_fee_per_transaction_type_offline is a valuable addition, covering fee calculation for a payment transaction with issued currency. However, there are a few points to consider:

  1. The test is using a private function _calculate_fee_per_transaction_type. Consider if this should be a public API or if the test should be moved to a more appropriate location.

  2. The expected fee is hardcoded as "200". This might make the test brittle if fee calculations change in the future.

Consider the following improvements:

  1. If _calculate_fee_per_transaction_type is meant to be a public API, rename it without the leading underscore. Otherwise, consider moving this test to be closer to the implementation it's testing.
  2. Instead of hardcoding the expected fee, calculate it based on the current fee settings or make it clear why "200" is the expected value (e.g., is it a minimum fee for issued currency transactions?).
  3. Add more assertions to verify other properties of the created Payment object to ensure it's constructed correctly.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c288a5a and 644dddd.

📒 Files selected for processing (8)
  • .ci-config/rippled.cfg (1 hunks)
  • tests/integration/sugar/test_transaction.py (4 hunks)
  • tests/unit/core/addresscodec/test_main.py (0 hunks)
  • xrpl/asyncio/transaction/init.py (2 hunks)
  • xrpl/asyncio/transaction/main.py (5 hunks)
  • xrpl/models/base_model.py (1 hunks)
  • xrpl/transaction/init.py (2 hunks)
  • xrpl/transaction/main.py (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/unit/core/addresscodec/test_main.py
🧰 Additional context used
🔇 Additional comments (14)
xrpl/asyncio/transaction/__init__.py (2)

Line range hint 2-9: LGTM: Import statement is correctly implemented.

The new function _calculate_fee_per_transaction_type is properly imported from the xrpl.asyncio.transaction.main module, maintaining consistency with the existing import structure.


Line range hint 11-27: Reconsider exposing _calculate_fee_per_transaction_type in __all__.

The function _calculate_fee_per_transaction_type is being added to the __all__ list, which exposes it as part of the public API. However, the function name starts with an underscore, which is a Python convention for indicating internal use. This seems inconsistent.

Consider one of the following actions:

  1. If the function is intended for public use, rename it without the leading underscore.
  2. If the function is intended for internal use, remove it from the __all__ list.

Please clarify the intended usage of this function and adjust accordingly.

To help verify the intended usage of this function, let's check its implementation and any documentation:

xrpl/transaction/__init__.py (1)

Line range hint 1-28: Clarify the purpose of these changes in relation to PR objectives.

The changes in this file introduce a private function _calculate_fee_per_transaction_type to the module's imports and __all__ list. While this might be related to updating fee calculations, it's not immediately clear how these changes contribute to the PR's stated objective of removing references to "10 drops" as the base transaction cost.

Could you provide more context on how these changes align with the PR objectives? Additionally, consider running the following script to check for any remaining references to "10 drops" in the codebase:

✅ Verification successful

Verification Successful: No remaining references to "10 drops" found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for "10 drops" references in Python files

# Test: Search for "10 drops" in Python files
rg --type python "10 drops"

Length of output: 60


Script:

#!/bin/bash
# Description: Search for "10 drops" references in Python files

# Test: Search for "10 drops" in Python files
rg --type py "10 drops"

Length of output: 25

.ci-config/rippled.cfg (1)

185-190: Approve addition of [voting] section with clarification needed

The addition of the [voting] section is a good implementation for simulating various FeeSettings scenarios in standalone mode. This aligns with the PR objectives of updating FeeSettings.

However, there are a few points that need clarification:

  1. The reference_fee is set to 200 drops, which differs from the "10 drops" mentioned in the PR objectives. Is this intentional?
  2. Can you confirm that the account_reserve (20 XRP) and owner_reserve (5 XRP) values are correct for your use case?

To verify the consistency of these values across the codebase, please run the following script:

This will help ensure that these new values are consistently applied throughout the codebase.

✅ Verification successful

Please manually verify the consistency of reference_fee, account_reserve, and owner_reserve values across the codebase.

While automated scripts did not identify any conflicting hardcoded fee or reserve values, it's essential to ensure that the newly added [voting] section aligns correctly with all parts of the application.


Approve addition of [voting] section with clarification on reference_fee

The addition of the [voting] section correctly implements the simulation of various FeeSettings scenarios in standalone mode. Automated checks confirm that there are no conflicting hardcoded fee or reserve values in the codebase.

However, the reference_fee is set to 200 drops, which differs from the "10 drops" mentioned in the PR objectives. Please confirm if this change is intentional.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any hardcoded fee or reserve values in the codebase

# Search for hardcoded fee values
echo "Searching for hardcoded fee values:"
rg --type python -i '(fee|drop).*?[0-9]+' -g '!*.cfg'

# Search for hardcoded reserve values
echo "Searching for hardcoded reserve values:"
rg --type python -i '(reserve).*?[0-9]+' -g '!*.cfg'

Length of output: 342




xrpl/transaction/main.py (2)

1-5: File structure and imports look good

The overall file structure is maintained, and the necessary imports have been added to support the new functionality. The placement of the new function at the end of the file is appropriate and follows the existing code organization.


Line range hint 1-159: Summary: Changes align well with PR objectives

The modifications to xrpl/transaction/main.py successfully address the PR objectives:

  1. The new _calculate_fee_per_transaction_type function uses the Client parameter to accurately retrieve current fee values.
  2. The implementation maintains backward compatibility by not altering existing functions.
  3. The changes support the removal of "10 drops" as the base transaction cost reference.

These updates contribute to a more dynamic and accurate fee calculation system for the XRPL client library.

xrpl/models/base_model.py (1)

180-182: Overall impact assessment

This change improves type handling without altering the core functionality of the BaseModel class. It maintains backwards compatibility and doesn't introduce any performance overhead. However, to ensure robustness:

  1. Verify that existing tests pass with this change.
  2. Consider adding new test cases that specifically cover the handling of Any type parameters in the _from_dict_single_param method.

You can use the following script to run the existing tests and check for any failures:

If you need assistance in creating additional test cases for Any type parameters, please let me know.

tests/integration/sugar/test_transaction.py (2)

18-21: LGTM: New imports added for additional functionality.

The new imports for _calculate_fee_per_transaction_type and IssuedCurrencyAmount are correctly added to support the new test case introduced later in the file.

Also applies to: 25-25


219-222: LGTM: Improved clarity and simplified assertion in payment fee test.

The updated comment provides a clearer explanation of what the expected fee represents. The assertion has been simplified by directly comparing payment_autofilled.fee with expected_fee, which is more straightforward and removes unnecessary string conversion.

xrpl/asyncio/transaction/main.py (5)

400-400: Docstring correctly reflects updated fee-checking logic

The docstring for _check_fee now accurately describes that the function checks if the transaction fee is higher than the expected transaction type fee.


459-459: Validate the fee calculation for EscrowFinish with fulfillment

The calculation for base_fee in the EscrowFinish transaction with a fulfillment seems correct. It uses the formula:

base_fee = math.ceil(net_fee * (33 + (len(fulfillment_bytes) / 16)))

Ensure that fulfillment_bytes is correctly encoded and that the division by 16 accurately reflects the fee calculation as per the XRPL documentation.


467-469: Confirm the fee assignment for AccountDelete and AMM_CREATE transactions

Setting base_fee to the owner's reserve fee for AccountDelete and AMM_CREATE transactions is appropriate according to XRPL fee guidelines. Ensure that _fetch_owner_reserve_fee(client) correctly retrieves the necessary fee from the ledger.


426-429: Ensure all calls to _calculate_fee_per_transaction_type pass the required client parameter

The client parameter in _calculate_fee_per_transaction_type has been changed from optional to required. Please verify that all calls to this function have been updated to include the client argument to avoid potential issues.

Run the following script to identify any calls to _calculate_fee_per_transaction_type that may be missing the client parameter:

#!/bin/bash
# Description: Find calls to `_calculate_fee_per_transaction_type` without the `client` parameter

# Search for `_calculate_fee_per_transaction_type` calls in Python files
rg --type py '_calculate_fee_per_transaction_type\(' -A 2

396-399: Ensure all calls to _check_fee pass the required client parameter

The client parameter in _check_fee has been changed from optional to required. Please verify that all calls to this function have been updated to include the client argument to prevent runtime errors.

Run the following script to identify any calls to _check_fee that may be missing the client parameter:

✅ Verification successful

All _check_fee calls correctly include the client parameter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find calls to `_check_fee` without the `client` parameter

# Search for `_check_fee` calls in Python files
rg --type py '_check_fee\(' -A 2

Length of output: 1279


Script:

#!/bin/bash
# Description: Find calls to `_check_fee` without the `client` parameter

# Search for `_check_fee` calls in Python files
rg --type py '_check_fee\(' -A 2

Length of output: 888

from xrpl.asyncio.transaction import (
XRPLReliableSubmissionException,
transaction_json_to_binary_codec_form,
)
from xrpl.transaction.main import (
_calculate_fee_per_transaction_type,
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 16, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reconsider importing a private function.

The import of _calculate_fee_per_transaction_type raises a concern. Importing private functions (indicated by the leading underscore) from other modules is generally discouraged as it can lead to tight coupling and make the code more difficult to maintain.

Consider either:

  1. Making the function public if it's intended for use outside its original module, or
  2. Refactoring the code to avoid the need for importing this private function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This import is necessary for integration testing purposes. This method is used for internal purposes only.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ckeshava, understood. Thank you for the clarification.

(・_・)


✏️ Learnings added
Learnt from: ckeshava
PR: XRPLF/xrpl-py#758
File: xrpl/transaction/__init__.py:8-8
Timestamp: 2024-10-17T17:45:46.326Z
Learning: In the xrpl-py project, importing private functions (indicated by a leading underscore) for integration testing purposes is acceptable when the methods are used internally.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@@ -23,4 +25,5 @@
"transaction_json_to_binary_codec_form",
"multisign",
"XRPLReliableSubmissionException",
"_calculate_fee_per_transaction_type",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove private function from all.

Adding _calculate_fee_per_transaction_type to the __all__ list is problematic. The __all__ list is meant to define the public API of a module, but this function is clearly intended to be private (as indicated by the leading underscore).

Remove this line from the __all__ list to maintain proper encapsulation and avoid exposing internal implementation details.

- "_calculate_fee_per_transaction_type",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"_calculate_fee_per_transaction_type",

Comment on lines +470 to 473
# BaseFee × (1 + Number of Signatures Provided)
if signers_count is not None and signers_count > 0:
base_fee += net_fee * (1 + signers_count)
# Round Up base_fee and return it as a String
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review the multisign fee calculation logic

The fee calculation for multisignature transactions adds to base_fee as follows:

if signers_count is not None and signers_count > 0:
    base_fee += net_fee * (1 + signers_count)

Consider verifying whether the formula should multiply the base_fee instead of adding, based on the XRPL fee formula for multisigned transactions (BaseFee × (1 + Number of Signatures Provided)).

Apply this diff to correct the fee calculation:

-    base_fee += net_fee * (1 + signers_count)
+    base_fee = base_fee * (1 + signers_count)

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: 0

🧹 Outside diff range and nitpick comments (1)
CHANGELOG.md (1)

13-14: Approve changes with minor wording suggestion.

The update correctly addresses the PR objective by removing the hard-coded reference to 10 drops as the base transaction cost. It also aligns with the goal of using current fee values by retrieving FeeSettings from the latest validated ledger.

Consider rephrasing for clarity:

- Grab the FeeSettings values from the latest validated ledger. Remove hard-coded reference to 10 drops as the reference transaction cost.
+ Retrieve FeeSettings values from the latest validated ledger. Remove hard-coded reference to 10 drops as the base transaction cost.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 644dddd and bb4ec7c.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🧰 Additional context used

Copy link
Collaborator

@achowdhry-ripple achowdhry-ripple left a comment

Choose a reason for hiding this comment

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

LGTM - curious why we no longer want a default fee but otherwise looks good!


# If FeeSettings ledger object is updated, the below assert needs to be changed
# correspondingly
self.assertEqual(fee, "200")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: could we use the reference_fee variable from the config file here so that only that file needs to be updated in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

completed in 16099ec
I tried to use external libraries like toml and configparser. Thy could not parse the .ci-config/rippled.cfg file. Let me know if I can accomplish this without manually reading the file contents.

net_fee = 10 # 10 drops
else:
net_fee = int(await get_fee(client)) # Usually 0.00001 XRP (10 drops)

net_fee = int(
await get_fee(client)
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought we should default to 200 drops always? Is the new recommendation that we don't have a default fee anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, we do not have a default value. I used 200 drops as an example value, it was chosen arbitrarily.

We will know the transaction fees once all the validators have reached a compromise. Here is more detail on the Fee Voting process: https://xrpl.org/docs/concepts/consensus-protocol/fee-voting#voting-process

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

🧹 Outside diff range and nitpick comments (2)
.github/workflows/snippet_test.yml (1)

Line range hint 52-53: Consider improving snippet execution for better error reporting.

The current method of running snippets in a loop is functional, but it could be enhanced for better error reporting and maintainability. Here's a suggestion to improve this step:

Consider replacing the current snippet execution with a dedicated Python script. This approach would allow for more detailed error reporting and easier maintenance. Here's an example of how you could modify this step:

  1. Create a new file run_snippets.py in your repository:
import os
import sys
import subprocess

def run_snippets():
    snippets_dir = 'snippets'
    for filename in os.listdir(snippets_dir):
        if filename.endswith('.py'):
            print(f"Running {filename}")
            result = subprocess.run(['poetry', 'run', 'python', os.path.join(snippets_dir, filename)], capture_output=True, text=True)
            if result.returncode != 0:
                print(f"Error in {filename}:")
                print(result.stderr)
                return 1
    return 0

if __name__ == '__main__':
    sys.exit(run_snippets())
  1. Update the workflow step to use this script:
- name: Run Snippets
  run: poetry run python run_snippets.py

This approach provides more structured error output and allows for easier addition of logging or other features in the future.

.github/workflows/integration_test.yml (1)

Line range hint 1-78: Approve overall workflow structure with a suggestion for improvement.

The workflow structure is well-organized and includes necessary steps for setting up the environment, running tests, and cleaning up. The use of caching for Poetry and Python dependencies is a good practice for improving workflow efficiency.

However, to further enhance the workflow, consider the following suggestion:

Add a step to validate the rippled Docker container's health before running the tests. This can help catch any issues with the rippled service early in the workflow. Add the following step after the "Run docker in background" step:

      - name: Wait for rippled to be healthy
        run: |
          timeout 60s bash -c 'while [[ "$(docker inspect -f {{.State.Health.Status}} rippled-service)" != "healthy" ]]; do sleep 5; done' || exit 1

This step will wait for up to 60 seconds for the rippled container to report a healthy status before proceeding with the tests.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bb4ec7c and e671483.

📒 Files selected for processing (3)
  • .github/workflows/integration_test.yml (1 hunks)
  • .github/workflows/snippet_test.yml (1 hunks)
  • .github/workflows/unit_test.yml (1 hunks)
🧰 Additional context used
🔇 Additional comments (6)
.github/workflows/snippet_test.yml (2)

Line range hint 1-53: Overall, the workflow looks well-structured and up-to-date.

The update to Poetry version 1.8.3 is the main change in this file, and it appears to be a positive improvement. The workflow's structure, including the use of caching and matrix strategy for Python versions, is well-implemented.

The only suggestion for improvement is related to the snippet execution step, which could be enhanced for better error reporting and maintainability as mentioned in the previous comment.


10-10: Poetry version update looks good, but consider potential impacts.

The update of POETRY_VERSION from 1.4.2 to 1.8.3 is a significant version jump. This change is likely beneficial as it brings in the latest features and bug fixes from Poetry.

However, please consider the following:

  1. Ensure that all dependencies in your project are compatible with Poetry 1.8.3.
  2. Check if there are any breaking changes in Poetry between these versions that might affect your workflow.
  3. It might be worth updating the pyproject.toml file (if not already done) to specify the new minimum Poetry version required for the project.

To verify the compatibility and impact of this change, you can run the following script:

This script will help identify any potential issues related to the Poetry version update.

.github/workflows/integration_test.yml (1)

4-4: Approve Poetry version update with verification steps.

The update of POETRY_VERSION from 1.4.2 to 1.8.3 is a good practice for keeping dependencies up-to-date. However, given the significant version jump, please ensure the following:

  1. Verify compatibility with all Python versions in the matrix (3.8 to 3.12).
  2. Check if there are any breaking changes in Poetry 1.8.3 that might affect this workflow.
  3. Review the project's pyproject.toml file to ensure it's compatible with Poetry 1.8.3.

To verify Poetry's compatibility, run the following script:

.github/workflows/unit_test.yml (3)

Line range hint 1-114: Overall, the workflow update looks good with some points to address.

The update to Poetry version 1.8.3 is the only change in this workflow file. While this update is likely beneficial, please address the following points:

  1. Clarify the reason for updating Poetry in the context of this PR's objectives.
  2. Verify compatibility of the new Poetry version with the project's dependencies.
  3. Ensure that all Poetry commands used in the workflow are still compatible with version 1.8.3.

Once these points are addressed, the workflow update should be good to go.


10-10: Clarify the reason for updating Poetry version.

While updating Poetry is generally a good practice, this change doesn't seem directly related to the PR objectives of removing "10 drops" references and updating fee-related functionality. Could you please clarify why this update was necessary in the context of this PR?

To help understand if this change is related to any new dependencies or testing requirements, please run the following script:

#!/bin/bash
# Description: Check for any new dependencies or testing requirements that might necessitate the Poetry update

# Test: Compare dependencies between the old and new Poetry versions
echo "Checking for dependency changes..."

# Fetch the old pyproject.toml from the main branch
git show main:pyproject.toml > pyproject.toml.old

# Compare dependencies
echo "Old dependencies:"
grep '^\[tool.poetry.dependencies\]' -A 100 pyproject.toml.old | grep -v '^\[' | grep -v '^$'

echo "New dependencies:"
grep '^\[tool.poetry.dependencies\]' -A 100 pyproject.toml | grep -v '^\[' | grep -v '^$'

echo "Differences in dependencies:"
diff <(grep '^\[tool.poetry.dependencies\]' -A 100 pyproject.toml.old | grep -v '^\[' | grep -v '^$') <(grep '^\[tool.poetry.dependencies\]' -A 100 pyproject.toml | grep -v '^\[' | grep -v '^$')

# Check for changes in dev dependencies or test requirements
echo "Checking for changes in dev dependencies or test requirements..."
diff <(grep '^\[tool.poetry.dev-dependencies\]' -A 100 pyproject.toml.old | grep -v '^\[' | grep -v '^$') <(grep '^\[tool.poetry.dev-dependencies\]' -A 100 pyproject.toml | grep -v '^\[' | grep -v '^$')

This script will help identify any new dependencies or testing requirements that might explain the need for the Poetry version update.


10-10: Poetry version update looks good, but let's verify compatibility.

The Poetry version has been updated from 1.4.2 to 1.8.3, which is a significant version jump. This update is likely to bring improvements and bug fixes.

To ensure this change doesn't introduce any compatibility issues, please run the following verification script:

This script will verify that the new Poetry version is compatible with your project's configuration and dependencies.

@@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
POETRY_VERSION: 1.4.2
POETRY_VERSION: 1.8.3
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Poetry is not installed in the workflow environment.

The workflow updates the Poetry version to 1.8.3 but does not include a step to install Poetry. This will cause any Poetry commands in the workflow to fail.

  • Solution: Add a step to install Poetry before running Poetry commands. For example:

    - name: Install Poetry
      run: |
        curl -sSL https://install.python-poetry.org | python3 -
        export PATH="$HOME/.local/bin:$PATH"
🔗 Analysis chain

Verify Poetry command compatibility with the new version.

While the workflow has been updated to use Poetry 1.8.3, it's important to ensure that all Poetry commands used in the workflow are still compatible with this new version. Please review the Poetry changelog for any breaking changes or new features that might affect the workflow.

To help with this verification, please run the following script:

This script will help verify that the Poetry commands used in the workflow are still valid and highlight any new features or changes that might be relevant to the workflow.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Poetry command compatibility and new features

# Test: Verify Poetry commands used in the workflow
echo "Checking Poetry command compatibility..."

poetry_commands=("install" "run")

for cmd in "${poetry_commands[@]}"; do
    echo "Checking 'poetry $cmd' command..."
    poetry help $cmd | grep -q "Usage:" && echo "'poetry $cmd' is available" || echo "Warning: 'poetry $cmd' might have changed or is not available"
done

# Check for new relevant features or changes
echo "Checking for new relevant features or changes in Poetry 1.8.3..."
poetry --version
poetry help | grep -E "new|changed"

Length of output: 1222


Script:

#!/bin/bash
# Description: Verify if Poetry is installed and available in PATH

echo "Verifying Poetry installation..."

# Check if Poetry is installed
if command -v poetry >/dev/null 2>&1; then
    echo "Poetry is installed."
    echo "Poetry version:"
    poetry --version
else
    echo "Poetry is not installed or not in PATH."
fi

# Display current PATH
echo "Current PATH:"
echo $PATH

# Attempt to locate Poetry executable
echo "Locating Poetry executable..."
which poetry || echo "Poetry executable not found."

Length of output: 574

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: 0

🧹 Outside diff range and nitpick comments (1)
tests/integration/sugar/test_transaction.py (1)

440-478: LGTM: New test method for fee calculation with issued currency.

The new test method test_basic_calculate_fee_per_transaction_type_offline is a valuable addition to verify fee calculation for payment transactions involving issued currencies. It uses the _calculate_fee_per_transaction_type function and compares the result with an expected fee read from a configuration file.

Consider updating the comment on lines 472-473 to be more precise:

-                # This step assumes that no non-`voting` section in the config file
-                # uses the reference_fee key-value pair.
+                # This step assumes that 'reference_fee' is only used in the [voting]
+                # section of the config file.

This change more accurately reflects the assumption being made about the config file structure.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e671483 and 16099ec.

📒 Files selected for processing (1)
  • tests/integration/sugar/test_transaction.py (4 hunks)
🧰 Additional context used
🔇 Additional comments (3)
tests/integration/sugar/test_transaction.py (3)

18-21: LGTM: Import statements updated correctly.

The new imports are necessary for the added functionality in the test file. The _calculate_fee_per_transaction_type function is used in the new test method, and IssuedCurrencyAmount is used to create test data.

Also applies to: 25-25


196-196: LGTM: Improved comment clarity.

The updated comment provides a clearer explanation of the fee calculation formula for the EscrowFinish transaction.


219-220: LGTM: Enhanced comment clarity for fee calculation.

The updated comments provide a more precise explanation of the expected fee calculation for the Payment transaction.

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: 0

🧹 Outside diff range and nitpick comments (3)
tests/integration/transactions/test_xchain_claim.py (3)

22-22: LGTM: Test decorator updated to handle async fee retrieval.

The @test_async_and_sync decorator is correctly updated to include ["xrpl.ledger.get_fee"], allowing the test to handle asynchronous calls for fetching transaction fees. This aligns with the PR objective of using the Client parameter to retrieve current fee values.

Consider adding a comment explaining why ["xrpl.ledger.get_fee"] is included in the decorator, to improve code readability:

@test_async_and_sync(globals(), ["xrpl.ledger.get_fee"])  # Include get_fee for async fee retrieval

101-101: LGTM: Transaction fee retrieval implemented.

The addition of transaction_fee = int(await get_fee(client)) correctly implements the retrieval of the current fee, aligning with the PR objectives. The use of await is appropriate for asynchronous fee retrieval.

Consider adding error handling to make the code more robust:

try:
    transaction_fee = int(await get_fee(client))
except Exception as e:
    self.fail(f"Failed to retrieve transaction fee: {e}")

This will provide more informative error messages if fee retrieval fails.


Line range hint 1-107: Summary: Changes align with PR objectives, but verification needed.

The modifications to this test file correctly implement the retrieval and incorporation of transaction fees into the balance calculations, aligning with the PR objectives. The changes include:

  1. Adding the necessary import for get_fee.
  2. Updating the test decorator to handle async fee retrieval.
  3. Implementing transaction fee retrieval.
  4. Updating the final balance assertion to account for the fee.

These changes should improve the accuracy of the test by reflecting real-world fee scenarios. However, given the mention in the PR objectives that this file was failing some tests, it's crucial to verify if these changes have resolved those issues.

Next steps:

  1. Run the verification script provided in the previous comment to check if the test passes with the new changes.
  2. If the test still fails, investigate the specific assertions that are failing and consider if further adjustments are needed to the balance calculations or other parts of the test setup.
  3. Ensure that the test environment accurately reflects the expected FeeSettings values mentioned in the PR objectives.

Once these steps are completed, we can be more confident in the robustness of this test implementation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 16099ec and 0bc1d38.

📒 Files selected for processing (1)
  • tests/integration/transactions/test_xchain_claim.py (3 hunks)
🧰 Additional context used
🔇 Additional comments (2)
tests/integration/transactions/test_xchain_claim.py (2)

7-7: LGTM: Import statement for get_fee added.

The new import statement for get_fee from xrpl.asyncio.ledger is correctly added and will be used for fee calculations later in the test.


104-107: LGTM: Final balance calculation updated to include transaction fee.

The modification to subtract transaction_fee from the final balance calculation is correct and aligns with the PR objective of accurately handling fees in tests.

However, the PR objectives mention that this file currently fails to pass all tests with the new FeeSettings values. Let's verify if this is still an issue:

If the test is still failing, we may need to adjust the balance calculation further or investigate other factors affecting the test outcome.

@ckeshava ckeshava requested a review from pdp2121 October 18, 2024 20:17
@@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
POETRY_VERSION: 1.4.2
POETRY_VERSION: 1.8.3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need version bump here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

poetry released version 1.8.3 6 months ago. I believe it is stable enough for our adoption: https://github.com/python-poetry/poetry/releases

Initially, I assumed the older version was causing a lint error, but the poetry version is not related to the linter.

I can revert back the poetry-related changes, if required.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No issue at all. Just curious since poetry.lock already use 1.8.3 but I guess it doesn't update automatically in all places.
https://github.com/XRPLF/xrpl-py/blob/main/poetry.lock#L1

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: 0

🧹 Outside diff range and nitpick comments (1)
CHANGELOG.md (1)

16-17: Enhance the changelog entry for completeness.

While the current entry correctly documents the removal of hard-coded fee settings, consider adding more details to help users understand the full scope of changes:

 ### Fixed
-Grab the FeeSettings values from the latest validated ledger. Remove hard-coded reference to 10 drops as the reference transaction cost.
+- Grab the FeeSettings values from the latest validated ledger by requiring Client parameter in check_fee method
+- Remove hard-coded reference to 10 drops as the reference transaction cost
+- Reorganize tests to support dynamic fee calculation

This enhanced entry better reflects:

  1. The mandatory Client parameter requirement
  2. The test reorganization
  3. Each change as a separate bullet point for clarity
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bb020f5 and f182ead.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🔇 Additional comments (1)
CHANGELOG.md (1)

Line range hint 1-24: LGTM! The changelog structure follows best practices.

The changelog properly follows the Keep a Changelog format and semantic versioning, with clear categorization of changes and proper placement of the unreleased section.

🧰 Tools
🪛 Markdownlint

13-13: Punctuation: ':'
Trailing punctuation in heading

(MD026, no-trailing-punctuation)

@ckeshava ckeshava merged commit c723b7b into XRPLF:main Oct 28, 2024
22 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
9 tasks
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