test: SRD tie-break test #36740

Open
Zeegaths wants to merge 1 commit from srd-tiebreak-check into master AGit
Zeegaths commented 2026-11-03 06:26:28 +00:00 (Migrated from github.com)

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.

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 ](https://github.com/bitcoin/bitcoin/pull/36255#discussion_r4432516127) 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](https://github.com/bitcoin/bitcoin/pull/33223) reverted and pass on master.
DrahtBot commented 2026-11-03 06:26:37 +00:00 (Migrated from github.com)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36740 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36740.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36740#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [yancyribbens](https://github.com/bitcoin/bitcoin/pull/36740#issuecomment-7062349764), [frankomosh](https://github.com/bitcoin/bitcoin/pull/36740#pullrequestreview-6025192147) | | Concept ACK | [psychemist](https://github.com/bitcoin/bitcoin/pull/36740#issuecomment-6898697605) | | Stale ACK | [Zippo76](https://github.com/bitcoin/bitcoin/pull/36740#pullrequestreview-5813861304), [mercie-ux](https://github.com/bitcoin/bitcoin/pull/36740#issuecomment-6749704013) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36255](https://github.com/bitcoin/bitcoin/pull/36255) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36255.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 751956e3ca9b · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3705f06c6a27c475c77f2533c4d016ac03c829c839b7b538bba5e4768ccf54f1:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:004cfb21a51db563b92cde968f249086ef58df7c --> <!-- ralph-head:751956e3ca9bb7fff8f9e13cf5cd2f1dd054f849 --> <!-- ralph-case:bd928736bf1b8372a0808282f04df79bdeb2bc5c015b154712aebd23cd45f21d --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`751956e3ca9b`](<https://git.fish.foo/bitcoin/bitcoin/commit/751956e3ca9bb7fff8f9e13cf5cd2f1dd054f849>) · [Review report](<https://review.fish.foo/report/36740-751956e3ca9bb7fff8f9e13cf5cd2f1dd054f849-2911-5.html>) · [Previous reports](<https://review.fish.foo/traces/36740/>) [permalink](<https://review.fish.foo/report/36740-751956e3ca9bb7fff8f9e13cf5cd2f1dd054f849-2911-5.html>)
yancyribbens commented 2026-11-03 15:04:46 +00:00 (Migrated from github.com)

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

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: ```c++ 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
yancyribbens (Migrated from github.com) reviewed 2026-11-03 15:06:01 +00:00
yancyribbens (Migrated from github.com) commented 2026-11-03 15:06:01 +00:00

just a nit, but I think this for loop just adds test complexity. There are only two utxos, so it would be more clean to just assert the weight of each UTXO without a loop.

just a nit, but I think this for loop just adds test complexity. There are only two utxos, so it would be more clean to just assert the weight of each UTXO without a loop.
yancyribbens (Migrated from github.com) reviewed 2026-11-03 15:07:05 +00:00
yancyribbens (Migrated from github.com) commented 2026-11-03 15:07:05 +00:00

nit, I think this require is superfluous since even without it, the next asserts couldn't pass.

nit, I think this require is superfluous since even without it, the next asserts couldn't pass.
Zeegaths (Migrated from github.com) reviewed 2026-11-04 08:49:48 +00:00
Zeegaths (Migrated from github.com) commented 2026-11-04 08:49:48 +00:00

done, removed

done, removed
Zeegaths (Migrated from github.com) reviewed 2026-11-04 08:54:40 +00:00
Zeegaths (Migrated from github.com) commented 2026-11-04 08:54:40 +00:00

replaced the loop with a weight check

replaced the loop with a weight check
winterrdog commented 2026-11-04 09:15:27 +00:00 (Migrated from github.com)

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.

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 commented 2026-11-04 09:31:27 +00:00 (Migrated from github.com)

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

> 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 commented 2026-11-04 15:02:16 +00:00 (Migrated from github.com)
ACK 2ade73da7ace76d6f6cc630fe01b275c39fb9401
Zippo76 (Migrated from github.com) reviewed 2026-11-06 07:03:04 +00:00
Zippo76 (Migrated from github.com) left a comment

tACK 2ade73da7a

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.

tACK 2ade73da7a 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 commented 2026-11-06 12:37:34 +00:00 (Migrated from github.com)

@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 please write your pull request descriptions in your own words. Not doing so is in violation of our [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md). 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 commented 2026-11-06 13:09:11 +00:00 (Migrated from github.com)

@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

> @Zeegaths please write your pull request descriptions in your own words. Not doing so is in violation of our [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md). 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 commented 2026-11-06 13:34:50 +00:00 (Migrated from github.com)

lmk if that works

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

> 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 commented 2026-11-06 13:44:20 +00:00 (Migrated from github.com)

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

> > 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 commented 2026-11-06 14:48:12 +00:00 (Migrated from github.com)

If you reverse https://github.com/bitcoin/bitcoin/pull/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.

> If you reverse https://github.com/bitcoin/bitcoin/pull/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 commented 2026-11-06 14:58:33 +00:00 (Migrated from github.com)

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

> > 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 commented 2026-11-06 19:27:34 +00:00 (Migrated from github.com)

@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](https://github.com/Zeegaths) Zeegaths [force-pushed](https://github.com/bitcoin/bitcoin/compare/2ade73da7ace76d6f6cc630fe01b275c39fb9401..b1240a856e1a8f45e0dff4b600bf07605c23ed1a) the srd-tiebreak-check branch from [2ade73d](https://github.com/bitcoin/bitcoin/commit/2ade73da7ace76d6f6cc630fe01b275c39fb9401) to [b1240a8](https://github.com/bitcoin/bitcoin/commit/b1240a856e1a8f45e0dff4b600bf07605c23ed1a) [2 hours ago](https://github.com/bitcoin/bitcoin/pull/36740#event-35369963119) 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 commented 2026-11-06 19:55:02 +00:00 (Migrated from github.com)

@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

> > @[Zeegaths](https://github.com/Zeegaths) > > Zeegaths [force-pushed](https://github.com/bitcoin/bitcoin/compare/2ade73da7ace76d6f6cc630fe01b275c39fb9401..b1240a856e1a8f45e0dff4b600bf07605c23ed1a) the srd-tiebreak-check branch from [2ade73d](https://github.com/bitcoin/bitcoin/commit/2ade73da7ace76d6f6cc630fe01b275c39fb9401) to [b1240a8](https://github.com/bitcoin/bitcoin/commit/b1240a856e1a8f45e0dff4b600bf07605c23ed1a) [2 hours ago](https://github.com/bitcoin/bitcoin/pull/36740#event-35369963119) > > 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 (Migrated from github.com) reviewed 2026-11-07 17:00:24 +00:00
Zippo76 (Migrated from github.com) left a comment

re-ACK b1240a856e

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

re-ACK b1240a856e The range-diff against 2ade73da7a shows an unchanged patch.
frankomosh (Migrated from github.com) reviewed 2026-11-09 15:13:42 +00:00
frankomosh (Migrated from github.com) left a comment

Tested ACK b1240a856e.

Tested ACK b1240a856e1a8f45e0dff4b600bf07605c23ed1a.
fanquake commented 2026-11-09 15:15:41 +00:00 (Migrated from github.com)

cc @murchandamus

cc @murchandamus
mercie-ux commented 2026-11-09 19:44:55 +00:00 (Migrated from github.com)
ACK b1240a856e1a8f45e0dff4b600bf07605c23ed1a
psychemist commented 2026-11-15 17:50:26 +00:00 (Migrated from github.com)

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

tested ACK tested the committed changes and they fail against the production fix at [`eff9e79`](https://github.com/bitcoin/bitcoin/commit/eff9e798b95ef06e0899f348f142703e8504ac5d) but pass on the PR's latest commit at [`b1240a8`](https://github.com/bitcoin/bitcoin/commit/b1240a856e1a8f45e0dff4b600bf07605c23ed1a)
achow101 (Migrated from github.com) reviewed 2026-11-20 22:59:17 +00:00
achow101 (Migrated from github.com) commented 2026-11-20 22:59:17 +00:00

Please use the helper function rather than duplicating the checks

Please use the helper function rather than duplicating the checks
Zeegaths (Migrated from github.com) reviewed 2026-11-21 06:11:24 +00:00
Zeegaths (Migrated from github.com) commented 2026-11-21 06:11:24 +00:00

Switched the checks to the helper function 751956e

Switched the checks to the helper function [751956e](https://github.com/bitcoin/bitcoin/pull/36740/commits/751956e3ca9bb7fff8f9e13cf5cd2f1dd054f849)
yancyribbens commented 2026-11-21 12:07:48 +00:00 (Migrated from github.com)

ACK 751956e3ca

CI looks like its down, however tests pass locally.

ACK 751956e3ca9bb7fff8f9e13cf5cd2f1dd054f849 CI looks like its down, however tests pass locally.
frankomosh (Migrated from github.com) reviewed 2026-11-23 16:20:41 +00:00
frankomosh (Migrated from github.com) left a comment

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

reACK 751956e3ca9bb7fff8f9e13cf5cd2f1dd054f849 . Only change is switching to the TestSRDSuccess helper.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36740
No description provided.