[GEN-1815] Implement closest utxo selection algorithm - #565
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements a “closest-to-amount” UTXO selection algorithm in UTXOSelectionAlgorithms and adds/updates unit tests to validate both the new selection behavior and the CoinSelectionService routing flag.
Changes:
- Implemented
SelectUTXOsByClosestand refactored shared argument/funding validation into a helper method. - Added dedicated unit tests for the closest-selection algorithm, plus shared “no UTXOs” / “insufficient funds” coverage for both algorithms.
- Strengthened an existing CoinSelectionService test to ensure the “closest” path produces a non-empty, distinguishable selection.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/NodeGuard.Tests/Services/CoinSelectionServiceTests.cs | Tightens the closest-selection routing assertion by ensuring the expected selection is non-empty. |
| test/NodeGuard.Tests/Helpers/UTXOSelectionAlgorithmsTests.cs | Adds focused unit tests for the closest-selection algorithm plus shared edge-case coverage. |
| src/Helpers/UTXOSelectionAlgorithms.cs | Implements closest-selection and introduces shared validation logic for selection algorithms. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
cac9ab4 to
9aca8c9
Compare
| Wallet wallet, long satsAmount, List<UTXO> availableUTXOs, ILogger logger) | ||
| { | ||
| return new List<UTXO>(); | ||
| var selectedUTXOs = new List<UTXO>(); |
There was a problem hiding this comment.
@daliclovr @RodriFS regarding the debate raised whether to implement this on NBXplorer, main reason I took for implementing it on NG is that, when this is called, utxos has been already selected priorly given derivation strategy that comes from the wallet.
We could add the strategy we want on there, but that's for getting all available utxos. Then, we would still be selecting by order.
We could maybe talk this offline in more detail. @RodriFS I will borrow your time 😬 .
Title self-explanatory
Stack created with GitHub Stacks CLI • Give Feedback 💬