Merge pull request #6458 from sellout/safer-note-selection

Make pool selection order more flexible
This commit is contained in:
Kris Nuttycombe 2023-03-08 13:53:11 -07:00 committed by GitHub
commit 62a0e78e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -8063,9 +8063,6 @@ bool SpendableInputs::LimitToAmount(
// Fully shielded. // Fully shielded.
selectionOrder = { selectionOrder = {
OutputPool::Orchard, OutputPool::Orchard,
// Pools below here are erased.
OutputPool::Transparent,
OutputPool::Sapling,
}; };
} else if ( } else if (
recipientPools.count(OutputPool::Transparent) && recipientPools.count(OutputPool::Transparent) &&
@ -8075,9 +8072,6 @@ bool SpendableInputs::LimitToAmount(
// Fewer pools. // Fewer pools.
selectionOrder = { selectionOrder = {
OutputPool::Orchard, OutputPool::Orchard,
// Pools below here are erased.
OutputPool::Transparent,
OutputPool::Sapling,
}; };
} else if (wouldSuffice(availableSapling + availableOrchard)) { } else if (wouldSuffice(availableSapling + availableOrchard)) {
// Hide sender. // Hide sender.
@ -8087,8 +8081,6 @@ bool SpendableInputs::LimitToAmount(
selectionOrder = { selectionOrder = {
OutputPool::Sapling, OutputPool::Sapling,
OutputPool::Orchard, OutputPool::Orchard,
// Pools below here are erased.
OutputPool::Transparent,
}; };
} else { } else {
// Opportunistic shielding. // Opportunistic shielding.
@ -8100,14 +8092,25 @@ bool SpendableInputs::LimitToAmount(
opportunisticShielding = true; opportunisticShielding = true;
} }
// Ensure we provided a total selection order (so that all unselected notes // Erase all notes and coins from pools that arent used in selection.
// and coins are erased).
for (auto pool : available) { for (auto pool : available) {
bool poolIsPresent = false; bool poolIsPresent = false;
for (auto entry : selectionOrder) { for (auto entry : selectionOrder) {
poolIsPresent |= entry == pool; poolIsPresent |= entry == pool;
} }
assert(poolIsPresent); if (!poolIsPresent) {
switch (pool) {
case OutputPool::Transparent:
utxos.clear();
break;
case OutputPool::Sapling:
saplingNoteEntries.clear();
break;
case OutputPool::Orchard:
orchardNoteMetadata.clear();
break;
}
}
} }
// Finally, select the remaining notes and coins based on this order. // Finally, select the remaining notes and coins based on this order.