Skip to content

Commit de7d459

Browse files
committed
Merge pull request #6965
77f1f59 Benchmark sanity checks and fork checks in ConnectBlock (Matt Corallo)
2 parents b56953e + 77f1f59 commit de7d459

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/main.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,8 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const
17111711
}
17121712
}
17131713

1714+
static int64_t nTimeCheck = 0;
1715+
static int64_t nTimeForks = 0;
17141716
static int64_t nTimeVerify = 0;
17151717
static int64_t nTimeConnect = 0;
17161718
static int64_t nTimeIndex = 0;
@@ -1721,6 +1723,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17211723
{
17221724
const CChainParams& chainparams = Params();
17231725
AssertLockHeld(cs_main);
1726+
1727+
int64_t nTimeStart = GetTimeMicros();
1728+
17241729
// Check it again in case a previous version let a bad block in
17251730
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck))
17261731
return false;
@@ -1746,6 +1751,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17461751
}
17471752
}
17481753

1754+
int64_t nTime1 = GetTimeMicros(); nTimeCheck += nTime1 - nTimeStart;
1755+
LogPrint("bench", " - Sanity checks: %.2fms [%.2fs]\n", 0.001 * (nTime1 - nTimeStart), nTimeCheck * 0.000001);
1756+
17491757
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
17501758
// unless those are already completely spent.
17511759
// If such overwrites are allowed, coinbases and transactions depending upon those
@@ -1788,11 +1796,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17881796
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
17891797
}
17901798

1799+
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
1800+
LogPrint("bench", " - Fork checks: %.2fms [%.2fs]\n", 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001);
1801+
17911802
CBlockUndo blockundo;
17921803

17931804
CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL);
17941805

1795-
int64_t nTimeStart = GetTimeMicros();
17961806
CAmount nFees = 0;
17971807
int nInputs = 0;
17981808
unsigned int nSigOps = 0;
@@ -1845,8 +1855,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18451855
vPos.push_back(std::make_pair(tx.GetHash(), pos));
18461856
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
18471857
}
1848-
int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart;
1849-
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001);
1858+
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
1859+
LogPrint("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);
18501860

18511861
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
18521862
if (block.vtx[0].GetValueOut() > blockReward)
@@ -1857,8 +1867,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18571867

18581868
if (!control.Wait())
18591869
return state.DoS(100, false);
1860-
int64_t nTime2 = GetTimeMicros(); nTimeVerify += nTime2 - nTimeStart;
1861-
LogPrint("bench", " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs]\n", nInputs - 1, 0.001 * (nTime2 - nTimeStart), nInputs <= 1 ? 0 : 0.001 * (nTime2 - nTimeStart) / (nInputs-1), nTimeVerify * 0.000001);
1870+
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime2;
1871+
LogPrint("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);
18621872

18631873
if (fJustCheck)
18641874
return true;
@@ -1889,16 +1899,16 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18891899
// add this block to the view's block chain
18901900
view.SetBestBlock(pindex->GetBlockHash());
18911901

1892-
int64_t nTime3 = GetTimeMicros(); nTimeIndex += nTime3 - nTime2;
1893-
LogPrint("bench", " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime3 - nTime2), nTimeIndex * 0.000001);
1902+
int64_t nTime5 = GetTimeMicros(); nTimeIndex += nTime5 - nTime4;
1903+
LogPrint("bench", " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001);
18941904

18951905
// Watch for changes to the previous coinbase transaction.
18961906
static uint256 hashPrevBestCoinBase;
18971907
GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase);
18981908
hashPrevBestCoinBase = block.vtx[0].GetHash();
18991909

1900-
int64_t nTime4 = GetTimeMicros(); nTimeCallbacks += nTime4 - nTime3;
1901-
LogPrint("bench", " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime4 - nTime3), nTimeCallbacks * 0.000001);
1910+
int64_t nTime6 = GetTimeMicros(); nTimeCallbacks += nTime6 - nTime5;
1911+
LogPrint("bench", " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001);
19021912

19031913
return true;
19041914
}

0 commit comments

Comments
 (0)