@@ -211,7 +211,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
211
211
// and higher priority to zpivs that are large in value
212
212
int64_t nTimeSeen = GetAdjustedTime ();
213
213
double nConfs = 100000 ;
214
- double dPriorityPrev = dPriority;
215
214
216
215
auto it = mapZerocoinspends.find (txid);
217
216
if (it != mapZerocoinspends.end ()) {
@@ -221,19 +220,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
221
220
mapZerocoinspends[txid] = nTimeSeen;
222
221
}
223
222
224
- // zPIV spends can have very large priority, prevent datatype problems
225
223
double nTimePriority = std::pow (GetAdjustedTime () - nTimeSeen, 6 );
226
- double fLimit = std::numeric_limits<double >::max () - dPriority;
227
- if (fLimit > (nTimePriority * nConfs))
228
- dPriority += nTimePriority * nConfs;
229
- else
230
- dPriority = std::numeric_limits<double >::max ();
231
-
232
- fLimit = std::numeric_limits<double >::max () / dPriority;
233
- if (fLimit > nTotalIn)
234
- dPriority *= nTotalIn;
235
- else
236
- dPriority = std::numeric_limits<double >::max ();
224
+
225
+ // zPIV spends can have very large priority, use non-overflowing safe functions
226
+ dPriority = double_safe_addition (dPriority, (nTimePriority * nConfs));
227
+ dPriority = double_safe_multiplication (dPriority, nTotalIn);
237
228
238
229
continue ;
239
230
}
@@ -279,13 +270,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
279
270
280
271
int nConf = nHeight - coins->nHeight ;
281
272
282
- // zPIV spends can have very large priority, prevent datatype problems
283
- double fLimit = std::numeric_limits< double >:: max () - dPriority ;
273
+ // zPIV spends can have very large priority, use non-overflowing safe functions
274
+ dPriority = double_safe_addition (dPriority, (( double )nValueIn * nConf)) ;
284
275
285
- if (fLimit > ((double )nValueIn * nConf))
286
- dPriority += (double )nValueIn * nConf;
287
- else
288
- dPriority = std::numeric_limits<double >::max ();
289
276
}
290
277
if (fMissingInputs ) continue ;
291
278
0 commit comments