diff --git a/src/validation.cpp b/src/validation.cpp index 00a8f31bdbc72..c925b6b173fca 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -68,8 +68,6 @@ #include #include -#include - #define MICRO 0.000001 #define MILLI 0.001 @@ -944,7 +942,7 @@ bool MemPoolAccept::Finalize(ATMPArgs& args, Workspace& ws) bool MemPoolAccept::AcceptSingleTransaction(const CTransactionRef& ptx, ATMPArgs& args) { - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); + auto start = Now(); AssertLockHeld(cs_main); LOCK(m_pool.cs); // mempool "read lock" (held through GetMainSignals().TransactionAddedToMempool()) @@ -971,9 +969,9 @@ bool MemPoolAccept::AcceptSingleTransaction(const CTransactionRef& ptx, ATMPArgs GetMainSignals().TransactionAddedToMempool(ptx, nAcceptTime); const CTransaction& tx = *ptx; - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("AcceptToMemoryPool_ms", diff.total_milliseconds(), 1.0f); + auto finish = Now(); + auto diff = finish - start; + statsClient.timing("AcceptToMemoryPool_ms", count_milliseconds(diff), 1.0f); statsClient.inc("transactions.accepted", 1.0f); statsClient.count("transactions.inputs", tx.vin.size(), 1.0f); statsClient.count("transactions.outputs", tx.vout.size(), 1.0f); @@ -1498,7 +1496,7 @@ void InitScriptExecutionCache() { */ bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); + auto start = Now(); if (tx.IsCoinBase()) return true; if (pvChecks) { @@ -1575,9 +1573,9 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const C g_scriptExecutionCache.insert(hashCacheEntry); } - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("CheckInputScripts_ms", diff.total_milliseconds(), 1.0f); + auto finish = Now(); + auto diff = finish - start; + statsClient.timing("CheckInputScripts_ms", count_milliseconds(diff), 1.0f); return true; } @@ -1694,7 +1692,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI return DISCONNECT_FAILED; } - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); + auto start = Now(); bool fClean = true; @@ -1829,9 +1827,9 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI view.SetBestBlock(pindex->pprev->GetBlockHash()); m_evoDb.WriteBestBlock(pindex->pprev->GetBlockHash()); - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("DisconnectBlock_ms", diff.total_milliseconds(), 1.0f); + auto finish = Now(); + auto diff = finish - start; + statsClient.timing("DisconnectBlock_ms", count_milliseconds(diff), 1.0f); return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN; } @@ -2015,7 +2013,7 @@ static int64_t nBlocksTotal = 0; bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck) { - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); + int64_t nTimeStart = GetTimeMicros(); AssertLockHeld(cs_main); assert(pindex); @@ -2026,7 +2024,6 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, assert(m_clhandler); assert(m_isman); assert(m_quorum_block_processor); - int64_t nTimeStart = GetTimeMicros(); // Check it again in case a previous version let a bad block in // NOTE: We don't currently (re-)invoke ContextualCheckBlock() or @@ -2455,9 +2452,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, int64_t nTime8 = GetTimeMicros(); nTimeCallbacks += nTime8 - nTime5; LogPrint(BCLog::BENCHMARK, " - Callbacks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime8 - nTime5), nTimeCallbacks * MICRO, nTimeCallbacks * MILLI / nBlocksTotal); - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("ConnectBlock_ms", diff.total_milliseconds(), 1.0f); + auto diff = nTime8 - nTimeStart; + statsClient.timing("ConnectBlock_ms", diff, 1.0f); statsClient.gauge("blocks.tip.SizeBytes", ::GetSerializeSize(block, PROTOCOL_VERSION), 1.0f); statsClient.gauge("blocks.tip.Height", m_chain.Height(), 1.0f); statsClient.gauge("blocks.tip.Version", block.nVersion, 1.0f); @@ -2841,7 +2837,6 @@ class ConnectTrace { */ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew, const std::shared_ptr& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) { - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); AssertLockHeld(cs_main); if (m_mempool) AssertLockHeld(m_mempool->cs); @@ -2903,9 +2898,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew LogPrint(BCLog::BENCHMARK, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal); LogPrint(BCLog::BENCHMARK, "- Connect block: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime1) * MILLI, nTimeTotal * MICRO, nTimeTotal * MILLI / nBlocksTotal); - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("ConnectTip_ms", diff.total_milliseconds(), 1.0f); + statsClient.timing("ConnectTip_ms", nTime6 - nTime1, 1.0f); connectTrace.BlockConnected(pindexNew, std::move(pthisBlock)); return true; @@ -3124,7 +3117,7 @@ bool CChainState::ActivateBestChain(BlockValidationState& state, std::shared_ptr // we use m_cs_chainstate to enforce mutual exclusion so that only one caller may execute this function at a time LOCK(m_cs_chainstate); - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); + auto start = Now(); CBlockIndex *pindexMostWork = nullptr; CBlockIndex *pindexNewTip = nullptr; @@ -3205,9 +3198,9 @@ bool CChainState::ActivateBestChain(BlockValidationState& state, std::shared_ptr } while (pindexNewTip != pindexMostWork); CheckBlockIndex(); - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("ActivateBestChain_ms", diff.total_milliseconds(), 1.0f); + auto finish = Now(); + auto diff = finish - start; + statsClient.timing("ActivateBestChain_ms", count_milliseconds(diff), 1.0f); // Write changes periodically to disk, after relay. if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) { @@ -3758,7 +3751,7 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu { // These are checks that are independent of context. - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); + auto start = Now(); if (block.fChecked) return true; @@ -3821,9 +3814,9 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu if (fCheckPOW && fCheckMerkleRoot) block.fChecked = true; - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("CheckBlock_us", diff.total_microseconds(), 1.0f); + auto finish = Now(); + auto diff = finish - start; + statsClient.timing("CheckBlock_us", count_microseconds(diff), 1.0f); return true; } @@ -4128,7 +4121,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector& /** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */ bool CChainState::AcceptBlock(const std::shared_ptr& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock) { - boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); + auto start = Now(); const CBlock& block = *pblock; @@ -4210,9 +4203,9 @@ bool CChainState::AcceptBlock(const std::shared_ptr& pblock, Block CheckBlockIndex(); - boost::posix_time::ptime finish = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration diff = finish - start; - statsClient.timing("AcceptBlock_us", diff.total_microseconds(), 1.0f); + auto finish = Now(); + auto diff = finish - start; + statsClient.timing("AcceptBlock_us", count_microseconds(diff), 1.0f); return true; }