X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=1a90e5172df83080463f1b5e6e847cef7a9db243;hp=b8577398aea3068b3102d5e508b27665bb07d0ee;hb=6aba6f08af53e3fa49ab4d1ef002e6771d0ce358;hpb=fe3160e5c4a0046b4f97ec6d32d280aaa6ecc74c diff --git a/src/main.cpp b/src/main.cpp index b857739..1a90e51 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #include "checkpoints.h" #include "db.h" #include "txdb.h" -#include "net.h" #include "init.h" #include "ui_interface.h" #include "checkqueue.h" @@ -182,10 +181,10 @@ void static Inventory(const uint256& hash) } // ask wallets to resend their transactions -void ResendWalletTransactions() +void ResendWalletTransactions(bool fForceResend) { BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) - pwallet->ResendWalletTransactions(); + pwallet->ResendWalletTransactions(fForceResend); } @@ -430,7 +429,7 @@ unsigned int CTransaction::GetLegacySigOpCount() const { unsigned int nSigOps = 0; - if (!IsCoinBase() || nTime < COINBASE_SIGOPS_SWITCH_TIME) + if (!IsCoinBase()) { // Coinbase scriptsigs are never executed, so there is // no sense in calculation of sigops. @@ -619,6 +618,10 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, if (pfMissingInputs) *pfMissingInputs = false; + // Time (prevent mempool memory exhaustion attack) + if (tx.nTime > FutureDrift(GetAdjustedTime())) + return tx.DoS(10, error("CTxMemPool::accept() : transaction timestamp is too far in the future")); + if (!tx.CheckTransaction()) return error("CTxMemPool::accept() : CheckTransaction failed"); @@ -1186,10 +1189,10 @@ const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfSta unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake) { - CBigNum bnTargetLimit = !fProofOfStake ? bnProofOfWorkLimit : GetProofOfStakeLimit(pindexLast->nHeight, pindexLast->nTime); - if (pindexLast == NULL) - return bnTargetLimit.GetCompact(); // genesis block + return bnProofOfWorkLimit.GetCompact(); // genesis block + + CBigNum bnTargetLimit = !fProofOfStake ? bnProofOfWorkLimit : GetProofOfStakeLimit(pindexLast->nHeight, pindexLast->nTime); const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake); if (pindexPrev->pprev == NULL) @@ -1755,8 +1758,16 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if (!tx.IsCoinStake()) nFees += nTxValueIn - nTxValueOut; + unsigned int nFlags = SCRIPT_VERIFY_NOCACHE | SCRIPT_VERIFY_P2SH; + + if (tx.nTime >= CHECKLOCKTIMEVERIFY_SWITCH_TIME) { + nFlags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; + // OP_CHECKSEQUENCEVERIFY is senseless without BIP68, so we're going disable it for now. + // nFlags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY; + } + std::vector vChecks; - if (!tx.ConnectInputs(txdb, mapInputs, mapQueuedChanges, posThisTx, pindex, true, false, fScriptChecks, SCRIPT_VERIFY_NOCACHE | SCRIPT_VERIFY_P2SH, nScriptCheckThreads ? &vChecks : NULL)) + if (!tx.ConnectInputs(txdb, mapInputs, mapQueuedChanges, posThisTx, pindex, true, false, fScriptChecks, nFlags, nScriptCheckThreads ? &vChecks : NULL)) return false; control.Add(vChecks); } @@ -2134,7 +2145,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) return error("AddToBlockIndex() : %s already exists", hash.ToString().substr(0,20).c_str()); // Construct new block index object - CBlockIndex* pindexNew = new CBlockIndex(nFile, nBlockPos, *this); + CBlockIndex* pindexNew = new(nothrow) CBlockIndex(nFile, nBlockPos, *this); if (!pindexNew) return error("AddToBlockIndex() : new CBlockIndex failed"); pindexNew->phashBlock = &hash; @@ -2336,9 +2347,9 @@ bool CBlock::AcceptBlock() return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake")); int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); - int nMaxOffset = 12 * 3600; // 12 hours - if (pindexPrev->nTime < 1450569600) - nMaxOffset = 7 * 86400; // One week until 20 Dec, 2015 + int nMaxOffset = 12 * nOneHour; // 12 hours + if (fTestNet || pindexPrev->nTime < 1450569600) + nMaxOffset = 7 * nOneWeek; // One week (permanently on testNet or until 20 Dec, 2015 on mainNet) // Check timestamp against prev if (GetBlockTime() <= nMedianTimePast || FutureDrift(GetBlockTime()) < pindexPrev->GetBlockTime()) @@ -2517,6 +2528,13 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) if (mapOrphanBlocks.count(hash)) return error("ProcessBlock() : already have block (orphan) %s", hash.ToString().substr(0,20).c_str()); + // Check that block isn't listed as unconditionally banned. + if (!Checkpoints::CheckBanned(hash)) { + if (pfrom) + pfrom->Misbehaving(100); + return error("ProcessBlock() : block %s is rejected by hard-coded banlist", hash.GetHex().substr(0,20).c_str()); + } + // Check proof-of-stake // Limited duplicity on stake: prevents block flood attack // Duplicate stake allowed only when there is orphan child block @@ -3668,7 +3686,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (!GetBoolArg("-allowreceivebyip")) { - pfrom->PushMessage("reply", hashReply, (int)2, string("")); + pfrom->PushMessage("reply", hashReply, 2, string("")); return true; } @@ -3684,7 +3702,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Send back approval of order and pubkey to use CScript scriptPubKey; scriptPubKey << mapReuseKey[pfrom->addr] << OP_CHECKSIG; - pfrom->PushMessage("reply", hashReply, (int)0, scriptPubKey); + pfrom->PushMessage("reply", hashReply, 0, scriptPubKey); } @@ -3710,23 +3728,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "ping") { - if (pfrom->nVersion > BIP0031_VERSION) - { - uint64_t nonce = 0; - vRecv >> nonce; - // Echo the message back with the nonce. This allows for two useful features: - // - // 1) A remote node can quickly check if the connection is operational - // 2) Remote nodes can measure the latency of the network thread. If this node - // is overloaded it won't respond to pings quickly and the remote node can - // avoid sending us more work, like chain download requests. - // - // The nonce stops the remote getting confused between different pings: without - // it, if the remote node sends a ping once per second and this node takes 5 - // seconds to respond to each, the 5th ping the remote sends would appear to - // return very quickly. - pfrom->PushMessage("pong", nonce); - } + uint64_t nonce = 0; + vRecv >> nonce; + // Echo the message back with the nonce. This allows for two useful features: + // + // 1) A remote node can quickly check if the connection is operational + // 2) Remote nodes can measure the latency of the network thread. If this node + // is overloaded it won't respond to pings quickly and the remote node can + // avoid sending us more work, like chain download requests. + // + // The nonce stops the remote getting confused between different pings: without + // it, if the remote node sends a ping once per second and this node takes 5 + // seconds to respond to each, the 5th ping the remote sends would appear to + // return very quickly. + pfrom->PushMessage("pong", nonce); } @@ -3910,10 +3925,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // right now. if (pto->nLastSend && GetTime() - pto->nLastSend > nPingInterval && pto->vSend.empty()) { uint64_t nonce = 0; - if (pto->nVersion > BIP0031_VERSION) - pto->PushMessage("ping", nonce); - else - pto->PushMessage("ping"); + pto->PushMessage("ping", nonce); } // Start block sync @@ -4084,4 +4096,4 @@ public: // orphan transactions } -} instance_of_cmaincleanup; \ No newline at end of file +} instance_of_cmaincleanup;