Skip to content

Commit

Permalink
[mini miner]: avoid signed-integer-overflow by comparing fee rate
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelsadeeq committed Jul 8, 2024
1 parent 0b38a86 commit b1b28a2
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/node/mini_miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit b1b28a2

Please sign in to comment.