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

Deep Freeze XLS-77d #2873

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Deep Freeze XLS-77d #2873

wants to merge 1 commit into from

Conversation

ckeshava
Copy link
Collaborator

@ckeshava ckeshava commented Jan 7, 2025

High Level Overview of Change

This PR implements the Deep-Freeze spec: XRPLF/XRPL-Standards#220

CPP implementation: https://github.com/XRPLF/rippled/pull/5187/files#

Note: Please do not merge this PR until the CPP implementation is merged into the develop branch of rippled.

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 HISTORY.md?

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

Test Plan

New integration tests have been added to validate the Deep-Freeze behavior. Unit tests have been modified to incorporate deep-frozen trust lines.

Future Tasks

Once the behavior of Checks is better understood with the deep-frozen trust lines, additional integration tests can be added. However, they introduce non-trivial complexity in the code. Furthermore, such tests are already covered by the cpp implementaion.

…t transaction

integration test for OfferCreate txn (negative case)

update to the unit test of TrustSet transaction
Copy link

coderabbitai bot commented Jan 7, 2025

Walkthrough

This pull request introduces support for the XLS-77d Deep-Freeze amendment in the XRPL ecosystem. The changes span multiple files across the xrpl.js library, adding new flags and configurations related to deep-freezing trust lines. The modifications include updating configuration files, extending enum definitions, and adding test cases to verify the new deep-freeze functionality. The implementation allows for setting and clearing deep-freeze states on trust lines, which restricts sending and receiving of specified issued currencies.

Changes

File Change Summary
.ci-config/rippled.cfg Added DeepFreeze amendment to [features] section; commented out some port and SSL configurations
packages/xrpl/HISTORY.md Added "Support for XLS-77d Deep-Freeze amendment" under Unreleased Changes
packages/xrpl/src/models/ledger/RippleState.ts Added lsfLowDeepFreeze and lsfHighDeepFreeze flags to RippleStateFlags enum
packages/xrpl/src/models/transactions/trustSet.ts Added tfSetDeepFreeze and tfClearDeepFreeze flags to TrustSetFlags enum
packages/xrpl/test/... Added integration and model tests for deep-freeze functionality

Possibly Related PRs

Suggested Reviewers

  • achowdhry-ripple
  • khancode

Poem

🐰 A Rabbit's Deep-Freeze Delight

In the realm of trust and token's might,
Deep-freeze flags now take their flight,
Transactions locked, no currency's sway,
A rabbit's magic keeps risks at bay!
🧊✨


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

@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

🧹 Nitpick comments (5)
packages/xrpl/src/models/ledger/RippleState.ts (1)

80-83: Add documentation comments for the new deep freeze flags.

The new flags would benefit from detailed documentation comments explaining their purpose and behavior, similar to other flags in the enum.

  // True, trust line to AMM. Used by client apps to identify payments via AMM.
  lsfAMMNode = 0x01000000,
-  // True, low side has set deep freeze flag
+  /**
+   * True if the low side has set the deep freeze flag.
+   * When set, this flag permanently freezes the trust line until explicitly cleared.
+   */
  lsfLowDeepFreeze = 0x02000000,
-  // True, high side has set deep freeze flag
+  /**
+   * True if the high side has set the deep freeze flag.
+   * When set, this flag permanently freezes the trust line until explicitly cleared.
+   */
  lsfHighDeepFreeze = 0x04000000,
packages/xrpl/test/models/trustSet.test.ts (1)

25-29: Enhance test coverage for deep freeze flags.

The test suite would benefit from additional test cases:

  1. Testing the tfClearDeepFreeze flag
  2. Negative test cases for invalid flag combinations
  3. Validation of flag values
// Example additional test cases:
it('throws when setting both tfSetDeepFreeze and tfClearDeepFreeze', function () {
  trustSet.Flags = {
    tfSetDeepFreeze: true,
    tfClearDeepFreeze: true,
  }
  assert.throws(
    () => validateTrustSet(trustSet),
    ValidationError,
    'TrustSet: cannot set and clear deep freeze simultaneously',
  )
})

it('verifies clearing of deep freeze', function () {
  trustSet.Flags = {
    tfClearDeepFreeze: true,
  }
  assert.doesNotThrow(() => validateTrustSet(trustSet))
})
packages/xrpl/test/integration/transactions/offerCreate.test.ts (1)

62-108: Enhance test coverage for deep-frozen trust line scenarios.

While the test verifies basic blocking behavior, consider adding test cases for:

  1. Attempting to modify an existing offer after deep-freezing
  2. Testing with different combinations of freeze flags (regular freeze vs deep freeze)
  3. Testing behavior when only one side of the trust line is deep-frozen

Also, consider extracting the trust line setup into a helper function to improve test readability and reusability:

async function setupDeepFrozenTrustLine(
  testContext: XrplIntegrationTestContext,
  counterparty: Wallet,
  currency: string = 'USD',
  value: string = '10',
): Promise<void> {
  const trust_set_tx: TrustSet = {
    TransactionType: 'TrustSet',
    Account: testContext.wallet.classicAddress,
    LimitAmount: {
      currency,
      issuer: counterparty.classicAddress,
      value,
    },
    Flags: {
      tfSetFreeze: true,
      tfSetDeepFreeze: true,
    },
  }
  await testTransaction(testContext.client, trust_set_tx, testContext.wallet)
}
packages/xrpl/src/models/transactions/trustSet.ts (2)

33-34: Fix typo in documentation comment

There's a typo in the comment: "recieving" should be "receiving".

-  /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */
+  /** Deep-Freeze the trust line -- disallow sending and receiving the said IssuedCurrency */

96-99: Document interaction with regular freeze flags

The documentation should clarify how deep-freeze flags interact with regular freeze flags (tfSetFreeze/tfClearFreeze). This helps developers understand the precedence and combined effects.

Add a note in the documentation:

   /** Deep-Freeze the trust line -- disallow sending and receiving the said IssuedCurrency */
   tfSetDeepFreeze?: boolean
   /** Clear a Deep-Frozen trust line */
   tfClearDeepFreeze?: boolean
+  /**
+   * Note: Deep-freeze takes precedence over regular freeze. When a trust line is
+   * deep-frozen, the regular freeze state has no effect until the deep-freeze is cleared.
+   */
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84943ae and 1d897a4.

📒 Files selected for processing (7)
  • .ci-config/rippled.cfg (1 hunks)
  • packages/xrpl/HISTORY.md (1 hunks)
  • packages/xrpl/src/models/ledger/RippleState.ts (1 hunks)
  • packages/xrpl/src/models/transactions/trustSet.ts (2 hunks)
  • packages/xrpl/test/integration/transactions/offerCreate.test.ts (2 hunks)
  • packages/xrpl/test/integration/transactions/trustSet.test.ts (1 hunks)
  • packages/xrpl/test/models/trustSet.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/xrpl/HISTORY.md
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: integration (22.x)
  • GitHub Check: snippets (22.x)
  • GitHub Check: unit (18.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: integration (18.x)
  • GitHub Check: browser (18.x)
  • GitHub Check: snippets (18.x)
🔇 Additional comments (2)
.ci-config/rippled.cfg (1)

191-191: Verify amendment dependency with C++ implementation

The PR objectives state that this PR should not be merged until the C++ implementation is integrated into the rippled project. We should ensure that enabling the DeepFreeze amendment here is safe and won't cause issues if the C++ implementation isn't ready.

Run this script to check the amendment status in rippled:

packages/xrpl/src/models/transactions/trustSet.ts (1)

33-36: Verify bit flag values with rippled implementation

The bit flag values (0x00400000 and 0x00800000) for deep-freeze must match the C++ implementation in rippled.

Run this script to verify the flag values:

Also applies to: 96-99

✅ Verification successful

Deep-freeze flag values are correctly implemented

The values 0x00400000 (tfSetDeepFreeze) and 0x00800000 (tfClearDeepFreeze) are correctly implemented as part of the XLS-77d Deep-Freeze amendment. These values are consistently used across the codebase and validated through integration tests. While these bit positions are reused in other transaction and ledger entry types, this is a common practice in XRPL as each type maintains its own separate flag namespace.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify deep-freeze flag values match rippled implementation

# Check flag definitions in rippled
gh api repos/ripple/rippled/contents/src/ripple/protocol/TxFlags.h -q '.content' | base64 -d | grep -A 5 "tfSetDeepFreeze"

Length of output: 217


Script:

#!/bin/bash
# Try multiple approaches to verify the flag values

# 1. Fetch rippled implementation using curl
curl -s https://raw.githubusercontent.com/ripple/rippled/develop/src/ripple/protocol/TxFlags.h | grep -A 5 "tfSetDeepFreeze"

# 2. Search for tests or documentation about these flags
rg -i "deep.*freeze" -A 5 -B 5

# 3. Look for any validation of these specific hex values
rg "0x00400000|0x00800000" -A 2 -B 2

Length of output: 12337


Script:

#!/bin/bash
# Look for XLS-77d documentation and specs
rg -i "XLS-77d|deep.?freeze" --type md

# Check if there are any conflicting uses of these specific values
rg "0x00400000|0x00800000" --type ts --context 3

Length of output: 3790

Comment on lines +89 to +128
it(
'Create a Deep-Frozen trust line',
async () => {
assert(wallet2 != null)
// preemptively deep-freeze a trust line with the specified counter-party/currency-code
const tx: TrustSet = {
TransactionType: 'TrustSet',
Account: testContext.wallet.classicAddress,
LimitAmount: {
currency: 'USD',
issuer: wallet2.classicAddress,
value: '10',
},
Flags: {
tfSetFreeze: true,
tfSetDeepFreeze: true,
},
}

const response = await testTransaction(
testContext.client,
tx,
testContext.wallet,
)
assert.equal(response.result.engine_result, 'tesSUCCESS')

// assert that the trust line is deep-frozen
const trustLine = await testContext.client.request({
command: 'account_lines',
account: testContext.wallet.classicAddress,
})

// assert that the TrustLine is deep-frozen
assert.equal(trustLine.result.lines[0].freeze, true)

// Keshava: ensure that account_lines RPC response contains a deep_freeze flag
// assert.equal(trustLine.result.lines[0].deep_freeze, true)
},
TIMEOUT,
)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add test cases for high/low side deep freeze behavior.

The test suite should verify:

  1. Deep freeze behavior from both high and low sides of the trust line
  2. Interaction between regular freeze and deep freeze
  3. Clearing of deep freeze flags
it('Deep freeze from high side', async () => {
  // Similar test but with wallet2 setting the deep freeze
})

it('Clear deep freeze', async () => {
  // Test clearing the deep freeze flag
})

it('Interaction between regular and deep freeze', async () => {
  // Test combinations of regular and deep freeze flags
})

Comment on lines +124 to +125
// Keshava: ensure that account_lines RPC response contains a deep_freeze flag
// assert.equal(trustLine.result.lines[0].deep_freeze, true)
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Remove the commented deep_freeze assertion

The deep_freeze flag is not part of the XRPL account_lines API. The trust line freeze functionality is handled by the documented freeze and freeze_peer flags. This commented assertion should be removed as it references a non-existent feature.

🔗 Analysis chain

Clarify the status of the commented assertion.

The commented assertion suggests that the deep_freeze flag in the account_lines RPC response might be pending implementation. This should be either:

  1. Implemented and uncommented if the feature is ready
  2. Removed if the feature is not planned
  3. Converted to a TODO comment with a clear explanation if it's pending
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if deep_freeze flag is implemented in account_lines RPC
rg -A 5 "deep_freeze.*account_lines"

Length of output: 38


Script:

#!/bin/bash
# Search for deep_freeze usage in the codebase
rg "deep_freeze" -B 2 -A 2

# Search for account_lines test assertions
rg "account_lines.*assert" -B 2 -A 2

# Check documentation or type definitions for account_lines
fd "account.*lines" --type f --exec cat {}

Length of output: 83376

Comment on lines +33 to +36
/** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */
tfSetDeepFreeze = 0x00400000,
/** Clear a Deep-Frozen trust line */
tfClearDeepFreeze = 0x00800000,
Copy link

@coderabbitai coderabbitai bot Jan 7, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding validation for mutually exclusive flags

The deep-freeze flags (tfSetDeepFreeze and tfClearDeepFreeze) are mutually exclusive, similar to the existing freeze flags. Consider adding validation to prevent setting both flags simultaneously.

Here's a suggested implementation:

function validateTrustSet(tx: Record<string, unknown>): void {
  // ... existing validation ...
  
  if (typeof tx.Flags === 'object') {
    const flags = tx.Flags as TrustSetFlagsInterface
    if (flags.tfSetDeepFreeze && flags.tfClearDeepFreeze) {
      throw new ValidationError(
        'TrustSet: cannot set both tfSetDeepFreeze and tfClearDeepFreeze flags',
      )
    }
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there are many validation rules associated with the flags of trust-set transaction. It is not informative if certain rules are cherry-picked for implementation

Copy link

Choose a reason for hiding this comment

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

@ckeshava Understood, I'll retract the suggestion. You make a valid point about the importance of comprehensive validation rather than selective implementation.


✏️ Learnings added
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.450Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.

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.

@ckeshava
Copy link
Collaborator Author

ckeshava commented Jan 8, 2025

@shawnxie999 If you have any free time, please review this PR

@shawnxie999
Copy link
Collaborator

just a heads up I'll only be able to start reviewing this PR end of next week - if that's fine with you. doesn't want to be a blocker if this PR is urgent

@ckeshava
Copy link
Collaborator Author

ckeshava commented Jan 9, 2025

just a heads up I'll only be able to start reviewing this PR end of next week - if that's fine with you. doesn't want to be a blocker if this PR is urgent

no worries, that is fine

Comment on lines +25 to +28
if (!wallet2) {
// eslint-disable-next-line require-atomic-updates -- race condition doesn't really matter
wallet2 = await generateFundedWallet(testContext.client)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better practice would be to put this in a beforeAll

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