Skip to content

Commit 6484930

Browse files
committed
Apply AreSane() checks to the fees from the network.
'Sane' was already defined by this code as: fee.GetFeePerK() > minRelayFee.GetFeePerK() * 10000 But sanity was only enforced for data loaded from disk. Note that this is a pretty expansive definition of 'sane': A 10 BTC fee is still passes the test if its on a 100kb transaction. This prevents a single insane fee on the network from making us reject our stored fee data at start. We still may reject valid saved fee state if minRelayFee is changed between executions. This also reduces the risk and limits the damage from a cascading failure where one party pays a bunch of insane fees which cases others to pay insane fees.
1 parent 13c077c commit 6484930

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/txmempool.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,32 @@ class CBlockAverage
9191
* Used as belt-and-suspenders check when reading to detect
9292
* file corruption
9393
*/
94-
bool AreSane(const std::vector<CFeeRate>& vecFee, const CFeeRate& minRelayFee)
94+
static bool AreSane(const CFeeRate fee, const CFeeRate& minRelayFee)
95+
{
96+
if (fee < CFeeRate(0))
97+
return false;
98+
if (fee.GetFeePerK() > minRelayFee.GetFeePerK() * 10000)
99+
return false;
100+
return true;
101+
}
102+
static bool AreSane(const std::vector<CFeeRate>& vecFee, const CFeeRate& minRelayFee)
95103
{
96104
BOOST_FOREACH(CFeeRate fee, vecFee)
97105
{
98-
if (fee < CFeeRate(0))
99-
return false;
100-
if (fee.GetFeePerK() > minRelayFee.GetFeePerK() * 10000)
106+
if (!AreSane(fee, minRelayFee))
101107
return false;
102108
}
103109
return true;
104110
}
105-
bool AreSane(const std::vector<double> vecPriority)
111+
static bool AreSane(const double priority)
112+
{
113+
return priority >= 0;
114+
}
115+
static bool AreSane(const std::vector<double> vecPriority)
106116
{
107117
BOOST_FOREACH(double priority, vecPriority)
108118
{
109-
if (priority < 0)
119+
if (!AreSane(priority))
110120
return false;
111121
}
112122
return true;
@@ -167,12 +177,12 @@ class CMinerPolicyEstimator
167177
bool sufficientFee = (feeRate > minRelayFee);
168178
bool sufficientPriority = AllowFree(dPriority);
169179
const char* assignedTo = "unassigned";
170-
if (sufficientFee && !sufficientPriority)
180+
if (sufficientFee && !sufficientPriority && CBlockAverage::AreSane(feeRate, minRelayFee))
171181
{
172182
history[nBlocksTruncated].RecordFee(feeRate);
173183
assignedTo = "fee";
174184
}
175-
else if (sufficientPriority && !sufficientFee)
185+
else if (sufficientPriority && !sufficientFee && CBlockAverage::AreSane(dPriority))
176186
{
177187
history[nBlocksTruncated].RecordPriority(dPriority);
178188
assignedTo = "priority";

0 commit comments

Comments
 (0)