Skip to content

Commit

Permalink
[policy]: make CFeeRate work with uint64_t sizes
Browse files Browse the repository at this point in the history
Co-authored-by: Pieter Wuille <bitcoin-dev@wuille.net>
  • Loading branch information
2 people authored and ismaelsadeeq committed Jul 3, 2024
1 parent 3714692 commit 550a6c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/policy/feerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include <cmath>

CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes)
CFeeRate::CFeeRate(const CAmount& nFeePaid, uint64_t num_bytes)
{
const int64_t nSize{num_bytes};
const int64_t nSize{static_cast<int64_t>(num_bytes)};

if (nSize > 0) {
nSatoshisPerK = nFeePaid * 1000 / nSize;
Expand All @@ -20,9 +20,9 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes)
}
}

CAmount CFeeRate::GetFee(uint32_t num_bytes) const
CAmount CFeeRate::GetFee(uint64_t num_bytes) const
{
const int64_t nSize{num_bytes};
const int64_t nSize{static_cast<int64_t>(num_bytes)};

// Be explicit that we're converting from a double to int64_t (CAmount) here.
// We've previously had issues with the silent double->int64_t conversion.
Expand Down
4 changes: 2 additions & 2 deletions src/policy/feerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ class CFeeRate
* param@[in] nFeePaid The fee paid by a transaction, in satoshis
* param@[in] num_bytes The vsize of a transaction, in vbytes
*/
CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes);
CFeeRate(const CAmount& nFeePaid, uint64_t num_bytes);

/**
* Return the fee in satoshis for the given vsize in vbytes.
* If the calculated fee would have fractional satoshis, then the
* returned fee will always be rounded up to the nearest satoshi.
*/
CAmount GetFee(uint32_t num_bytes) const;
CAmount GetFee(uint64_t num_bytes) const;

/**
* Return the fee in satoshis for a vsize of 1000 vbytes
Expand Down

0 comments on commit 550a6c2

Please sign in to comment.