Skip to content

test: SRD tie-break test - #36740

Open
Zeegaths wants to merge 1 commit into
bitcoin:masterfrom
Zeegaths:srd-tiebreak-check
Open

Zeegaths wants to merge 1 commit into
bitcoin:masterfrom
Zeegaths:srd-tiebreak-check

Conversation

@Zeegaths

@Zeegaths Zeegaths commented Nov 3, 2026 •

Copy link
Copy Markdown

I was researching coin selection when I came across this bug, so I thought I'd fix it

Pr #33223 adjusts weight selection to keep the lighter coin when two coins have the same value, but the test has two mistakes, as confirmed in this comment

  1. It builds mixed_weight_pool but passes utxo_pool to TestSRDSuccess.
  2. There is nothing enforcing coin eviction because the current max weight (4 * 3 * 67 = 804 WU) fits any two coins (544 WU)

If you reverse #33223, it still passes, which means it misses the tie-break

The fix

The test now uses `mixed_weight_pool and adds an extra light coin so that only two light coins can fit together and evicts a coin on every tie to pass.
Lowers the max weight to 536 WU; SRD now has to evict the heavier coin on every tie to succeed

This should show failed tests with bitcoin#33223 reverted and pass on master.

@DrahtBot DrahtBot added the Tests label Nov 3, 2026
@DrahtBot

DrahtBot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK yancyribbens, frankomosh
Concept ACK psychemist
Stale ACK Zippo76, mercie-ux

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36255 (Refactor CoinGrinder tests by murchandamus)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@yancyribbens

Copy link
Copy Markdown
Contributor

Concept ACK.

PR 33223 added a tie breaker condition such that if two UTXOs are the same effective_value, sort such that the lighter UTXO is preferred. This creates a lighter and thus cheaper transaction.

The sort is defined by 33223 here:

class MinOutputGroupComparator
{
public:
    int operator() (const OutputGroup& group1, const OutputGroup& group2) const
    {
        return descending_effval_weight(group1, group2);
    }
};

However, the test added did not actually test the new behavior since selecting two UTXOs needed to hit the target did not cause an eviction to take place. Confirmed that this PR fixes that by lowering the weight limit which causes the heap to pop an item, and in so doing, must sort and then perform the eviction. The second lighter UTXO is added such that the only solution that causes completion is when both lighter UTXOs remain and the heavier UTXOs evicted.

Approach ACK

Comment thread src/wallet/test/coinselection_tests.cpp Resolved
Comment thread src/wallet/test/coinselection_tests.cpp Resolved
@Zeegaths
Zeegaths force-pushed the srd-tiebreak-check branch 2 times, most recently from 87756e7 to 2ade73d Compare November 4, 2026 08:47
@winterrdog

winterrdog commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

From https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md

The description for a new pull request should not contain any @ mentions. The PR description will be included in the commit message when the PR is merged and any users mentioned in the description will be annoyingly notified each time a fork of Bitcoin Core copies the merge. Instead, make any username mentions in a subsequent comment to the PR.

@Zeegaths

Zeegaths commented Nov 4, 2026

Copy link
Copy Markdown
Author

From https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md

The description for a new pull request should not contain any @ mentions. The PR description will be included in the commit message when the PR is merged and any users mentioned in the description will be annoyingly notified each time a fork of Bitcoin Core copies the merge. Instead, make any username mentions in a subsequent comment to the PR.

noted, Thanks for this

@yancyribbens

Copy link
Copy Markdown
Contributor

ACK 2ade73d

@Zippo76 Zippo76 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tACK 2ade73d

Tested on macOS 27.0.1 arm64, using master fcf76ea549 for comparison. srd_test passes on the PR.
With the comparator change from #33223 reverted, the PR’s test fails while master’s test passes.
I also checked that the 536 WU limit only allows the two lighter coins together. Whenever a heavier coin makes the selection exceed that limit, it must be evicted for selection to succeed.

@sedited

sedited commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@Zeegaths please write your pull request descriptions in your own words. Not doing so is in violation of our AI policy. Most of the lines are basically redundant statements. Reviewers are expected to know basic git usage, how to run the tests and make them fail by undoing prior work, and read a diff to figure out which tests are changed. What it should say is why the change is important to you.

@Zeegaths

Zeegaths commented Nov 6, 2026 •

Copy link
Copy Markdown
Author

@Zeegaths please write your pull request descriptions in your own words. Not doing so is in violation of our AI policy. Most of the lines are basically redundant statements. Reviewers are expected to know basic git usage, how to run the tests and make them fail by undoing prior work, and read a diff to figure out which tests are changed. What it should say is why the change is important to you.

i see what you mean. lmk if that works

@sedited

sedited commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

lmk if that works

It does read a bit better. I think people can count for themselves how many tests are being run though.

@Zeegaths

Zeegaths commented Nov 6, 2026

Copy link
Copy Markdown
Author

lmk if that works

It does read a bit better. I think people can count for themselves how many tests are being run though.

got it, thankyou

@yancyribbens

Copy link
Copy Markdown
Contributor

If you reverse #33223, it still passes, which means it misses the tie-break

Note that this is a non-deterministic code path being tested. It looks like because of issue 1) it would never fail if 33223 is revered. However, I think 2) may fail if 33223 is undone and the random selection happened to select the lighter coin on it's first attempt even with no eviction, although this is very unlikely.

@Zeegaths

Zeegaths commented Nov 6, 2026

Copy link
Copy Markdown
Author

If you reverse #33223, it still passes, which means it misses the tie-break

Note that this is a non-deterministic code path being tested. It looks like because of issue 1) it would never fail if 33223 is revered. However, I think 2) may fail if 33223 is undone and the random selection happened to select the lighter coin on it's first attempt even with no eviction, although this is very unlikely.

noted

@yancyribbens

Copy link
Copy Markdown
Contributor

@Zeegaths
Zeegaths force-pushed the srd-tiebreak-check branch from 2ade73d to b1240a8 2 hours ago

When you force push like this it dismisses the reviews people have done. And if you don't explain why you are force pushing, it requires people to need to re-review all changes. Is this just a rebase? If so, it's nice to say that so people reviewing save time trying to figure out what changed.

@Zeegaths

Zeegaths commented Nov 6, 2026

Copy link
Copy Markdown
Author

@Zeegaths
Zeegaths force-pushed the srd-tiebreak-check branch from 2ade73d to b1240a8 2 hours ago

When you force push like this it dismisses the reviews people have done. And if you don't explain why you are force pushing, it requires people to need to re-review all changes. Is this just a rebase? If so, it's nice to say that so people reviewing save time trying to figure out what changed.

yes, It's just a rebase

@Zippo76 Zippo76 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

re-ACK b1240a8

The range-diff against 2ade73d shows an unchanged patch.

@DrahtBot
DrahtBot requested a review from yancyribbens November 7, 2026 17:00

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

Tested ACK b1240a8.

@fanquake

fanquake commented Nov 9, 2026

Copy link
Copy Markdown
Member

cc @murchandamus

@mercie-ux

Copy link
Copy Markdown
Contributor

ACK b1240a8

@psychemist

psychemist commented Nov 15, 2026 •

Copy link
Copy Markdown

tested ACK

tested the committed changes and they fail against the production fix at eff9e79 but pass on the PR's latest commit at b1240a8

@maflcko maflcko removed the CI failed label Nov 16, 2026
Comment thread src/wallet/test/coinselection_tests.cpp Resolved
The test in bitcoin#33223 builds `mixed_weight_pool` but passes
`utxo_pool` to `TestSRDSuccess`, and the max weight (804 WU) fits
any two coins, so SRD never evicts and the tie-break never runs.

Pass `mixed_weight_pool` instead of `utxo_pool`.
add an extra light coin and lower the max weight to 536 WU so that
the heavier coin gets evicted on every tie.
asserts the resulting utxos on success.
@yancyribbens

Copy link
Copy Markdown
Contributor

ACK 751956e

CI looks like its down, however tests pass locally.

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

reACK 751956e . Only change is switching to the TestSRDSuccess helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.