rust-payjoin icon indicating copy to clipboard operation
rust-payjoin copied to clipboard

feat: add consolidation input selection strategy

Open IgnacioPorte opened this issue 10 months ago • 1 comments

Add Consolidation Input Selection Strategy

Overview

This PR introduces a new input selection strategy for receivers that optimizes for UTXO consolidation. This enables receivers to use payjoins as an opportunity to consolidate their UTXOs efficiently, improving their wallet's long-term UTXO management.

Features

  • New SelectionStrategy::Consolidate option for receiver input selection
  • Configurable parameters to control consolidation behavior:
    • max_consolidation_fee_rate: Only consolidate when fees are below this threshold
    • max_inputs: Limit the number of inputs to add
    • target_value: Optionally stop adding inputs after reaching a target amount
    • dust_limit: Minimum value for inputs to be considered

Implementation Details

  • Inputs are sorted by value (ascending) and added until reaching either max_inputs or target_value
  • Consolidation only proceeds if current transaction fee rate is below the specified threshold
  • Maintains compatibility with existing privacy-preserving selection strategy
  • V2 receiver implementation delegates to V1 for actual consolidation logic

Considerations

  • Testing pending
  • CLI changes pending to expose consolidation strategy and its parameters
  • While providing numerous parameters could offer flexibility, it might also lead to unnecessary complexity. We need to strike the right balance between configurability and simplicity.

Related Issues

#460

IgnacioPorte avatar Feb 28 '25 02:02 IgnacioPorte

Pull Request Test Coverage Report for Build 13778844253

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 5 of 81 (6.17%) changed or added relevant lines in 3 files are covered.
  • 11 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-1.2%) to 78.547%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/receive/error.rs 0 3 0.0%
payjoin/src/receive/v2/mod.rs 5 30 16.67%
payjoin/src/receive/v1/mod.rs 0 48 0.0%
<!-- Total: 5 81
Files with Coverage Reduction New Missed Lines %
payjoin/src/receive/v2/mod.rs 11 79.79%
<!-- Total: 11
Totals Coverage Status
Change from base Build 13751979319: -1.2%
Covered Lines: 4562
Relevant Lines: 5808

💛 - Coveralls

coveralls avatar Mar 03 '25 17:03 coveralls

Closing as stale and due to the feature freeze for 1.0 milestone

spacebear21 avatar Aug 21 '25 13:08 spacebear21