aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp6
-rw-r--r--src/miner.cpp2
-rw-r--r--src/net_processing.cpp2
-rw-r--r--src/policy/feerate.cpp3
-rw-r--r--src/policy/feerate.h23
5 files changed, 25 insertions, 11 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 36b82c243..b38f192c1 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1118,6 +1118,8 @@ bool AppInitParameterInteraction(const ArgsManager& args)
CAmount n = 0;
if (!ParseMoney(args.GetArg("-incrementalrelayfee", ""), n))
return InitError(AmountErrMsg("incrementalrelayfee", args.GetArg("-incrementalrelayfee", "")));
+ if (n > MAX_FEE_RATE)
+ return InitError(strprintf(Untranslated("-incrementalrelayfee is greater than maximum fee rate of %ld."), MAX_FEE_RATE));
incrementalRelayFee = CFeeRate(n);
}
@@ -1154,6 +1156,8 @@ bool AppInitParameterInteraction(const ArgsManager& args)
if (!ParseMoney(args.GetArg("-minrelaytxfee", ""), n)) {
return InitError(AmountErrMsg("minrelaytxfee", args.GetArg("-minrelaytxfee", "")));
}
+ if (n > MAX_FEE_RATE)
+ return InitError(strprintf(Untranslated("-minrelaytxfee is greater than maximum fee rate of %ld."), MAX_FEE_RATE));
// High fee check is done afterward in CWallet::Create()
::minRelayTxFee = CFeeRate(n);
} else if (incrementalRelayFee > ::minRelayTxFee) {
@@ -1176,6 +1180,8 @@ bool AppInitParameterInteraction(const ArgsManager& args)
CAmount n = 0;
if (!ParseMoney(args.GetArg("-dustrelayfee", ""), n))
return InitError(AmountErrMsg("dustrelayfee", args.GetArg("-dustrelayfee", "")));
+ if (n > MAX_FEE_RATE)
+ return InitError(strprintf(Untranslated("-dustrelayfee is greater than maximum fee rate of %ld."), MAX_FEE_RATE));
dustRelayFee = CFeeRate(n);
}
diff --git a/src/miner.cpp b/src/miner.cpp
index b44cb947d..013ea4005 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -72,7 +72,7 @@ static BlockAssembler::Options DefaultOptions()
BlockAssembler::Options options;
options.nBlockMaxWeight = gArgs.GetArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
CAmount n = 0;
- if (gArgs.IsArgSet("-blockmintxfee") && ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) {
+ if (gArgs.IsArgSet("-blockmintxfee") && ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n) && n <= MAX_FEE_RATE) {
options.blockMinFeeRate = CFeeRate(n);
} else {
options.blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 4b38767e8..b39e11647 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -3722,7 +3722,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
if (msg_type == NetMsgType::FEEFILTER) {
CAmount newFeeFilter = 0;
vRecv >> newFeeFilter;
- if (MoneyRange(newFeeFilter)) {
+ if (FeeRange(newFeeFilter)) {
if (pfrom.m_tx_relay != nullptr) {
LOCK(pfrom.m_tx_relay->cs_feeFilter);
pfrom.m_tx_relay->minFeeFilter = newFeeFilter;
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; }