From: CryptoManiac Date: Thu, 31 Mar 2016 16:02:47 +0000 (+0300) Subject: Merge pull request #296 from svost/patch X-Git-Tag: nvc-v0.5.8~15^2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=c95d66bd55a225326e81dce15d347f04b1d71d67;hp=-c Merge pull request #296 from svost/patch Minor fix --- c95d66bd55a225326e81dce15d347f04b1d71d67 diff --combined src/init.cpp index 8b0302c,01900a5..0801311 --- a/src/init.cpp +++ b/src/init.cpp @@@ -38,6 -38,7 +38,6 @@@ enum Checkpoints::CPMode CheckpointsMod // Ping and address broadcast intervals extern int64_t nPingInterval; -extern int64_t nBroadcastInterval; extern int64_t nReserveBalance; ////////////////////////////////////////////////////////////////////////////// @@@ -381,6 -382,7 +381,6 @@@ bool AppInit2( // Ping and address broadcast intervals nPingInterval = max(10 * 60, GetArg("-keepalive", 30 * 60)); - nBroadcastInterval = max(6 * nOneHour, GetArg("-addrsetlifetime", nOneDay)); CheckpointsMode = Checkpoints::STRICT; std::string strCpMode = GetArg("-cppolicy", "strict"); @@@ -778,8 -780,7 +778,7 @@@ strLoadError = _("Error loading block database"); break; } - } catch(std::exception &e) { - (void)e; + } catch(const std::exception&) { strLoadError = _("Error opening block database"); break; } diff --combined src/main.cpp index 9ef3d64,4b7bb9a..502aa15 --- a/src/main.cpp +++ b/src/main.cpp @@@ -80,6 -80,7 +80,6 @@@ int64_t nMinimumInputValue = MIN_TXOUT_ // Ping and address broadcast intervals int64_t nPingInterval = 30 * 60; -int64_t nBroadcastInterval = nOneDay; extern enum Checkpoints::CPMode CheckpointsMode; @@@ -116,6 -117,15 +116,6 @@@ bool static IsFromMe(CTransaction& tx return false; } -// get the wallet transaction with the given hash (if it exists) -bool static GetTransaction(const uint256& hashTx, CWalletTx& wtx) -{ - BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) - if (pwallet->GetTransaction(hashTx,wtx)) - return true; - return false; -} - // erases transaction with the given hash from all wallets void static EraseFromWallets(uint256 hash) { @@@ -435,7 -445,6 +435,6 @@@ CTransaction::GetLegacySigOpCount() con return nSigOps; } - int CMerkleTx::SetMerkleBranch(const CBlock* pblock) { if (fClient) @@@ -446,16 -455,6 +445,6 @@@ else { CBlock blockTmp; - if (pblock == NULL) - { - // Load the block this tx is in - CTxIndex txindex; - if (!CTxDB("r").ReadTxIndex(GetHash(), txindex)) - return 0; - if (!blockTmp.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos)) - return 0; - pblock = &blockTmp; - } // Update the tx's hashBlock hashBlock = pblock->GetHash(); @@@ -480,19 -479,13 +469,13 @@@ map::iterator mi = mapBlockIndex.find(hashBlock); if (mi == mapBlockIndex.end()) return 0; - CBlockIndex* pindex = (*mi).second; + const CBlockIndex* pindex = (*mi).second; if (!pindex || !pindex->IsInMainChain()) return 0; return pindexBest->nHeight - pindex->nHeight + 1; } - - - - - - bool CTransaction::CheckTransaction() const { // Basic checks that don't depend on any context @@@ -3903,13 -3896,10 +3886,13 @@@ bool ProcessMessages(CNode* pfrom } -bool SendMessages(CNode* pto, bool fSendTrickle) +bool SendMessages(CNode* pto) { TRY_LOCK(cs_main, lockMain); if (lockMain) { + // Current time in microseconds + int64_t nNow = GetTimeMicros(); + // Don't send anything until we get their version message if (pto->nVersion == 0) return true; @@@ -3931,20 -3921,39 +3914,20 @@@ ResendWalletTransactions(); // Address refresh broadcast - static int64_t nLastRebroadcast; - if (!IsInitialBlockDownload() && (GetTime() - nLastRebroadcast > nBroadcastInterval)) - { - { - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - // Periodically clear setAddrKnown to allow refresh broadcasts - if (nLastRebroadcast) - pnode->setAddrKnown.clear(); - - // Rebroadcast our address - if (!fNoListen) - { - CAddress addr = GetLocalAddress(&pnode->addr); - if (addr.IsRoutable()) - pnode->PushAddress(addr); - } - } - } - nLastRebroadcast = GetTime(); + if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) { + AdvertiseLocal(pto); + pto->nNextLocalAddrSend = PoissonNextSend(nNow, nOneDay); } // // Message: addr // - if (fSendTrickle) - { + if (pto->nNextAddrSend < nNow) { + pto->nNextAddrSend = PoissonNextSend(nNow, 30); vector vAddr; vAddr.reserve(pto->vAddrToSend.size()); BOOST_FOREACH(const CAddress& addr, pto->vAddrToSend) { - // returns true if wasn't already contained in the set if (pto->setAddrKnown.insert(addr).second) { vAddr.push_back(addr); @@@ -3961,17 -3970,13 +3944,17 @@@ pto->PushMessage("addr", vAddr); } - // // Message: inventory // vector vInv; vector vInvWait; { + bool fSendTrickle = false; + if (pto->nNextInvSend < nNow) { + fSendTrickle = true; + pto->nNextInvSend = PoissonNextSend(nNow, 5); + } LOCK(pto->cs_inventory); vInv.reserve(pto->vInventoryToSend.size()); vInvWait.reserve(pto->vInventoryToSend.size()); @@@ -3991,6 -3996,15 +3974,6 @@@ hashRand = Hash(BEGIN(hashRand), END(hashRand)); bool fTrickleWait = ((hashRand & 3) != 0); - // always trickle our own transactions - if (!fTrickleWait) - { - CWalletTx wtx; - if (GetTransaction(inv.hash, wtx)) - if (wtx.fFromMe) - fTrickleWait = true; - } - if (fTrickleWait) { vInvWait.push_back(inv); @@@ -4019,6 -4033,7 +4002,6 @@@ // Message: getdata // vector vGetData; - int64_t nNow = GetTime() * 1000000; CTxDB txdb("r"); while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) {