Skip to content

Commit a473eff

Browse files
committed
[bench] Replace 0.00(000)1 with MICRO/MILLI #defines in validation.cpp.
1 parent 5f850b0 commit a473eff

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/validation.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
# error "Bitcoin cannot be compiled without assertions."
5252
#endif
5353

54+
#define MICRO 0.000001
55+
#define MILLI 0.001
56+
5457
/**
5558
* Global state
5659
*/
@@ -1552,7 +1555,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15521555
}
15531556

15541557
int64_t nTime1 = GetTimeMicros(); nTimeCheck += nTime1 - nTimeStart;
1555-
LogPrint(BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime1 - nTimeStart), nTimeCheck * 0.000001, nTimeCheck * 0.001 / nBlocksTotal);
1558+
LogPrint(BCLog::BENCH, " - Sanity checks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime1 - nTimeStart), nTimeCheck * MICRO, nTimeCheck * MILLI / nBlocksTotal);
15561559

15571560
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
15581561
// unless those are already completely spent.
@@ -1619,7 +1622,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16191622
}
16201623

16211624
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
1622-
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001, nTimeForks * 0.001 / nBlocksTotal);
1625+
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime2 - nTime1), nTimeForks * MICRO, nTimeForks * MILLI / nBlocksTotal);
16231626

16241627
CBlockUndo blockundo;
16251628

@@ -1693,7 +1696,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16931696
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
16941697
}
16951698
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
1696-
LogPrint(BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\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, nTimeConnect * 0.001 / nBlocksTotal);
1699+
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);
16971700

16981701
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
16991702
if (block.vtx[0]->GetValueOut() > blockReward)
@@ -1705,7 +1708,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
17051708
if (!control.Wait())
17061709
return state.DoS(100, error("%s: CheckQueue failed", __func__), REJECT_INVALID, "block-validation-failed");
17071710
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime2;
1708-
LogPrint(BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk)]\n", nInputs - 1, 0.001 * (nTime4 - nTime2), nInputs <= 1 ? 0 : 0.001 * (nTime4 - nTime2) / (nInputs-1), nTimeVerify * 0.000001, nTimeVerify * 0.001 / nBlocksTotal);
1711+
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);
17091712

17101713
if (fJustCheck)
17111714
return true;
@@ -1737,10 +1740,10 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
17371740
view.SetBestBlock(pindex->GetBlockHash());
17381741

17391742
int64_t nTime5 = GetTimeMicros(); nTimeIndex += nTime5 - nTime4;
1740-
LogPrint(BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001, nTimeIndex * 0.001 / nBlocksTotal);
1743+
LogPrint(BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime5 - nTime4), nTimeIndex * MICRO, nTimeIndex * MILLI / nBlocksTotal);
17411744

17421745
int64_t nTime6 = GetTimeMicros(); nTimeCallbacks += nTime6 - nTime5;
1743-
LogPrint(BCLog::BENCH, " - Callbacks: %.2fms [%.2fs (%.2fms/blk)]\n", 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001, nTimeCallbacks * 0.001 / nBlocksTotal);
1746+
LogPrint(BCLog::BENCH, " - Callbacks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime6 - nTime5), nTimeCallbacks * MICRO, nTimeCallbacks * MILLI / nBlocksTotal);
17441747

17451748
return true;
17461749
}
@@ -1959,7 +1962,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
19591962
bool flushed = view.Flush();
19601963
assert(flushed);
19611964
}
1962-
LogPrint(BCLog::BENCH, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
1965+
LogPrint(BCLog::BENCH, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * MILLI);
19631966
// Write the chain state to disk, if necessary.
19641967
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
19651968
return false;
@@ -2080,7 +2083,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
20802083
// Apply the block atomically to the chain state.
20812084
int64_t nTime2 = GetTimeMicros(); nTimeReadFromDisk += nTime2 - nTime1;
20822085
int64_t nTime3;
2083-
LogPrint(BCLog::BENCH, " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001);
2086+
LogPrint(BCLog::BENCH, " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * MILLI, nTimeReadFromDisk * MICRO);
20842087
{
20852088
CCoinsViewCache view(pcoinsTip);
20862089
bool rv = ConnectBlock(blockConnecting, state, pindexNew, view, chainparams);
@@ -2091,26 +2094,26 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
20912094
return error("ConnectTip(): ConnectBlock %s failed", pindexNew->GetBlockHash().ToString());
20922095
}
20932096
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
2094-
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001, nTimeConnectTotal * 0.001 / nBlocksTotal);
2097+
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime3 - nTime2) * MILLI, nTimeConnectTotal * MICRO, nTimeConnectTotal * MILLI / nBlocksTotal);
20952098
bool flushed = view.Flush();
20962099
assert(flushed);
20972100
}
20982101
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
2099-
LogPrint(BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001, nTimeFlush * 0.001 / nBlocksTotal);
2102+
LogPrint(BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime4 - nTime3) * MILLI, nTimeFlush * MICRO, nTimeFlush * MILLI / nBlocksTotal);
21002103
// Write the chain state to disk, if necessary.
21012104
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
21022105
return false;
21032106
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
2104-
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001, nTimeChainState * 0.001 / nBlocksTotal);
2107+
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * MILLI, nTimeChainState * MICRO, nTimeChainState * MILLI / nBlocksTotal);
21052108
// Remove conflicting transactions from the mempool.;
21062109
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight);
21072110
disconnectpool.removeForBlock(blockConnecting.vtx);
21082111
// Update chainActive & related variables.
21092112
UpdateTip(pindexNew, chainparams);
21102113

21112114
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
2112-
LogPrint(BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001, nTimePostConnect * 0.001 / nBlocksTotal);
2113-
LogPrint(BCLog::BENCH, "- Connect block: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001, nTimeTotal * 0.001 / nBlocksTotal);
2115+
LogPrint(BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal);
2116+
LogPrint(BCLog::BENCH, "- Connect block: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime1) * MILLI, nTimeTotal * MICRO, nTimeTotal * MILLI / nBlocksTotal);
21142117

21152118
connectTrace.BlockConnected(pindexNew, std::move(pthisBlock));
21162119
return true;
@@ -4123,7 +4126,7 @@ void DumpMempool(void)
41234126
file.fclose();
41244127
RenameOver(GetDataDir() / "mempool.dat.new", GetDataDir() / "mempool.dat");
41254128
int64_t last = GetTimeMicros();
4126-
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*0.000001, (last-mid)*0.000001);
4129+
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO);
41274130
} catch (const std::exception& e) {
41284131
LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what());
41294132
}

0 commit comments

Comments
 (0)