Skip to content

[GEN-1815] Implement closest utxo selection algorithm - #565

Open
imclvr wants to merge 1 commit into
feat/improve-coin-selection-refactorfrom
feat/improve-coin-selection-with-ff
Open

[GEN-1815] Implement closest utxo selection algorithm#565
imclvr wants to merge 1 commit into
feat/improve-coin-selection-refactorfrom
feat/improve-coin-selection-with-ff

Conversation

@imclvr

@imclvr imclvr commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Title self-explanatory


Stack created with GitHub Stacks CLIGive Feedback 💬

@imclvr
imclvr requested review from Jossec101, RodriFS and daliclovr and a lite review from Copilot August 12, 2026 12:29

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 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 SelectUTXOsByClosest and 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.

Comment thread src/Helpers/UTXOSelectionAlgorithms.cs
Comment thread src/Helpers/UTXOSelectionAlgorithms.cs
@imclvr
imclvr force-pushed the feat/improve-coin-selection-with-ff branch from cac9ab4 to 9aca8c9 Compare August 17, 2026 07:45
@imclvr
imclvr requested a review from manumonti August 17, 2026 08:51
Wallet wallet, long satsAmount, List<UTXO> availableUTXOs, ILogger logger)
{
return new List<UTXO>();
var selectedUTXOs = new List<UTXO>();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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 😬 .

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.

2 participants