5353# error "Bitcoin cannot be compiled without assertions."
5454#endif
5555
56+ #define MICRO 0.000001
57+ #define MILLI 0.001
58+
5659/* *
5760 * Global state
5861 */
@@ -1623,6 +1626,7 @@ static int64_t nTimeConnect = 0;
16231626static int64_t nTimeIndex = 0 ;
16241627static int64_t nTimeCallbacks = 0 ;
16251628static int64_t nTimeTotal = 0 ;
1629+ static int64_t nBlocksTotal = 0 ;
16261630
16271631/* * Apply the effects of this block (with given index) on the UTXO set represented by coins.
16281632 * Validity checks that depend on the UTXO set are also done; ConnectBlock()
@@ -1653,6 +1657,8 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16531657 return true ;
16541658 }
16551659
1660+ nBlocksTotal++;
1661+
16561662 bool fScriptChecks = true ;
16571663 if (!hashAssumeValid.IsNull ()) {
16581664 // We've been configured with the hash of a block which has been externally verified to have a valid history.
@@ -1680,7 +1686,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16801686 }
16811687
16821688 int64_t nTime1 = GetTimeMicros (); nTimeCheck += nTime1 - nTimeStart;
1683- LogPrint (BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs]\n " , 0.001 * (nTime1 - nTimeStart), nTimeCheck * 0.000001 );
1689+ LogPrint (BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs (%.2fms/blk) ]\n " , MILLI * (nTime1 - nTimeStart), nTimeCheck * MICRO, nTimeCheck * MILLI / nBlocksTotal );
16841690
16851691 // Do not allow blocks that contain transactions which 'overwrite' older transactions,
16861692 // unless those are already completely spent.
@@ -1729,7 +1735,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
17291735 unsigned int flags = GetBlockScriptFlags (pindex, chainparams.GetConsensus ());
17301736
17311737 int64_t nTime2 = GetTimeMicros (); nTimeForks += nTime2 - nTime1;
1732- LogPrint (BCLog::BENCH, " - Fork checks: %.2fms [%.2fs]\n " , 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001 );
1738+ LogPrint (BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk) ]\n " , MILLI * (nTime2 - nTime1), nTimeForks * MICRO, nTimeForks * MILLI / nBlocksTotal );
17331739
17341740 CBlockUndo blockundo;
17351741
@@ -1803,7 +1809,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
18031809 pos.nTxOffset += ::GetSerializeSize (tx, SER_DISK, CLIENT_VERSION);
18041810 }
18051811 int64_t nTime3 = GetTimeMicros (); nTimeConnect += nTime3 - nTime2;
1806- LogPrint (BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n " , (unsigned )block.vtx .size (), 0.001 * (nTime3 - nTime2), 0.001 * (nTime3 - nTime2) / block.vtx .size (), nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs-1 ), nTimeConnect * 0.000001 );
1812+ LogPrint (BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk) ]\n " , (unsigned )block.vtx .size (), MILLI * (nTime3 - nTime2), MILLI * (nTime3 - nTime2) / block.vtx .size (), nInputs <= 1 ? 0 : MILLI * (nTime3 - nTime2) / (nInputs-1 ), nTimeConnect * MICRO, nTimeConnect * MILLI / nBlocksTotal );
18071813
18081814 CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , chainparams.GetConsensus ());
18091815 if (block.vtx [0 ]->GetValueOut () > blockReward)
@@ -1815,7 +1821,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
18151821 if (!control.Wait ())
18161822 return state.DoS (100 , error (" %s: CheckQueue failed" , __func__), REJECT_INVALID, " block-validation-failed" );
18171823 int64_t nTime4 = GetTimeMicros (); nTimeVerify += nTime4 - nTime2;
1818- LogPrint (BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs]\n " , nInputs - 1 , 0.001 * (nTime4 - nTime2), nInputs <= 1 ? 0 : 0.001 * (nTime4 - nTime2) / (nInputs-1 ), nTimeVerify * 0.000001 );
1824+ LogPrint (BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk) ]\n " , nInputs - 1 , MILLI * (nTime4 - nTime2), nInputs <= 1 ? 0 : MILLI * (nTime4 - nTime2) / (nInputs-1 ), nTimeVerify * MICRO, nTimeVerify * MILLI / nBlocksTotal );
18191825
18201826 if (fJustCheck )
18211827 return true ;
@@ -1847,10 +1853,10 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
18471853 view.SetBestBlock (pindex->GetBlockHash ());
18481854
18491855 int64_t nTime5 = GetTimeMicros (); nTimeIndex += nTime5 - nTime4;
1850- LogPrint (BCLog::BENCH, " - Index writing: %.2fms [%.2fs]\n " , 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001 );
1856+ LogPrint (BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk) ]\n " , MILLI * (nTime5 - nTime4), nTimeIndex * MICRO, nTimeIndex * MILLI / nBlocksTotal );
18511857
18521858 int64_t nTime6 = GetTimeMicros (); nTimeCallbacks += nTime6 - nTime5;
1853- LogPrint (BCLog::BENCH, " - Callbacks: %.2fms [%.2fs]\n " , 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001 );
1859+ LogPrint (BCLog::BENCH, " - Callbacks: %.2fms [%.2fs (%.2fms/blk) ]\n " , MILLI * (nTime6 - nTime5), nTimeCallbacks * MICRO, nTimeCallbacks * MILLI / nBlocksTotal );
18541860
18551861 return true ;
18561862}
@@ -2075,7 +2081,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
20752081 bool flushed = view.Flush ();
20762082 assert (flushed);
20772083 }
2078- LogPrint (BCLog::BENCH, " - Disconnect block: %.2fms\n " , (GetTimeMicros () - nStart) * 0.001 );
2084+ LogPrint (BCLog::BENCH, " - Disconnect block: %.2fms\n " , (GetTimeMicros () - nStart) * MILLI );
20792085 // Write the chain state to disk, if necessary.
20802086 if (!FlushStateToDisk (chainparams, state, FLUSH_STATE_IF_NEEDED))
20812087 return false ;
@@ -2196,7 +2202,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
21962202 // Apply the block atomically to the chain state.
21972203 int64_t nTime2 = GetTimeMicros (); nTimeReadFromDisk += nTime2 - nTime1;
21982204 int64_t nTime3;
2199- LogPrint (BCLog::BENCH, " - Load block from disk: %.2fms [%.2fs]\n " , (nTime2 - nTime1) * 0.001 , nTimeReadFromDisk * 0.000001 );
2205+ LogPrint (BCLog::BENCH, " - Load block from disk: %.2fms [%.2fs]\n " , (nTime2 - nTime1) * MILLI , nTimeReadFromDisk * MICRO );
22002206 {
22012207 CCoinsViewCache view (pcoinsTip);
22022208 bool rv = ConnectBlock (blockConnecting, state, pindexNew, view, chainparams);
@@ -2207,26 +2213,26 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
22072213 return error (" ConnectTip(): ConnectBlock %s failed" , pindexNew->GetBlockHash ().ToString ());
22082214 }
22092215 nTime3 = GetTimeMicros (); nTimeConnectTotal += nTime3 - nTime2;
2210- LogPrint (BCLog::BENCH, " - Connect total: %.2fms [%.2fs]\n " , (nTime3 - nTime2) * 0.001 , nTimeConnectTotal * 0.000001 );
2216+ LogPrint (BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk) ]\n " , (nTime3 - nTime2) * MILLI , nTimeConnectTotal * MICRO, nTimeConnectTotal * MILLI / nBlocksTotal );
22112217 bool flushed = view.Flush ();
22122218 assert (flushed);
22132219 }
22142220 int64_t nTime4 = GetTimeMicros (); nTimeFlush += nTime4 - nTime3;
2215- LogPrint (BCLog::BENCH, " - Flush: %.2fms [%.2fs]\n " , (nTime4 - nTime3) * 0.001 , nTimeFlush * 0.000001 );
2221+ LogPrint (BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk) ]\n " , (nTime4 - nTime3) * MILLI , nTimeFlush * MICRO, nTimeFlush * MILLI / nBlocksTotal );
22162222 // Write the chain state to disk, if necessary.
22172223 if (!FlushStateToDisk (chainparams, state, FLUSH_STATE_IF_NEEDED))
22182224 return false ;
22192225 int64_t nTime5 = GetTimeMicros (); nTimeChainState += nTime5 - nTime4;
2220- LogPrint (BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs]\n " , (nTime5 - nTime4) * 0.001 , nTimeChainState * 0.000001 );
2226+ LogPrint (BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk) ]\n " , (nTime5 - nTime4) * MILLI , nTimeChainState * MICRO, nTimeChainState * MILLI / nBlocksTotal );
22212227 // Remove conflicting transactions from the mempool.;
22222228 mempool.removeForBlock (blockConnecting.vtx , pindexNew->nHeight );
22232229 disconnectpool.removeForBlock (blockConnecting.vtx );
22242230 // Update chainActive & related variables.
22252231 UpdateTip (pindexNew, chainparams);
22262232
22272233 int64_t nTime6 = GetTimeMicros (); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
2228- LogPrint (BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs]\n " , (nTime6 - nTime5) * 0.001 , nTimePostConnect * 0.000001 );
2229- LogPrint (BCLog::BENCH, " - Connect block: %.2fms [%.2fs]\n " , (nTime6 - nTime1) * 0.001 , nTimeTotal * 0.000001 );
2234+ LogPrint (BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk) ]\n " , (nTime6 - nTime5) * MILLI , nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal );
2235+ LogPrint (BCLog::BENCH, " - Connect block: %.2fms [%.2fs (%.2fms/blk) ]\n " , (nTime6 - nTime1) * MILLI , nTimeTotal * MICRO, nTimeTotal * MILLI / nBlocksTotal );
22302236
22312237 connectTrace.BlockConnected (pindexNew, std::move (pthisBlock));
22322238 return true ;
@@ -4367,7 +4373,7 @@ void DumpMempool(void)
43674373 file.fclose ();
43684374 RenameOver (GetDataDir () / " mempool.dat.new" , GetDataDir () / " mempool.dat" );
43694375 int64_t last = GetTimeMicros ();
4370- LogPrintf (" Dumped mempool: %gs to copy, %gs to dump\n " , (mid-start)*0.000001 , (last-mid)*0.000001 );
4376+ LogPrintf (" Dumped mempool: %gs to copy, %gs to dump\n " , (mid-start)*MICRO , (last-mid)*MICRO );
43714377 } catch (const std::exception& e) {
43724378 LogPrintf (" Failed to dump mempool: %s. Continuing anyway.\n " , e.what ());
43734379 }
0 commit comments