From 576f3bde12e58e1b1a3c429955bcd7b92860169a Mon Sep 17 00:00:00 2001 From: svost Date: Sat, 16 Jan 2016 16:52:49 +0300 Subject: [PATCH] We have constants (commit e1fc548) --- src/addrman.cpp | 4 ++-- src/checkpoints.h | 3 ++- src/kernelrecord.cpp | 16 ++++++++-------- src/ntp.cpp | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 6676f62..ed17c39 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -43,13 +43,13 @@ bool CAddrInfo::IsTerrible(int64_t nNow) const if (nTime > nNow + 10*60) // came in a flying DeLorean return true; - if (nTime==0 || nNow-nTime > ADDRMAN_HORIZON_DAYS*86400) // not seen in over a month + if (nTime==0 || nNow-nTime > ADDRMAN_HORIZON_DAYS*nOneDay) // not seen in over a month return true; if (nLastSuccess==0 && nAttempts>=ADDRMAN_RETRIES) // tried three times and never a success return true; - if (nNow-nLastSuccess > ADDRMAN_MIN_FAIL_DAYS*86400 && nAttempts>=ADDRMAN_MAX_FAILURES) // 10 successive failures in the last week + if (nNow-nLastSuccess > ADDRMAN_MIN_FAIL_DAYS*nOneDay && nAttempts>=ADDRMAN_MAX_FAILURES) // 10 successive failures in the last week return true; return false; diff --git a/src/checkpoints.h b/src/checkpoints.h index 135838d..347b2d0 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -8,7 +8,8 @@ #include "util.h" #include "net.h" -#define CHECKPOINT_MAX_SPAN (60 * 60) // max 1 hour before latest block +// max 1 hour before latest block +static const int64_t CHECKPOINT_MAX_SPAN = nOneHour; #ifdef WIN32 #undef STRICT diff --git a/src/kernelrecord.cpp b/src/kernelrecord.cpp index bf05268..a9a2e8e 100644 --- a/src/kernelrecord.cpp +++ b/src/kernelrecord.cpp @@ -47,7 +47,7 @@ vector KernelRecord::decomposeOutput(const CWallet *wallet, const CTxDestination address; std::string addrStr; - uint64_t coinAge = max( (txOut.nValue * nDayWeight) / (COIN * 86400), (int64_t)0); + uint64_t coinAge = max( (txOut.nValue * nDayWeight) / (COIN * nOneDay), 0LL); if (ExtractDestination(txOut.scriptPubKey, address)) { @@ -75,7 +75,7 @@ std::string KernelRecord::getTxID() int64_t KernelRecord::getAge() const { - return (GetAdjustedTime() - nTime) / 86400; + return (GetAdjustedTime() - nTime) / nOneDay; } uint64_t KernelRecord::getCoinDay() const @@ -84,7 +84,7 @@ uint64_t KernelRecord::getCoinDay() const if( nWeight < 0) return 0; nWeight = min(nWeight, (int64_t)nStakeMaxAge); - uint64_t coinAge = (nValue * nWeight ) / (COIN * 86400); + uint64_t coinAge = (nValue * nWeight ) / (COIN * nOneDay); return coinAge; } @@ -94,7 +94,7 @@ int64_t KernelRecord::getPoSReward(int nBits, int minutes) int64_t nWeight = GetAdjustedTime() - nTime + minutes * 60; if( nWeight < nStakeMinAge) return 0; - uint64_t coinAge = (nValue * nWeight ) / (COIN * 86400); + uint64_t coinAge = (nValue * nWeight ) / (COIN * nOneDay); PoSReward = GetProofOfStakeReward(coinAge, nBits, GetAdjustedTime() + minutes * 60); return PoSReward; } @@ -107,7 +107,7 @@ double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const //uint64_t coinAge = max(nValue * dayWeight / COIN, (int64_t)0); //return target * coinAge / pow(static_cast(2), 256); int64_t Weight = (min((GetAdjustedTime() - nTime) + timeOffset, (int64_t)(nStakeMinAge+nStakeMaxAge)) - nStakeMinAge); - uint64_t coinAge = max(nValue * Weight / (COIN * 86400), (int64_t)0); + uint64_t coinAge = max(nValue * Weight / (COIN * nOneDay), 0LL); return coinAge / (pow(static_cast(2),32) * difficulty); } @@ -124,13 +124,13 @@ double KernelRecord::getProbToMintWithinNMinutes(double difficulty, int minutes) // Probabilities for the first d days for(i = 0; i < d; i++) { - timeOffset = i * 86400; - p = pow(1 - getProbToMintStake(difficulty, timeOffset), 86400); + timeOffset = i * nOneDay; + p = pow(1 - getProbToMintStake(difficulty, timeOffset), nOneDay); prob *= p; } // Probability for the m minutes of the last day - timeOffset = d * 86400; + timeOffset = d * nOneDay; p = pow(1 - getProbToMintStake(difficulty, timeOffset), 60 * m); prob *= p; diff --git a/src/ntp.cpp b/src/ntp.cpp index 527a02c..d66f3bb 100644 --- a/src/ntp.cpp +++ b/src/ntp.cpp @@ -445,7 +445,7 @@ int64_t GetNtpOffset() { } void ThreadNtpSamples(void* parg) { - const int64_t nMaxOffset = 86400; // Not a real limit, just sanity threshold. + const int64_t nMaxOffset = nOneDay; // Not a real limit, just sanity threshold. printf("Trying to find NTP server at localhost...\n"); -- 1.7.1