53
53
# error "Bitcoin cannot be compiled without assertions."
54
54
#endif
55
55
56
+ #define MICRO 0.000001
57
+ #define MILLI 0.001
58
+
56
59
/* *
57
60
* Global state
58
61
*/
@@ -1623,6 +1626,7 @@ static int64_t nTimeConnect = 0;
1623
1626
static int64_t nTimeIndex = 0 ;
1624
1627
static int64_t nTimeCallbacks = 0 ;
1625
1628
static int64_t nTimeTotal = 0 ;
1629
+ static int64_t nBlocksTotal = 0 ;
1626
1630
1627
1631
/* * Apply the effects of this block (with given index) on the UTXO set represented by coins.
1628
1632
* 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
1653
1657
return true ;
1654
1658
}
1655
1659
1660
+ nBlocksTotal++;
1661
+
1656
1662
bool fScriptChecks = true ;
1657
1663
if (!hashAssumeValid.IsNull ()) {
1658
1664
// 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
1680
1686
}
1681
1687
1682
1688
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 );
1684
1690
1685
1691
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
1686
1692
// unless those are already completely spent.
@@ -1729,7 +1735,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
1729
1735
unsigned int flags = GetBlockScriptFlags (pindex, chainparams.GetConsensus ());
1730
1736
1731
1737
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 );
1733
1739
1734
1740
CBlockUndo blockundo;
1735
1741
@@ -1803,7 +1809,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
1803
1809
pos.nTxOffset += ::GetSerializeSize (tx, SER_DISK, CLIENT_VERSION);
1804
1810
}
1805
1811
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 );
1807
1813
1808
1814
CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , chainparams.GetConsensus ());
1809
1815
if (block.vtx [0 ]->GetValueOut () > blockReward)
@@ -1815,7 +1821,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
1815
1821
if (!control.Wait ())
1816
1822
return state.DoS (100 , error (" %s: CheckQueue failed" , __func__), REJECT_INVALID, " block-validation-failed" );
1817
1823
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 );
1819
1825
1820
1826
if (fJustCheck )
1821
1827
return true ;
@@ -1847,10 +1853,10 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
1847
1853
view.SetBestBlock (pindex->GetBlockHash ());
1848
1854
1849
1855
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 );
1851
1857
1852
1858
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 );
1854
1860
1855
1861
return true ;
1856
1862
}
@@ -2075,7 +2081,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
2075
2081
bool flushed = view.Flush ();
2076
2082
assert (flushed);
2077
2083
}
2078
- LogPrint (BCLog::BENCH, " - Disconnect block: %.2fms\n " , (GetTimeMicros () - nStart) * 0.001 );
2084
+ LogPrint (BCLog::BENCH, " - Disconnect block: %.2fms\n " , (GetTimeMicros () - nStart) * MILLI );
2079
2085
// Write the chain state to disk, if necessary.
2080
2086
if (!FlushStateToDisk (chainparams, state, FLUSH_STATE_IF_NEEDED))
2081
2087
return false ;
@@ -2196,7 +2202,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
2196
2202
// Apply the block atomically to the chain state.
2197
2203
int64_t nTime2 = GetTimeMicros (); nTimeReadFromDisk += nTime2 - nTime1;
2198
2204
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 );
2200
2206
{
2201
2207
CCoinsViewCache view (pcoinsTip);
2202
2208
bool rv = ConnectBlock (blockConnecting, state, pindexNew, view, chainparams);
@@ -2207,26 +2213,26 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
2207
2213
return error (" ConnectTip(): ConnectBlock %s failed" , pindexNew->GetBlockHash ().ToString ());
2208
2214
}
2209
2215
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 );
2211
2217
bool flushed = view.Flush ();
2212
2218
assert (flushed);
2213
2219
}
2214
2220
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 );
2216
2222
// Write the chain state to disk, if necessary.
2217
2223
if (!FlushStateToDisk (chainparams, state, FLUSH_STATE_IF_NEEDED))
2218
2224
return false ;
2219
2225
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 );
2221
2227
// Remove conflicting transactions from the mempool.;
2222
2228
mempool.removeForBlock (blockConnecting.vtx , pindexNew->nHeight );
2223
2229
disconnectpool.removeForBlock (blockConnecting.vtx );
2224
2230
// Update chainActive & related variables.
2225
2231
UpdateTip (pindexNew, chainparams);
2226
2232
2227
2233
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 );
2230
2236
2231
2237
connectTrace.BlockConnected (pindexNew, std::move (pthisBlock));
2232
2238
return true ;
@@ -4367,7 +4373,7 @@ void DumpMempool(void)
4367
4373
file.fclose ();
4368
4374
RenameOver (GetDataDir () / " mempool.dat.new" , GetDataDir () / " mempool.dat" );
4369
4375
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 );
4371
4377
} catch (const std::exception& e) {
4372
4378
LogPrintf (" Failed to dump mempool: %s. Continuing anyway.\n " , e.what ());
4373
4379
}
0 commit comments