X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fmain.cpp;h=7853aa38685b25448577740f1d4c4613171ff67e;hb=035eee8428bf34e5a57edf6a3898a782d682a779;hp=43747747e68f5a0b721593ff7c60685013f4e39c;hpb=e7e025dc61365eaf476dd22f59fd7228640a98ed;p=novacoin.git diff --git a/src/main.cpp b/src/main.cpp index 4374774..7853aa3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,12 @@ uint256 nPoWBase = uint256("0x00000000ffff00000000000000000000000000000000000000 CBigNum bnProofOfWorkLimitTestNet(~uint256(0) >> 16); +unsigned int nStakeMinAge = 60 * 60 * 24 * 30; // 30 days as zero time weight +unsigned int nStakeMaxAge = 60 * 60 * 24 * 90; // 90 days as full weight +unsigned int nStakeTargetSpacing = 10 * 60; // 10-minute stakes spacing +unsigned int nModifierInterval = 6 * 60 * 60; // time to elapse before new modifier is computed + +int nCoinbaseMaturity = 500; CBlockIndex* pindexGenesisBlock = NULL; int nBestHeight = -1; @@ -51,7 +57,7 @@ uint256 nBestInvalidTrust = 0; uint256 hashBestChain = 0; CBlockIndex* pindexBest = NULL; -int64 nTimeBestReceived = 0; +int64_t nTimeBestReceived = 0; int nScriptCheckThreads = 0; CMedianFilter cPeerBlockCounts(5, 0); // Amount of blocks that other nodes claim to have @@ -70,8 +76,8 @@ CScript COINBASE_FLAGS; const string strMessageMagic = "NovaCoin Signed Message:\n"; // Settings -int64 nTransactionFee = MIN_TX_FEE; -int64 nMinimumInputValue = MIN_TX_FEE; +int64_t nTransactionFee = MIN_TX_FEE; +int64_t nMinimumInputValue = MIN_TX_FEE; extern enum Checkpoints::CPMode CheckpointsMode; @@ -209,7 +215,7 @@ bool AddOrphanTx(const CTransaction& tx) if (nSize > 5000) { - printf("ignoring large orphan tx (size: %"PRIszu", hash: %s)\n", nSize, hash.ToString().substr(0,10).c_str()); + printf("ignoring large orphan tx (size: %" PRIszu ", hash: %s)\n", nSize, hash.ToString().substr(0,10).c_str()); return false; } @@ -217,7 +223,7 @@ bool AddOrphanTx(const CTransaction& tx) BOOST_FOREACH(const CTxIn& txin, tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(hash); - printf("stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString().substr(0,10).c_str(), + printf("stored orphan tx %s (mapsz %" PRIszu ")\n", hash.ToString().substr(0,10).c_str(), mapOrphanTransactions.size()); return true; } @@ -291,10 +297,13 @@ bool CTransaction::ReadFromDisk(COutPoint prevout) return ReadFromDisk(txdb, prevout, txindex); } -bool CTransaction::IsStandard() const +bool CTransaction::IsStandard(string& strReason) const { if (nVersion > CTransaction::CURRENT_VERSION) + { + strReason = "version"; return false; + } unsigned int nDataOut = 0; txnouttype whichType; @@ -304,24 +313,34 @@ bool CTransaction::IsStandard() const // pay-to-script-hash, which is 3 ~80-byte signatures, 3 // ~65-byte public keys, plus a few script ops. if (txin.scriptSig.size() > 500) + { + strReason = "scriptsig-size"; return false; + } if (!txin.scriptSig.IsPushOnly()) + { + strReason = "scriptsig-not-pushonly"; return false; + } if (!txin.scriptSig.HasCanonicalPushes()) { + strReason = "txin-scriptsig-not-canonicalpushes"; return false; } } BOOST_FOREACH(const CTxOut& txout, vout) { if (!::IsStandard(txout.scriptPubKey, whichType)) { + strReason = "scriptpubkey"; return false; } if (whichType == TX_NULL_DATA) nDataOut++; else { if (txout.nValue == 0) { + strReason = "txout-value=0"; return false; } if (!txout.scriptPubKey.HasCanonicalPushes()) { + strReason = "txout-scriptsig-not-canonicalpushes"; return false; } } @@ -329,6 +348,7 @@ bool CTransaction::IsStandard() const // only one OP_RETURN txout is permitted if (nDataOut > 1) { + strReason = "multi-op-return"; return false; } @@ -485,7 +505,7 @@ bool CTransaction::CheckTransaction() const return DoS(100, error("CTransaction::CheckTransaction() : size limits failed")); // Check for negative or overflow output values - int64 nValueOut = 0; + int64_t nValueOut = 0; for (unsigned int i = 0; i < vout.size(); i++) { const CTxOut& txout = vout[i]; @@ -525,13 +545,13 @@ bool CTransaction::CheckTransaction() const return true; } -int64 CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree, enum GetMinFee_mode mode, unsigned int nBytes) const +int64_t CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree, enum GetMinFee_mode mode, unsigned int nBytes) const { // Use new fees approach if we are on test network or // switch date has been reached bool fNewApproach = fTestNet || nTime > FEE_SWITCH_TIME; - int64 nMinTxFee = MIN_TX_FEE, nMinRelayTxFee = MIN_RELAY_TX_FEE; + int64_t nMinTxFee = MIN_TX_FEE, nMinRelayTxFee = MIN_RELAY_TX_FEE; if(!fNewApproach || IsCoinStake()) { @@ -541,10 +561,10 @@ int64 CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree, enum Get } // Base fee is either nMinTxFee or nMinRelayTxFee - int64 nBaseFee = (mode == GMF_RELAY) ? nMinRelayTxFee : nMinTxFee; + int64_t nBaseFee = (mode == GMF_RELAY) ? nMinRelayTxFee : nMinTxFee; unsigned int nNewBlockSize = nBlockSize + nBytes; - int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee; + int64_t nMinFee = (1 + (int64_t)nBytes / 1000) * nBaseFee; if (fNewApproach) { @@ -615,12 +635,13 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, return tx.DoS(100, error("CTxMemPool::accept() : coinstake as individual tx")); // To help v0.1.5 clients who would see it as a negative number - if ((int64)tx.nLockTime > std::numeric_limits::max()) + if ((int64_t)tx.nLockTime > std::numeric_limits::max()) return error("CTxMemPool::accept() : not accepting nLockTime beyond 2038 yet"); // Rather not work on nonstandard transactions (unless -testnet) - if (!fTestNet && !tx.IsStandard()) - return error("CTxMemPool::accept() : nonstandard transaction type"); + string strNonStd; + if (!fTestNet && !tx.IsStandard(strNonStd)) + return error("CTxMemPool::accept() : nonstandard transaction (%s)", strNonStd.c_str()); // Do we already have it? uint256 hash = tx.GetHash(); @@ -683,13 +704,13 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, // you should add code here to check that the transaction does a // reasonable number of ECDSA signature verifications. - int64 nFees = tx.GetValueIn(mapInputs)-tx.GetValueOut(); + int64_t nFees = tx.GetValueIn(mapInputs)-tx.GetValueOut(); unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); // Don't accept it if it can't get into a block - int64 txMinFee = tx.GetMinFee(1000, true, GMF_RELAY, nSize); + int64_t txMinFee = tx.GetMinFee(1000, true, GMF_RELAY, nSize); if (nFees < txMinFee) - return error("CTxMemPool::accept() : not enough fees %s, %"PRI64d" < %"PRI64d, + return error("CTxMemPool::accept() : not enough fees %s, %" PRId64 " < %" PRId64, hash.ToString().c_str(), nFees, txMinFee); @@ -700,8 +721,8 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, { static CCriticalSection cs; static double dFreeCount; - static int64 nLastTime; - int64 nNow = GetTime(); + static int64_t nLastTime; + int64_t nNow = GetTime(); { LOCK(cs); @@ -742,7 +763,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, if (ptxOld) EraseFromWallets(ptxOld->GetHash()); - printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n", + printf("CTxMemPool::accept() : accepted %s (poolsz %" PRIszu ")\n", hash.ToString().substr(0,10).c_str(), mapTx.size()); return true; @@ -1006,7 +1027,7 @@ CBigNum inline GetProofOfStakeLimit(int nHeight, unsigned int nTime) } // miner's coin base reward based on nBits -int64 GetProofOfWorkReward(unsigned int nBits, int64 nFees) +int64_t GetProofOfWorkReward(unsigned int nBits, int64_t nFees) { CBigNum bnSubsidyLimit = MAX_MINT_PROOF_OF_WORK; @@ -1028,26 +1049,26 @@ int64 GetProofOfWorkReward(unsigned int nBits, int64 nFees) { CBigNum bnMidValue = (bnLowerBound + bnUpperBound) / 2; if (fDebug && GetBoolArg("-printcreation")) - printf("GetProofOfWorkReward() : lower=%"PRI64d" upper=%"PRI64d" mid=%"PRI64d"\n", bnLowerBound.getuint64(), bnUpperBound.getuint64(), bnMidValue.getuint64()); + printf("GetProofOfWorkReward() : lower=%" PRId64 " upper=%" PRId64 " mid=%" PRId64 "\n", bnLowerBound.getuint64(), bnUpperBound.getuint64(), bnMidValue.getuint64()); if (bnMidValue * bnMidValue * bnMidValue * bnMidValue * bnMidValue * bnMidValue * bnTargetLimit > bnSubsidyLimit * bnSubsidyLimit * bnSubsidyLimit * bnSubsidyLimit * bnSubsidyLimit * bnSubsidyLimit * bnTarget) bnUpperBound = bnMidValue; else bnLowerBound = bnMidValue; } - int64 nSubsidy = bnUpperBound.getuint64(); + int64_t nSubsidy = bnUpperBound.getuint64(); nSubsidy = (nSubsidy / CENT) * CENT; if (fDebug && GetBoolArg("-printcreation")) - printf("GetProofOfWorkReward() : create=%s nBits=0x%08x nSubsidy=%"PRI64d"\n", FormatMoney(nSubsidy).c_str(), nBits, nSubsidy); + printf("GetProofOfWorkReward() : create=%s nBits=0x%08x nSubsidy=%" PRId64 "\n", FormatMoney(nSubsidy).c_str(), nBits, nSubsidy); return min(nSubsidy, MAX_MINT_PROOF_OF_WORK) + nFees; } // miner's coin stake reward based on nBits and coin age spent (coin-days) -int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTime, bool bCoinYearOnly) +int64_t GetProofOfStakeReward(int64_t nCoinAge, unsigned int nBits, unsigned int nTime, bool bCoinYearOnly) { - int64 nRewardCoinYear, nSubsidy, nSubsidyLimit = 10 * COIN; + int64_t nRewardCoinYear, nSubsidy, nSubsidyLimit = 10 * COIN; if(fTestNet || nTime > STAKE_SWITCH_TIME) { @@ -1069,7 +1090,7 @@ int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTi { CBigNum bnMidValue = (bnLowerBound + bnUpperBound) / 2; if (fDebug && GetBoolArg("-printcreation")) - printf("GetProofOfStakeReward() : lower=%"PRI64d" upper=%"PRI64d" mid=%"PRI64d"\n", bnLowerBound.getuint64(), bnUpperBound.getuint64(), bnMidValue.getuint64()); + printf("GetProofOfStakeReward() : lower=%" PRId64 " upper=%" PRId64 " mid=%" PRId64 "\n", bnLowerBound.getuint64(), bnUpperBound.getuint64(), bnMidValue.getuint64()); if(!fTestNet && nTime < STAKECURVE_SWITCH_TIME) { @@ -1130,14 +1151,14 @@ int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTi } if (fDebug && GetBoolArg("-printcreation")) - printf("GetProofOfStakeReward(): create=%s nCoinAge=%"PRI64d" nBits=%d\n", FormatMoney(nSubsidy).c_str(), nCoinAge, nBits); + printf("GetProofOfStakeReward(): create=%s nCoinAge=%" PRId64 " nBits=%d\n", FormatMoney(nSubsidy).c_str(), nCoinAge, nBits); return nSubsidy; } -static const int64 nTargetTimespan = 7 * 24 * 60 * 60; // one week +static const int64_t nTargetTimespan = 7 * 24 * 60 * 60; // one week // get proof of work blocks max spacing according to hard-coded conditions -int64 inline GetTargetSpacingWorkMax(int nHeight, unsigned int nTime) +int64_t inline GetTargetSpacingWorkMax(int nHeight, unsigned int nTime) { if(nTime > TARGETS_SWITCH_TIME) return 3 * nStakeTargetSpacing; // 30 minutes on mainNet since 20 Jul 2013 00:00:00 @@ -1151,7 +1172,7 @@ int64 inline GetTargetSpacingWorkMax(int nHeight, unsigned int nTime) // // maximum nBits value could possible be required nTime after // -unsigned int ComputeMaxBits(CBigNum bnTargetLimit, unsigned int nBase, int64 nTime) +unsigned int ComputeMaxBits(CBigNum bnTargetLimit, unsigned int nBase, int64_t nTime) { CBigNum bnResult; bnResult.SetCompact(nBase); @@ -1171,7 +1192,7 @@ unsigned int ComputeMaxBits(CBigNum bnTargetLimit, unsigned int nBase, int64 nTi // minimum amount of work that could possibly be required nTime after // minimum proof-of-work required was nBase // -unsigned int ComputeMinWork(unsigned int nBase, int64 nTime) +unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime) { return ComputeMaxBits(bnProofOfWorkLimit, nBase, nTime); } @@ -1180,7 +1201,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime) // minimum amount of stake that could possibly be required nTime after // minimum proof-of-stake required was nBase // -unsigned int ComputeMinStake(unsigned int nBase, int64 nTime, unsigned int nBlockTime) +unsigned int ComputeMinStake(unsigned int nBase, int64_t nTime, unsigned int nBlockTime) { return ComputeMaxBits(GetProofOfStakeLimit(0, nBlockTime), nBase, nTime); } @@ -1208,14 +1229,14 @@ unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfS if (pindexPrevPrev->pprev == NULL) return bnTargetLimit.GetCompact(); // second block - int64 nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime(); + int64_t nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime(); // ppcoin: target change every block // ppcoin: retarget with exponential moving toward target spacing CBigNum bnNew; bnNew.SetCompact(pindexPrev->nBits); - int64 nTargetSpacing = fProofOfStake? nStakeTargetSpacing : min(GetTargetSpacingWorkMax(pindexLast->nHeight, pindexLast->nTime), (int64) nStakeTargetSpacing * (1 + pindexLast->nHeight - pindexPrev->nHeight)); - int64 nInterval = nTargetTimespan / nTargetSpacing; + int64_t nTargetSpacing = fProofOfStake? nStakeTargetSpacing : min(GetTargetSpacingWorkMax(pindexLast->nHeight, pindexLast->nTime), (int64_t) nStakeTargetSpacing * (1 + pindexLast->nHeight - pindexPrev->nHeight)); + int64_t nInterval = nTargetTimespan / nTargetSpacing; bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing); bnNew /= ((nInterval + 1) * nTargetSpacing); @@ -1251,7 +1272,7 @@ bool IsInitialBlockDownload() { if (pindexBest == NULL || nBestHeight < Checkpoints::GetTotalBlocksEstimate()) return true; - static int64 nLastUpdate; + static int64_t nLastUpdate; static CBlockIndex* pindexLastBest; if (pindexBest != pindexLastBest) { @@ -1274,11 +1295,11 @@ void static InvalidChainFound(CBlockIndex* pindexNew) uint256 nBestInvalidBlockTrust = pindexNew->nChainTrust - pindexNew->pprev->nChainTrust; uint256 nBestBlockTrust = pindexBest->nHeight != 0 ? (pindexBest->nChainTrust - pindexBest->pprev->nChainTrust) : pindexBest->nChainTrust; - printf("InvalidChainFound: invalid block=%s height=%d trust=%s blocktrust=%"PRI64d" date=%s\n", + printf("InvalidChainFound: invalid block=%s height=%d trust=%s blocktrust=%" PRId64 " date=%s\n", pindexNew->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->nHeight, CBigNum(pindexNew->nChainTrust).ToString().c_str(), nBestInvalidBlockTrust.Get64(), DateTimeStrFormat("%x %H:%M:%S", pindexNew->GetBlockTime()).c_str()); - printf("InvalidChainFound: current best=%s height=%d trust=%s blocktrust=%"PRI64d" date=%s\n", + printf("InvalidChainFound: current best=%s height=%d trust=%s blocktrust=%" PRId64 " date=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, CBigNum(pindexBest->nChainTrust).ToString().c_str(), nBestBlockTrust.Get64(), @@ -1405,7 +1426,7 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map& mapTes // Revisit this if/when transaction replacement is implemented and allows // adding inputs: fInvalid = true; - return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %"PRIszu" %"PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); + return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %" PRIszu " %" PRIszu " prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); } } @@ -1425,12 +1446,12 @@ const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& in return txPrev.vout[input.prevout.n]; } -int64 CTransaction::GetValueIn(const MapPrevTx& inputs) const +int64_t CTransaction::GetValueIn(const MapPrevTx& inputs) const { if (IsCoinBase()) return 0; - int64 nResult = 0; + int64_t nResult = 0; for (unsigned int i = 0; i < vin.size(); i++) { nResult += GetOutputFor(vin[i], inputs).nValue; @@ -1476,8 +1497,8 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map= txPrev.vout.size() || prevout.n >= txindex.vSpent.size()) - return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %"PRIszu" %"PRIszu" prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); + return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %" PRIszu " %" PRIszu " prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str())); // If prev is coinbase or coinstake, check that it's matured if (txPrev.IsCoinBase() || txPrev.IsCoinStake()) @@ -1562,17 +1583,17 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map VALIDATION_SWITCH_TIME || fTestNet) ? GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION) : 0; - int64 nReward = GetValueOut() - nValueIn; - int64 nCalculatedReward = GetProofOfStakeReward(nCoinAge, pindexBlock->nBits, nTime) - GetMinFee(1, false, GMF_BLOCK, nTxSize) + CENT; + int64_t nReward = GetValueOut() - nValueIn; + int64_t nCalculatedReward = GetProofOfStakeReward(nCoinAge, pindexBlock->nBits, nTime) - GetMinFee(1, false, GMF_BLOCK, nTxSize) + CENT; if (nReward > nCalculatedReward) - return DoS(100, error("ConnectInputs() : coinstake pays too much(actual=%"PRI64d" vs calculated=%"PRI64d")", nReward, nCalculatedReward)); + return DoS(100, error("ConnectInputs() : coinstake pays too much(actual=%" PRId64 " vs calculated=%" PRId64 ")", nReward, nCalculatedReward)); } else { @@ -1580,7 +1601,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map mapQueuedChanges; CCheckQueueControl control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL); - int64 nFees = 0; - int64 nValueIn = 0; - int64 nValueOut = 0; + int64_t nFees = 0; + int64_t nValueIn = 0; + int64_t nValueOut = 0; unsigned int nSigOps = 0; BOOST_FOREACH(CTransaction& tx, vtx) { @@ -1756,8 +1775,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if (nSigOps > MAX_BLOCK_SIGOPS) return DoS(100, error("ConnectBlock() : too many sigops")); - int64 nTxValueIn = tx.GetValueIn(mapInputs); - int64 nTxValueOut = tx.GetValueOut(); + int64_t nTxValueIn = tx.GetValueIn(mapInputs); + int64_t nTxValueOut = tx.GetValueOut(); nValueIn += nTxValueIn; nValueOut += nTxValueOut; if (!tx.IsCoinStake()) @@ -1777,11 +1796,11 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if (IsProofOfWork()) { - int64 nBlockReward = GetProofOfWorkReward(nBits, fProtocol048 ? nFees : 0); + int64_t nBlockReward = GetProofOfWorkReward(nBits, nFees); // Check coinbase reward if (vtx[0].GetValueOut() > nBlockReward) - return error("CheckBlock() : coinbase reward exceeded (actual=%"PRI64d" vs calculated=%"PRI64d")", + return error("CheckBlock() : coinbase reward exceeded (actual=%" PRId64 " vs calculated=%" PRId64 ")", vtx[0].GetValueOut(), nBlockReward); } @@ -1794,8 +1813,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) // fees are not collected by proof-of-stake miners // fees are destroyed to compensate the entire network - if (fProtocol048 && fDebug && IsProofOfStake() && GetBoolArg("-printcreation")) - printf("ConnectBlock() : destroy=%s nFees=%"PRI64d"\n", FormatMoney(nFees).c_str(), nFees); + if (fDebug && IsProofOfStake() && GetBoolArg("-printcreation")) + printf("ConnectBlock() : destroy=%s nFees=%" PRId64 "\n", FormatMoney(nFees).c_str(), nFees); if (fJustCheck) return true; @@ -1854,8 +1873,8 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) vConnect.push_back(pindex); reverse(vConnect.begin(), vConnect.end()); - printf("REORGANIZE: Disconnect %"PRIszu" blocks; %s..%s\n", vDisconnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexBest->GetBlockHash().ToString().substr(0,20).c_str()); - printf("REORGANIZE: Connect %"PRIszu" blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); + printf("REORGANIZE: Disconnect %" PRIszu " blocks; %s..%s\n", vDisconnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexBest->GetBlockHash().ToString().substr(0,20).c_str()); + printf("REORGANIZE: Connect %" PRIszu " blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); // Disconnect shorter branch vector vResurrect; @@ -1983,7 +2002,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) } if (!vpindexSecondary.empty()) - printf("Postponing %"PRIszu" reconnects\n", vpindexSecondary.size()); + printf("Postponing %" PRIszu " reconnects\n", vpindexSecondary.size()); // Switch to new best branch if (!Reorganize(txdb, pindexIntermediate)) @@ -2031,7 +2050,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) uint256 nBestBlockTrust = pindexBest->nHeight != 0 ? (pindexBest->nChainTrust - pindexBest->pprev->nChainTrust) : pindexBest->nChainTrust; - printf("SetBestChain: new best=%s height=%d trust=%s blocktrust=%"PRI64d" date=%s\n", + printf("SetBestChain: new best=%s height=%d trust=%s blocktrust=%" PRId64 " date=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, CBigNum(nBestChainTrust).ToString().c_str(), nBestBlockTrust.Get64(), @@ -2073,7 +2092,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) // guaranteed to be in main chain by sync-checkpoint. This rule is // introduced to help nodes establish a consistent view of the coin // age (trust score) of competing branches. -bool CTransaction::GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const +bool CTransaction::GetCoinAge(CTxDB& txdb, uint64_t& nCoinAge) const { CBigNum bnCentSecond = 0; // coin age in the unit of cent-seconds nCoinAge = 0; @@ -2098,11 +2117,11 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const if (block.GetBlockTime() + nStakeMinAge > nTime) continue; // only count coins meeting min age requirement - int64 nValueIn = txPrev.vout[txin.prevout.n].nValue; + int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue; bnCentSecond += CBigNum(nValueIn) * (nTime-txPrev.nTime) / CENT; if (fDebug && GetBoolArg("-printcoinage")) - printf("coin age nValueIn=%"PRI64d" nTimeDiff=%d bnCentSecond=%s\n", nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString().c_str()); + 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); @@ -2113,14 +2132,14 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const } // ppcoin: total coin age spent in block, in the unit of coin-days. -bool CBlock::GetCoinAge(uint64& nCoinAge) const +bool CBlock::GetCoinAge(uint64_t& nCoinAge) const { nCoinAge = 0; CTxDB txdb("r"); BOOST_FOREACH(const CTransaction& tx, vtx) { - uint64 nTxCoinAge; + uint64_t nTxCoinAge; if (tx.GetCoinAge(txdb, nTxCoinAge)) nCoinAge += nTxCoinAge; else @@ -2130,7 +2149,7 @@ bool CBlock::GetCoinAge(uint64& nCoinAge) const if (nCoinAge == 0) // block coin age minimum 1 coin-day nCoinAge = 1; if (fDebug && GetBoolArg("-printcoinage")) - printf("block coin age total nCoinDays=%"PRI64d"\n", nCoinAge); + printf("block coin age total nCoinDays=%" PRId64 "\n", nCoinAge); return true; } @@ -2169,14 +2188,14 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) } // ppcoin: compute stake modifier - uint64 nStakeModifier = 0; + uint64_t nStakeModifier = 0; bool fGeneratedStakeModifier = false; if (!ComputeNextStakeModifier(pindexNew, nStakeModifier, fGeneratedStakeModifier)) return error("AddToBlockIndex() : ComputeNextStakeModifier() failed"); pindexNew->SetStakeModifier(nStakeModifier, fGeneratedStakeModifier); pindexNew->nStakeModifierChecksum = GetStakeModifierChecksum(pindexNew); if (!CheckStakeModifierCheckpoints(pindexNew->nHeight, pindexNew->nStakeModifierChecksum)) - return error("AddToBlockIndex() : Rejected by stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindexNew->nHeight, nStakeModifier); + return error("AddToBlockIndex() : Rejected by stake modifier checkpoint height=%d, modifier=0x%016" PRIx64, pindexNew->nHeight, nStakeModifier); // Add to mapBlockIndex map::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; @@ -2221,8 +2240,6 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE) return DoS(100, error("CheckBlock() : size limits failed")); - bool fProtocol048 = fTestNet || VALIDATION_SWITCH_TIME < nTime; - // Check proof of work matches claimed amount if (fCheckPOW && IsProofOfWork() && !CheckProofOfWork(GetHash(), nBits)) return DoS(50, error("CheckBlock() : proof of work failed")); @@ -2235,18 +2252,9 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c if (vtx.empty() || !vtx[0].IsCoinBase()) return DoS(100, error("CheckBlock() : first tx is not coinbase")); - if (!fProtocol048) - { - // Check coinbase timestamp - if (GetBlockTime() < (int64)vtx[0].nTime) - return DoS(100, error("CheckBlock() : coinbase timestamp violation")); - } - else - { - // Check coinbase timestamp - if (GetBlockTime() < PastDrift((int64)vtx[0].nTime)) - return DoS(50, error("CheckBlock() : coinbase timestamp is too late")); - } + // Check coinbase timestamp + if (GetBlockTime() < PastDrift((int64_t)vtx[0].nTime)) + return DoS(50, error("CheckBlock() : coinbase timestamp is too late")); for (unsigned int i = 1; i < vtx.size(); i++) { @@ -2254,17 +2262,14 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c return DoS(100, error("CheckBlock() : more than one coinbase")); // Check transaction timestamp - if (GetBlockTime() < (int64)vtx[i].nTime) + if (GetBlockTime() < (int64_t)vtx[i].nTime) return DoS(50, error("CheckBlock() : block timestamp earlier than transaction timestamp")); } if (IsProofOfStake()) { - if (fProtocol048) - { - if (nNonce != 0) - return DoS(100, error("CheckBlock() : non-zero nonce in proof-of-stake block")); - } + if (nNonce != 0) + return DoS(100, error("CheckBlock() : non-zero nonce in proof-of-stake block")); // Coinbase output should be empty if proof-of-stake block if (vtx[0].vout.size() != 1 || !vtx[0].vout[0].IsEmpty()) @@ -2278,8 +2283,8 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c return DoS(100, error("CheckBlock() : more than one coinstake")); // Check coinstake timestamp - if (GetBlockTime() != (int64)vtx[1].nTime) - return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%"PRI64d" nTimeTx=%u", GetBlockTime(), vtx[1].nTime)); + if (GetBlockTime() != (int64_t)vtx[1].nTime) + return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%" PRId64 " nTimeTx=%u", GetBlockTime(), vtx[1].nTime)); // NovaCoin: check proof-of-stake block signature if (fCheckSig && !CheckBlockSignature(true)) @@ -2540,7 +2545,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) if (pcheckpoint && pblock->hashPrevBlock != hashBestChain && !Checkpoints::WantedByPendingSyncCheckpoint(hash)) { // Extra checks to prevent "fill up memory by spamming with bogus blocks" - int64 deltaTime = pblock->GetBlockTime() - pcheckpoint->nTime; + int64_t deltaTime = pblock->GetBlockTime() - pcheckpoint->nTime; CBigNum bnNewBlock; bnNewBlock.SetCompact(pblock->nBits); CBigNum bnRequired; @@ -2638,11 +2643,11 @@ bool CBlock::SignBlock(CWallet& wallet) if (IsProofOfStake()) return true; - static int64 nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp + static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp CKey key; CTransaction txCoinStake; - int64 nSearchTime = txCoinStake.nTime; // search to current time + int64_t nSearchTime = txCoinStake.nTime; // search to current time if (nSearchTime > nLastCoinStakeSearchTime) { @@ -2729,9 +2734,9 @@ bool CBlock::CheckBlockSignature(bool fProofOfStake) const return false; } -bool CheckDiskSpace(uint64 nAdditionalBytes) +bool CheckDiskSpace(uint64_t nAdditionalBytes) { - uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available; + uint64_t nFreeBytesAvailable = filesystem::space(GetDataDir()).available; // Check for nMinDiskSpace bytes (currently 50MB) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) @@ -2796,6 +2801,20 @@ FILE* AppendBlockFile(unsigned int& nFileRet) bool LoadBlockIndex(bool fAllowNew) { + if (fTestNet) + { + pchMessageStart[0] = 0xcd; + pchMessageStart[1] = 0xf2; + pchMessageStart[2] = 0xc0; + pchMessageStart[3] = 0xef; + + bnProofOfWorkLimit = bnProofOfWorkLimitTestNet; // 16 bits PoW target limit for testnet + nStakeMinAge = 2 * 60 * 60; // test net min age is 2 hours + nModifierInterval = 20 * 60; // test modifier interval is 20 minutes + nCoinbaseMaturity = 10; // test maturity is 10 blocks + nStakeTargetSpacing = 5 * 60; // test block spacing is 5 minutes + } + // // Load block index // @@ -2957,7 +2976,7 @@ void PrintBlockTree() // print item CBlock block; block.ReadFromDisk(pindex); - printf("%d (%u,%u) %s %08x %s mint %7s tx %"PRIszu"", + printf("%d (%u,%u) %s %08x %s mint %7s tx %" PRIszu "", pindex->nHeight, pindex->nFile, pindex->nBlockPos, @@ -2988,7 +3007,7 @@ void PrintBlockTree() bool LoadExternalBlockFile(FILE* fileIn) { - int64 nStart = GetTimeMillis(); + int64_t nStart = GetTimeMillis(); int nLoaded = 0; { @@ -3042,7 +3061,7 @@ bool LoadExternalBlockFile(FILE* fileIn) BOOST_CURRENT_FUNCTION); } } - printf("Loaded %i blocks from external file in %"PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart); + printf("Loaded %i blocks from external file in %" PRId64 "ms\n", nLoaded, GetTimeMillis() - nStart); return nLoaded > 0; } @@ -3159,7 +3178,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) static map mapReuseKey; RandAddSeedPerfmon(); if (fDebug) - printf("received: %s (%"PRIszu" bytes)\n", strCommand.c_str(), vRecv.size()); + printf("received: %s (%" PRIszu " bytes)\n", strCommand.c_str(), vRecv.size()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { printf("dropmessagestest DROPPING RECV MESSAGE\n"); @@ -3175,10 +3194,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) return false; } - int64 nTime; + int64_t nTime; CAddress addrMe; CAddress addrFrom; - uint64 nNonce = 1; + uint64_t nNonce = 1; vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; if (pfrom->nVersion < MIN_PROTO_VERSION) { @@ -3323,13 +3342,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (vAddr.size() > 1000) { pfrom->Misbehaving(20); - return error("message addr size() = %"PRIszu"", vAddr.size()); + return error("message addr size() = %" PRIszu "", vAddr.size()); } // Store the new addresses vector vAddrOk; - int64 nNow = GetAdjustedTime(); - int64 nSince = nNow - 10 * 60; + int64_t nNow = GetAdjustedTime(); + int64_t nSince = nNow - 10 * 60; BOOST_FOREACH(CAddress& addr, vAddr) { if (fShutdown) @@ -3348,7 +3367,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) static uint256 hashSalt; if (hashSalt == 0) hashSalt = GetRandHash(); - uint64 hashAddr = addr.GetHash(); + uint64_t hashAddr = addr.GetHash(); uint256 hashRand = hashSalt ^ (hashAddr<<32) ^ ((GetTime()+hashAddr)/(24*60*60)); hashRand = Hash(BEGIN(hashRand), END(hashRand)); multimap mapMix; @@ -3385,7 +3404,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); - return error("message inv size() = %"PRIszu"", vInv.size()); + return error("message inv size() = %" PRIszu "", vInv.size()); } // find last block in inv vector @@ -3435,11 +3454,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); - return error("message getdata size() = %"PRIszu"", vInv.size()); + return error("message getdata size() = %" PRIszu "", vInv.size()); } if (fDebugNet || (vInv.size() != 1)) - printf("received getdata (%"PRIszu" invsz)\n", vInv.size()); + printf("received getdata (%" PRIszu " invsz)\n", vInv.size()); BOOST_FOREACH(const CInv& inv, vInv) { @@ -3676,7 +3695,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "getaddr") { // Don't return addresses older than nCutOff timestamp - int64 nCutOff = GetTime() - (nNodeLifespan * 24 * 60 * 60); + int64_t nCutOff = GetTime() - (nNodeLifespan * 24 * 60 * 60); pfrom->vAddrToSend.clear(); vector vAddr = addrman.GetAddr(); BOOST_FOREACH(const CAddress &addr, vAddr) @@ -3752,7 +3771,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { if (pfrom->nVersion > BIP0031_VERSION) { - uint64 nonce = 0; + uint64_t nonce = 0; vRecv >> nonce; // Echo the message back with the nonce. This allows for two useful features: // @@ -3852,7 +3871,7 @@ bool ProcessMessages(CNode* pfrom) break; } if (pstart - vRecv.begin() > 0) - printf("\n\nPROCESSMESSAGE SKIPPED %"PRIpdd" BYTES\n\n", pstart - vRecv.begin()); + printf("\n\nPROCESSMESSAGE SKIPPED %" PRIpdd " BYTES\n\n", pstart - vRecv.begin()); vRecv.erase(vRecv.begin(), pstart); // Read header @@ -3949,7 +3968,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Keep-alive ping. We send a nonce of zero because we don't use it anywhere // right now. if (pto->nLastSend && GetTime() - pto->nLastSend > 30 * 60 && pto->vSend.empty()) { - uint64 nonce = 0; + uint64_t nonce = 0; if (pto->nVersion > BIP0031_VERSION) pto->PushMessage("ping", nonce); else @@ -3966,7 +3985,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) ResendWalletTransactions(); // Address refresh broadcast - static int64 nLastRebroadcast; + static int64_t nLastRebroadcast; if (!IsInitialBlockDownload() && (GetTime() - nLastRebroadcast > 24 * 60 * 60)) { { @@ -4078,7 +4097,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Message: getdata // vector vGetData; - int64 nNow = GetTime() * 1000000; + int64_t nNow = GetTime() * 1000000; CTxDB txdb("r"); while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) {