aboutsummaryrefslogtreecommitdiff
path: root/src/policy
diff options
context:
space:
mode:
authorPatrick Lodder <[email protected]>2021-07-12 01:03:05 +0200
committerGitHub <[email protected]>2021-07-12 01:03:05 +0200
commitb1a924969057693a55c458ab53894f677abe1823 (patch)
tree389dffcde9239314e72c2bd5e05c2b74aec3f2a0 /src/policy
parentMerge pull request #2288 from fdoving/fdov-depends-libevent (diff)
parentAdd warning log message if overriding -blockmintxfee (diff)
downloaddiscoin-1.21-dev.tar.xz
discoin-1.21-dev.zip
Merge pull request #2311 from rnicoll/1.21-subsidy-tests1.21-dev
Rewrite subsidy limit tests (1.21)
Diffstat (limited to 'src/policy')
-rw-r--r--src/policy/feerate.cpp3
-rw-r--r--src/policy/feerate.h23
2 files changed, 17 insertions, 9 deletions
diff --git a/src/policy/feerate.cpp b/src/policy/feerate.cpp
index 04e0e117a..aeeb341ea 100644
--- a/src/policy/feerate.cpp
+++ b/src/policy/feerate.cpp
@@ -13,7 +13,8 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_)
int64_t nSize = int64_t(nBytes_);
if (nSize > 0)
- nSatoshisPerK = nFeePaid * 1000 / nSize;
+ // Dogecoin: Cap the fee paid so we can't overflow.
+ nSatoshisPerK = std::min(MAX_FEE_RATE, nFeePaid) * 1000 / nSize;
else
nSatoshisPerK = 0;
}
diff --git a/src/policy/feerate.h b/src/policy/feerate.h
index 0ef97f63b..18c669b45 100644
--- a/src/policy/feerate.h
+++ b/src/policy/feerate.h
@@ -14,6 +14,12 @@
const std::string CURRENCY_UNIT = "DOGE"; // One formatted unit
const std::string CURRENCY_ATOM = "koinu"; // One indivisible minimum value unit
+// Dogecoin: Bitcoin uses MAX_MONEY as the maximum fee rate, but that leads to
+// overflows with Doge MAX_MONEY, so instead we have it as a distinct value.
+static const CAmount MAX_FEE_RATE = 21000000 * COIN;
+
+inline bool FeeRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_FEE_RATE); }
+
/* Used to determine type of fee estimation requested */
enum class FeeEstimateMode {
UNSET, //!< Use default settings based on other criteria
@@ -29,33 +35,34 @@ enum class FeeEstimateMode {
class CFeeRate
{
private:
- CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
+ CAmount nSatoshisPerK; // unit is Koinu-per-1,000-bytes
public:
- /** Fee rate of 0 satoshis per kB */
+ /** Fee rate of 0 Koinu per kB */
CFeeRate() : nSatoshisPerK(0) { }
template<typename I>
explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
// We've previously had bugs creep in from silent double->int conversion...
static_assert(std::is_integral<I>::value, "CFeeRate should be used without floats");
}
- /** Constructor for a fee rate in satoshis per kvB (sat/kvB). The size in bytes must not exceed (2^63 - 1).
+ /** Constructor for a fee rate in Koinu per kvB (Koinu/kvB). The fee paid should not exceed MAX_FEE_RATE, and
+ * size in bytes must not exceed (2^63 - 1).
*
- * Passing an nBytes value of COIN (1e8) returns a fee rate in satoshis per vB (sat/vB),
+ * Passing an nBytes value of COIN (1e8) returns a fee rate in Koinu per vB (Koinu/vB),
* e.g. (nFeePaid * 1e8 / 1e3) == (nFeePaid / 1e5),
- * where 1e5 is the ratio to convert from BTC/kvB to sat/vB.
+ * where 1e5 is the ratio to convert from DOGE/kvB to Koinu/vB.
*
- * @param[in] nFeePaid CAmount fee rate to construct with
+ * @param[in] nFeePaid CAmount fee rate to construct with. If this exceeds MAX_FEE_RATE it will be capped at MAX_FEE_RATE.
* @param[in] nBytes size_t bytes (units) to construct with
* @returns fee rate
*/
CFeeRate(const CAmount& nFeePaid, size_t nBytes);
/**
- * Return the fee in satoshis for the given size in bytes.
+ * Return the fee in Koinu for the given size in bytes.
*/
CAmount GetFee(size_t nBytes) const;
/**
- * Return the fee in satoshis for a size of 1000 bytes
+ * Return the fee in Koinu for a size of 1000 bytes
*/
CAmount GetFeePerK() const { return GetFee(1000); }
friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }