Skip to content

Commit f8ad2a5

Browse files
committed
Make GetEntriesForConflicts return std::optional
Avoids reusing err_string.
1 parent b3a2b8c commit f8ad2a5

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/policy/rbf.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx)
4747
return SignalsOptInRBF(tx) ? RBFTransactionState::REPLACEABLE_BIP125 : RBFTransactionState::UNKNOWN;
4848
}
4949

50-
bool GetEntriesForConflicts(const CTransaction& tx,
50+
std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx,
5151
CTxMemPool& m_pool,
5252
const CTxMemPool::setEntries& setIterConflicting,
53-
CTxMemPool::setEntries& allConflicting,
54-
std::string& err_string)
53+
CTxMemPool::setEntries& allConflicting)
5554
{
5655
AssertLockHeld(m_pool.cs);
5756
const uint256 hash = tx.GetHash();
@@ -62,18 +61,17 @@ bool GetEntriesForConflicts(const CTransaction& tx,
6261
// but we just want to be conservative to avoid doing too much
6362
// work.
6463
if (nConflictingCount > MAX_BIP125_REPLACEMENT_CANDIDATES) {
65-
err_string = strprintf("rejecting replacement %s; too many potential replacements (%d > %d)\n",
64+
return strprintf("rejecting replacement %s; too many potential replacements (%d > %d)\n",
6665
hash.ToString(),
6766
nConflictingCount,
6867
MAX_BIP125_REPLACEMENT_CANDIDATES);
69-
return false;
7068
}
7169
}
7270
// If not too many to replace, then calculate the set of
7371
// transactions that would have to be evicted
7472
for (CTxMemPool::txiter it : setIterConflicting) {
7573
m_pool.CalculateDescendants(it, allConflicting);
7674
}
77-
return true;
75+
return std::nullopt;
7876
}
7977

src/policy/rbf.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx);
4040
* mempool must not exceed a total of 100 transactions." Quit as early as possible. There cannot be
4141
* more than MAX_BIP125_REPLACEMENT_CANDIDATES potential entries.
4242
* @param[in] setIterConflicting The set of iterators to mempool entries.
43-
* @param[out] err_string Used to return errors, if any.
4443
* @param[out] allConflicting Populated with all the mempool entries that would be replaced,
4544
* which includes descendants of setIterConflicting. Not cleared at
4645
* the start; any existing mempool entries will remain in the set.
47-
* @returns false if Rule 5 is broken.
46+
* @returns an error message if Rule #5 is broken, otherwise a std::nullopt.
4847
*/
49-
bool GetEntriesForConflicts(const CTransaction& tx, CTxMemPool& m_pool,
50-
const CTxMemPool::setEntries& setIterConflicting,
51-
CTxMemPool::setEntries& allConflicting,
52-
std::string& err_string) EXCLUSIVE_LOCKS_REQUIRED(m_pool.cs);
48+
std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx, CTxMemPool& m_pool,
49+
const CTxMemPool::setEntries& setIterConflicting,
50+
CTxMemPool::setEntries& allConflicting)
51+
EXCLUSIVE_LOCKS_REQUIRED(m_pool.cs);
5352
#endif // BITCOIN_POLICY_RBF_H

src/validation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,6 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
789789
fReplacementTransaction = setConflicts.size();
790790
if (fReplacementTransaction)
791791
{
792-
std::string err_string;
793792
CFeeRate newFeeRate(nModifiedFees, nSize);
794793
for (const auto& mi : setIterConflicting) {
795794
// Don't allow the replacement to reduce the feerate of the
@@ -818,8 +817,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
818817
}
819818

820819
// Calculate all conflicting entries and enforce Rule #5.
821-
if (!GetEntriesForConflicts(tx, m_pool, setIterConflicting, allConflicting, err_string)) {
822-
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "too many potential replacements", err_string);
820+
if (const auto err_string{GetEntriesForConflicts(tx, m_pool, setIterConflicting, allConflicting)}) {
821+
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY,
822+
"too many potential replacements", *err_string);
823823
}
824824

825825
// Check if it's economically rational to mine this transaction rather

0 commit comments

Comments
 (0)