Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "primitives/block.h"
#include "txmempool.h"

// Forward declaration of helper function from txmempool.h
bool CompareAncestorFeeRate(double aFees, double aSize, double bFees, double bSize);

#include <stdint.h>
#include <memory>
#include "boost/multi_index_container.hpp"
Expand Down Expand Up @@ -74,17 +77,20 @@ struct modifiedentry_iter {
};

// This matches the calculation in CompareTxMemPoolEntryByAncestorFee,
// except operating on CTxMemPoolModifiedEntry.
// TODO: refactor to avoid duplication of this logic.
// using the shared helper function to avoid code duplication.
struct CompareModifiedEntry {
bool operator()(const CTxMemPoolModifiedEntry &a, const CTxMemPoolModifiedEntry &b) const
{
double f1 = (double)a.nModFeesWithAncestors * b.nSizeWithAncestors;
double f2 = (double)b.nModFeesWithAncestors * a.nSizeWithAncestors;
if (f1 == f2) {
double aFees = (double)a.nModFeesWithAncestors;
double aSize = (double)a.nSizeWithAncestors;
double bFees = (double)b.nModFeesWithAncestors;
double bSize = (double)b.nSizeWithAncestors;

Comment on lines +84 to +88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Do not cast fees/size to double; keep integer types for exactness

Casting nModFeesWithAncestors and sizes to double risks precision loss and subtle ordering bugs. Keep everything in integral types and pass them directly to the helper (which should also operate on integral types).

Apply:

-        double aFees = (double)a.nModFeesWithAncestors;
-        double aSize = (double)a.nSizeWithAncestors;
-        double bFees = (double)b.nModFeesWithAncestors;
-        double bSize = (double)b.nSizeWithAncestors;
+        const CAmount aFees = a.nModFeesWithAncestors;
+        const uint64_t aSize = a.nSizeWithAncestors;
+        const CAmount bFees = b.nModFeesWithAncestors;
+        const uint64_t bSize = b.nSizeWithAncestors;

Note: This assumes the helper takes integral types; align with the actual signature in txmempool.h.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
double aFees = (double)a.nModFeesWithAncestors;
double aSize = (double)a.nSizeWithAncestors;
double bFees = (double)b.nModFeesWithAncestors;
double bSize = (double)b.nSizeWithAncestors;
const CAmount aFees = a.nModFeesWithAncestors;
const uint64_t aSize = a.nSizeWithAncestors;
const CAmount bFees = b.nModFeesWithAncestors;
const uint64_t bSize = b.nSizeWithAncestors;
🤖 Prompt for AI Agents
In src/miner.h around lines 84 to 88, the code casts fee and size values from
integers to double, risking precision loss and ordering bugs. Remove the casts
and keep these variables as their original integral types, passing them directly
to the helper function. Also, verify and align the helper function's signature
in txmempool.h to accept integral types accordingly.

if (CompareAncestorFeeRate(aFees, aSize, bFees, bSize) == CompareAncestorFeeRate(bFees, bSize, aFees, aSize)) {
return CTxMemPool::CompareIteratorByHash()(a.iter, b.iter);
}
return f1 > f2;

return CompareAncestorFeeRate(aFees, aSize, bFees, bSize);
}
};

Expand Down