mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-29 23:33:33 +02:00
Merge bitcoin/bitcoin#33223: coinselection: Tiebreak SRD eviction by weight
eff9e798b9coinselection: Tiebreak SRD eviction by weight (Murch) Pull request description: yancyribbens [pointed out](https://github.com/p2pderivatives/rust-bitcoin-coin-selection/pull/108#issuecomment-3202107069) that SRD would fail to find a possible solution if there are multiple UTXOs of the same effective value with diverse weight. This adds a tiebreaker that will make SRD succeed in such a scenario. ACKs for top commit: yancyribbens: utACKeff9e798b9Tree-SHA512: 6a26f3c06f3346cef7e06926d9f747ecea91f057435f22fa8c3333f129227cf5a361f45047003e8a762a99225e3df27e3980a8b4397b36dc9b59c44a9626a2ec
This commit is contained in:
@@ -529,7 +529,7 @@ class MinOutputGroupComparator
|
||||
public:
|
||||
int operator() (const OutputGroup& group1, const OutputGroup& group2) const
|
||||
{
|
||||
return group1.GetSelectionAmount() > group2.GetSelectionAmount();
|
||||
return descending_effval_weight(group1, group2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -283,6 +283,13 @@ BOOST_AUTO_TEST_CASE(srd_test)
|
||||
AddDuplicateCoins(utxo_pool, /*count=*/3, /*amount=*/7 * CENT, cs_params);
|
||||
TestSRDSuccess("Select most valuable UTXOs for acceptable weight", utxo_pool, /*selection_target=*/20 * CENT, cs_params, /*max_selection_weight=*/4 * 4 * (P2WPKH_INPUT_VSIZE - 1 ));
|
||||
TestSRDFail("No acceptable weight possible", utxo_pool, /*selection_target=*/25 * CENT, cs_params, /*max_selection_weight=*/4 * 3 * P2WPKH_INPUT_VSIZE, /*expect_max_weight_exceeded=*/true);
|
||||
|
||||
// Create UTXO pool with UTXOs of same effective value but different weights
|
||||
std::vector<OutputGroup> mixed_weight_pool;
|
||||
AddDuplicateCoins(mixed_weight_pool, /*count=*/100, /*amount=*/5 * CENT, cs_params);
|
||||
mixed_weight_pool.push_back(MakeCoin(5 * CENT, true, cs_params, /*custom_spending_vsize=*/P2WPKH_INPUT_VSIZE - 1));
|
||||
TestSRDSuccess("Tie-break same effective value with lower weight", utxo_pool, /*selection_target=*/9 * CENT, cs_params,
|
||||
/*max_selection_weight=*/4 * 3 * (P2WPKH_INPUT_VSIZE - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user