@@ -211,7 +211,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
211211 // and higher priority to zpivs that are large in value
212212 int64_t nTimeSeen = GetAdjustedTime ();
213213 double nConfs = 100000 ;
214- double dPriorityPrev = dPriority;
215214
216215 auto it = mapZerocoinspends.find (txid);
217216 if (it != mapZerocoinspends.end ()) {
@@ -221,19 +220,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
221220 mapZerocoinspends[txid] = nTimeSeen;
222221 }
223222
224- // zPIV spends can have very large priority, prevent datatype problems
225223 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);
237228
238229 continue ;
239230 }
@@ -279,13 +270,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
279270
280271 int nConf = nHeight - coins->nHeight ;
281272
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)) ;
284275
285- if (fLimit > ((double )nValueIn * nConf))
286- dPriority += (double )nValueIn * nConf;
287- else
288- dPriority = std::numeric_limits<double >::max ();
289276 }
290277 if (fMissingInputs ) continue ;
291278
0 commit comments