Skip to content

Add locked unit reserve for payment hub withdrawals#3791

Merged
jolestar merged 4 commits into
mainfrom
payment_hub_transfer
Nov 21, 2025
Merged

Add locked unit reserve for payment hub withdrawals#3791
jolestar merged 4 commits into
mainfrom
payment_hub_transfer

Conversation

@jolestar

Copy link
Copy Markdown
Contributor

Summary

  • add global per-coin locked unit config for PaymentHub and compute unlocked balance
  • allow withdrawals with active channels up to unlocked balance and expose view helpers
  • add tests covering unlocked balance behavior and updated withdrawal scenarios

Testing

  • target/debug/rooch move test -p frameworks/rooch-framework payment_channel

@vercel

vercel Bot commented Nov 21, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
rooch-portal-v2.1 Ready Ready Preview Comment Nov 21, 2025 8:45am
test-portal Ready Ready Preview Comment Nov 21, 2025 8:45am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
rooch Ignored Ignored Preview Nov 21, 2025 8:45am

@github-actions

github-actions Bot commented Nov 21, 2025

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a locked unit reserve mechanism for PaymentHub withdrawals, allowing users to withdraw funds even with active channels as long as they maintain sufficient locked reserves.

Key Changes

  • Added PaymentHubConfig global configuration to store per-coin locked unit requirements
  • Modified withdraw_from_hub to check unlocked balance instead of blocking all withdrawals when channels are active
  • Added view helpers (get_unlocked_balance_in_hub, get_required_locked_for_owner, get_locked_unit) and admin function set_locked_unit to manage locked reserves
  • Updated tests to verify unlocked balance behavior and removal of the old "no withdrawals with active channels" restriction

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
frameworks/rooch-framework/sources/payment_channel.move Implements PaymentHubConfig struct, unlocked balance calculation logic, admin API for setting locked units, and updates withdrawal validation to check unlocked balance instead of blocking all withdrawals with active channels
frameworks/rooch-framework/sources/tests/payment_channel_test.move Adds tests for unlocked balance behavior with active channels and updates existing tests to reflect new withdrawal logic that allows partial withdrawals when locked reserves are maintained
Comments suppressed due to low confidence (1)

frameworks/rooch-framework/sources/payment_channel.move:1525

  • The documentation comment states "does not check for active channels", but this is misleading. The function bypasses the unlocked balance check entirely, not just the active channels check. This could allow the transaction_gas module (the only friend) to withdraw locked reserves, potentially leaving channels underfunded.

Consider updating the comment to be more explicit: "does not check unlocked balance requirements or locked reserves" and ensure the transaction_gas module has proper safeguards to avoid withdrawing funds that should remain locked for active channels.

    /// Internal function to withdraw specific coin type from payment hub 
    /// (no signer required and does not check for active channels)
    /// Used by system contracts like transaction_gas module

Comment thread frameworks/rooch-framework/sources/payment_channel.move
Comment thread frameworks/rooch-framework/sources/payment_channel.move
Comment thread frameworks/rooch-framework/sources/payment_channel.move Outdated
Comment thread frameworks/rooch-framework/sources/payment_channel.move Outdated
Comment thread frameworks/rooch-framework/sources/payment_channel.move Outdated
Comment thread frameworks/rooch-framework/sources/payment_channel.move
@jolestar

Copy link
Copy Markdown
Contributor Author

Implemented requested changes:\n- Added LockedUnitConfigUpdatedEvent and emit in set_locked_unit\n- Enforced locked_unit monotonic non-decreasing updates to avoid sudden unlocks\n- Removed redundant copies/wrapper in locked unit helpers\n\nRe-ran: target/debug/rooch move test -p frameworks/rooch-framework payment_channel (pass).

@jolestar

Copy link
Copy Markdown
Contributor Author

Addressed review feedback:\n- Added LockedUnitConfigUpdatedEvent and emit in set_locked_unit\n- set_locked_unit now enforces non-decreasing updates (avoids sudden unlock when channels active)\n- Removed redundant copies/wrapper and simplified helper logic\n\nTests rerun: target/debug/rooch move test -p frameworks/rooch-framework payment_channel (pass).

@jolestar

Copy link
Copy Markdown
Contributor Author

@copilot addressed: locked unit event + monotonic update + copy cleanup already pushed; overflow concern noted but left as-is per discussion (Move aborts on overflow, governance expected to set sane values).

Copilot AI commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

@jolestar I've opened a new pull request, #3792, to work on those changes. Once the pull request is ready, I'll request review from you.

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.

PaymentHub: Allow withdrawals/transfers with active channels via global per-coin locked_unit × active channel count

3 participants