Skip to content

Commit ab879d9

Browse files
committed
Merge bitcoin/bitcoin#23762: wallet: Replace Assume with Assert where needed in coinselection
fa26c55 wallet: Replace Assume with Assert where needed in coinselection (MarcoFalke) Pull request description: `Assume` should only be used when a failed check is recoverable. The checks here don't recover and would run into UB, so use `Assert` instead. ACKs for top commit: theStack: Code-review ACK fa26c55 Tree-SHA512: 0cf9435f9ec44794022ce0274cba602aec95102ab73f4c8a93dae54ef4c0a594f6a81640477039719ddfb6f23b05f8ece3e4886ef7f8a725efff45685ac49d92
2 parents 5dd28e5 + fa26c55 commit ab879d9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/wallet/coinselection.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ void SelectionResult::ComputeAndSetWaste(CAmount change_cost)
390390

391391
CAmount SelectionResult::GetWaste() const
392392
{
393-
Assume(m_waste != std::nullopt);
394-
return *m_waste;
393+
return *Assert(m_waste);
395394
}
396395

397396
CAmount SelectionResult::GetSelectedValue() const
@@ -425,8 +424,8 @@ std::vector<CInputCoin> SelectionResult::GetShuffledInputVector() const
425424

426425
bool SelectionResult::operator<(SelectionResult other) const
427426
{
428-
Assume(m_waste != std::nullopt);
429-
Assume(other.m_waste != std::nullopt);
427+
Assert(m_waste.has_value());
428+
Assert(other.m_waste.has_value());
430429
// As this operator is only used in std::min_element, we want the result that has more inputs when waste are equal.
431430
return *m_waste < *other.m_waste || (*m_waste == *other.m_waste && m_selected_inputs.size() > other.m_selected_inputs.size());
432431
}

0 commit comments

Comments
 (0)