From b1b28a21e185dfbc0c75f92ac55401a9ba8a5b08 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Thu, 13 Jun 2024 19:55:23 +0100 Subject: [PATCH] [mini miner]: avoid signed-integer-overflow by comparing fee rate --- src/node/mini_miner.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/node/mini_miner.cpp b/src/node/mini_miner.cpp index c219a8aea1286a..84181623b47f35 100644 --- a/src/node/mini_miner.cpp +++ b/src/node/mini_miner.cpp @@ -189,11 +189,7 @@ struct AncestorFeerateComparator const int64_t ancestor_size{e.GetSizeWithAncestors()}; const CAmount tx_fee{e.GetModifiedFee()}; const int64_t tx_size{e.GetTxSize()}; - // Comparing ancestor feerate with individual feerate: - // ancestor_fee / ancestor_size <= tx_fee / tx_size - // Avoid division and possible loss of precision by - // multiplying both sides by the sizes: - return ancestor_fee * tx_size < tx_fee * ancestor_size ? + return CFeeRate(ancestor_fee, ancestor_size) <= CFeeRate(tx_fee, tx_size) ? CFeeRate(ancestor_fee, ancestor_size) : CFeeRate(tx_fee, tx_size); };