Skip to content

Commit

Permalink
Mitigate timeout in CalculateTotalBumpFees
Browse files Browse the repository at this point in the history
The slow fuzz seed described in bitcoin#27799 was just slower than expected,
not an endless loop. Ensuring that every anscestor is only processed
once speeds up the termination of the graph traversal.

Fixes bitcoin#27799
  • Loading branch information
murchandamus committed Jun 1, 2023
1 parent 34ac3f4 commit 5d718f6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/node/mini_miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,20 @@ std::optional<CAmount> MiniMiner::CalculateTotalBumpFees(const CFeeRate& target_
to_process.insert(iter);
ancestors.insert(iter);
}

std::set<uint256> has_been_processed;
while (!to_process.empty()) {
auto iter = to_process.begin();
const CTransaction& tx = (*iter)->second.GetTx();
for (const auto& input : tx.vin) {
if (auto parent_it{m_entries_by_txid.find(input.prevout.hash)}; parent_it != m_entries_by_txid.end()) {
to_process.insert(parent_it);
if (!has_been_processed.count(input.prevout.hash)) {
to_process.insert(parent_it);
}
ancestors.insert(parent_it);
}
}
has_been_processed.insert(tx.GetHash());
to_process.erase(iter);
}
const auto ancestor_package_size = std::accumulate(ancestors.cbegin(), ancestors.cend(), int64_t{0},
Expand Down

0 comments on commit 5d718f6

Please sign in to comment.