get_block_template_backlog: better sorting logic

std::sort is unstable, so it can return random sets of transactions when mempool has many transactions with the same fee/byte. It can result in p2pool mining empty blocks sometimes because it doesn't pick up "new" transactions immediately.
This commit is contained in:
SChernykh 2024-03-08 14:50:01 +01:00
parent b23116424d
commit 36ee12bd8d

View File

@ -1074,7 +1074,7 @@ namespace cryptonote
// If the total weight is too high, choose the best paying transactions // If the total weight is too high, choose the best paying transactions
if (total_weight > max_backlog_weight) if (total_weight > max_backlog_weight)
std::sort(tmp.begin(), tmp.end(), [](const auto& a, const auto& b){ return a.fee * b.weight > b.fee * a.weight; }); std::stable_sort(tmp.begin(), tmp.end(), [](const auto& a, const auto& b){ return a.fee * b.weight > b.fee * a.weight; });
backlog.clear(); backlog.clear();
uint64_t w = 0; uint64_t w = 0;