if (pinfo)
{
// periodically update nTime
- bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
- int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
+ bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < nOneDay);
+ int64_t nUpdateInterval = (fCurrentlyOnline ? nOneHour : nOneDay);
if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty))
pinfo->nTime = max((int64_t)0, addr.nTime - nTimePenalty);
for (std::map<int, CAddrInfo>::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++)
{
CAddrInfo addr = it->second;
- bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
+ bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < nOneDay);
if (fCurrentlyOnline)
vAddr.push_back(addr);
}
// Ping and address broadcast intervals
nPingInterval = max<int64_t>(10 * 60, GetArg("-keepalive", 30 * 60));
-
- nBroadcastInterval = max<int64_t>(6 * 60 * 60, GetArg("-addrsetlifetime", 24 * 60 * 60));
+ nBroadcastInterval = max<int64_t>(6 * 60 * 60, GetArg("-addrsetlifetime", nOneDay));
CheckpointsMode = Checkpoints::STRICT;
std::string strCpMode = GetArg("-cppolicy", "strict");
uint256 hashBlockFrom = blockFrom.GetHash();
- CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)txPrev.nTime, (int64_t)nTimeTx) / COIN / (24 * 60 * 60);
+ CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)txPrev.nTime, (int64_t)nTimeTx) / COIN / nOneDay;
targetProofOfStake = (bnCoinDayWeight * bnTargetPerCoinDay).getuint256();
// Calculate hash
ScanMidstateWorker()
{ }
ScanMidstateWorker(unsigned char *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, uint32_t nIntervalBegin, uint32_t nIntervalEnd)
- : nBits(nBits), nInputTxTime(nInputTxTime), nValueIn(nValueIn), nIntervalBegin(nIntervalBegin), nIntervalEnd(nIntervalEnd)
+ : nBits(nBits), nInputTxTime(nInputTxTime), bnValueIn(nValueIn), nIntervalBegin(nIntervalBegin), nIntervalEnd(nIntervalEnd)
{
// Init new sha256 context and update it
// with first 24 bytes of kernel
SHA256_Init(&workerCtx);
SHA256_Update(&workerCtx, kernel, 8 + 16);
- workerSolutions = vector<std::pair<uint256,uint32_t> >();
+ solutions = vector<std::pair<uint256,uint32_t> >();
}
void Do()
{
SetThreadPriority(THREAD_PRIORITY_LOWEST);
+ SHA256_CTX ctx = workerCtx;
+
+ // Sha256 result buffer
+ uint32_t hashProofOfStake[8];
+ // Compute maximum possible target to filter out majority of obviously insufficient hashes
CBigNum bnTargetPerCoinDay;
bnTargetPerCoinDay.SetCompact(nBits);
- // Get maximum possible target to filter out the majority of obviously insufficient hashes
- CBigNum bnMaxTargetPerCoinDay = bnTargetPerCoinDay * CBigNum(nValueIn) * nStakeMaxAge / COIN / (24 * 60 * 60);
- uint256 maxTarget = bnMaxTargetPerCoinDay.getuint256();
-
- SHA256_CTX ctx = workerCtx;
+ uint256 nMaxTarget = (bnTargetPerCoinDay * bnValueIn * nStakeMaxAge / COIN / nOneDay).getuint256(),
+ *pnHashProofOfStake = (uint256 *)&hashProofOfStake;
// Search forward in time from the given timestamp
// Stopping search in case of shutting down
- for (uint32_t nTimeTx=nIntervalBegin; nTimeTx<nIntervalEnd && !fShutdown; nTimeTx++)
+ for (uint32_t nTimeTx=nIntervalBegin, nMaxTarget32 = nMaxTarget.Get32(7); nTimeTx<nIntervalEnd && !fShutdown; nTimeTx++)
{
// Complete first hashing iteration
uint256 hash1;
ctx = workerCtx;
// Finally, calculate kernel hash
- uint256 hashProofOfStake;
SHA256((unsigned char*)&hash1, sizeof(hashProofOfStake), (unsigned char*)&hashProofOfStake);
-
// Skip if hash doesn't satisfy the maximum target
- if (hashProofOfStake > maxTarget)
+ if (hashProofOfStake[7] > nMaxTarget32)
continue;
- CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)nInputTxTime, (int64_t)nTimeTx) / COIN / (24 * 60 * 60);
+ CBigNum bnCoinDayWeight = bnValueIn * GetWeight((int64_t)nInputTxTime, (int64_t)nTimeTx) / COIN / nOneDay;
CBigNum bnTargetProofOfStake = bnCoinDayWeight * bnTargetPerCoinDay;
- if (bnTargetProofOfStake >= CBigNum(hashProofOfStake))
- {
- workerSolutions.push_back(std::pair<uint256,uint32_t>(hashProofOfStake, nTimeTx));
- }
+ if (bnTargetProofOfStake >= CBigNum(*pnHashProofOfStake))
+ solutions.push_back(std::pair<uint256,uint32_t>(*pnHashProofOfStake, nTimeTx));
}
}
vector<std::pair<uint256,uint32_t> >& GetSolutions()
{
- return workerSolutions;
+ return solutions;
}
private:
SHA256_CTX workerCtx;
- std::vector<std::pair<uint256,uint32_t> > workerSolutions;
+ std::vector<std::pair<uint256,uint32_t> > solutions;
uint32_t nBits;
uint32_t nInputTxTime;
- int64_t nValueIn;
+ CBigNum bnValueIn;
uint32_t nIntervalBegin;
uint32_t nIntervalEnd;
};
bnTargetPerCoinDay.SetCompact(nBits);
// Get maximum possible target to filter out the majority of obviously insufficient hashes
- CBigNum bnMaxTargetPerCoinDay = bnTargetPerCoinDay * CBigNum(nValueIn) * nStakeMaxAge / COIN / (24 * 60 * 60);
+ CBigNum bnMaxTargetPerCoinDay = bnTargetPerCoinDay * CBigNum(nValueIn) * nStakeMaxAge / COIN / nOneDay;
uint256 maxTarget = bnMaxTargetPerCoinDay.getuint256();
SHA256_CTX ctxCopy = ctx;
if (hashProofOfStake > maxTarget)
continue;
- CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)nInputTxTime, (int64_t)nTimeTx) / COIN / (24 * 60 * 60);
+ CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)nInputTxTime, (int64_t)nTimeTx) / COIN / nOneDay;
CBigNum bnTargetProofOfStake = bnCoinDayWeight * bnTargetPerCoinDay;
if (bnTargetProofOfStake >= CBigNum(hashProofOfStake))
// Ping and address broadcast intervals
int64_t nPingInterval = 30 * 60;
-int64_t nBroadcastInterval = 24 * 60 * 60;
+int64_t nBroadcastInterval = nOneDay;
extern enum Checkpoints::CPMode CheckpointsMode;
return nSubsidy;
}
-static const int64_t nTargetTimespan = 7 * 24 * 60 * 60; // one week
+static const int64_t nTargetTimespan = 7 * nOneDay; // one week
// get proof of work blocks max spacing according to hard-coded conditions
int64_t inline GetTargetSpacingWorkMax(int nHeight, unsigned int nTime)
{
// Maximum 200% adjustment per day...
bnResult *= 2;
- nTime -= 24 * 60 * 60;
+ nTime -= nOneDay;
}
if (bnResult > bnTargetLimit)
bnResult = bnTargetLimit;
nLastUpdate = nCurrentTime;
}
return (nCurrentTime - nLastUpdate < 10 &&
- pindexBest->GetBlockTime() < nCurrentTime - 24 * 60 * 60);
+ pindexBest->GetBlockTime() < nCurrentTime - nOneDay);
}
void static InvalidChainFound(CBlockIndex* pindexNew)
printf("coin age nValueIn=%" PRId64 " nTimeDiff=%d bnCentSecond=%s\n", nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString().c_str());
}
- CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60);
+ CBigNum bnCoinDay = bnCentSecond * CENT / COIN / nOneDay;
if (fDebug && GetBoolArg("-printcoinage"))
printf("coin age bnCoinDay=%s\n", bnCoinDay.ToString().c_str());
nCoinAge = bnCoinDay.getuint64();
if (fShutdown)
return true;
if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60)
- addr.nTime = nNow - 5 * 24 * 60 * 60;
+ addr.nTime = nNow - 5 * nOneDay;
pfrom->AddAddressKnown(addr);
bool fReachable = IsReachable(addr);
if (addr.nTime > nSince && !pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable())
else if (strCommand == "getaddr")
{
// Don't return addresses older than nCutOff timestamp
- int64_t nCutOff = GetTime() - (nNodeLifespan * 24 * 60 * 60);
+ int64_t nCutOff = GetTime() - (nNodeLifespan * nOneDay);
pfrom->vAddrToSend.clear();
vector<CAddress> vAddr = addrman.GetAddr();
BOOST_FOREACH(const CAddress &addr, vAddr)
static const int64_t MAX_MINT_PROOF_OF_STAKE = 1 * COIN;
static const int64_t MIN_TXOUT_AMOUNT = CENT/100;
+
inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
// Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp.
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
static const uint256 hashGenesisBlock("0x00000a060336cbb72fe969666d337b87198b1add2abaa59cca226820b32933a4");
static const uint256 hashGenesisBlockTestNet("0x000c763e402f2436da9ed36c7286f62c3f6e5dbafce9ff289bd43d7459327eb");
-inline int64_t PastDrift(int64_t nTime) { return nTime - 2 * 60 * 60; } // up to 2 hours from the past
-inline int64_t FutureDrift(int64_t nTime) { return nTime + 2 * 60 * 60; } // up to 2 hours from the future
+inline int64_t PastDrift(int64_t nTime) { return nTime - 2 * nOneHour; } // up to 2 hours from the past
+inline int64_t FutureDrift(int64_t nTime) { return nTime + 2 * nOneHour; } // up to 2 hours from the future
extern CScript COINBASE_FLAGS;
extern CCriticalSection cs_main;
#include "netbase.h" // for AddTimeData
+static const int32_t nOneHour = 60 * 60;
+static const int32_t nOneDay = 24 * 60 * 60;
static const int64_t COIN = 1000000;
static const int64_t CENT = 10000;
return;
}
- CBigNum bnCoinDayWeight = CBigNum(nValue) * nTimeWeight / COIN / (24 * 60 * 60);
+ CBigNum bnCoinDayWeight = CBigNum(nValue) * nTimeWeight / COIN / nOneDay;
nWeight = bnCoinDayWeight.getuint64();
}