Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarking for custom transactions #1571

Merged
merged 6 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const CLogCategoryDesc LogCategories[] =
{BCLog::FUTURESWAP, "futureswap"},
{BCLog::TOKENSPLIT, "tokensplit"},
{BCLog::RPCCACHE, "rpccache"},
{BCLog::CUSTOMTXBENCH, "customtxbench"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
};
Expand Down
1 change: 1 addition & 0 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace BCLog {
FUTURESWAP = (1 << 27),
TOKENSPLIT = (1 << 28),
RPCCACHE = (1 << 29),
CUSTOMTXBENCH = (1 << 30),
// Note: We're almost hitting 32 bit threshold.
ALL = ~(uint32_t)0,
};
Expand Down
13 changes: 13 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,17 @@ bool StopOrInterruptConnect(const CBlockIndex *pIndex, CValidationState& state)
return false;
}

static void LogApplyCustomTx(const CTransaction &tx, const int64_t start) {
// Only log once for one of the following categories. Log BENCH first for consistent formatting.
if (LogAcceptCategory(BCLog::BENCH)) {
std::vector<unsigned char> metadata;
LogPrint(BCLog::BENCH, " - ApplyCustomTx: %s Type: %s Time: %.2fms\n", tx.GetHash().ToString(), ToString(GuessCustomTxType(tx, metadata, false)), (GetTimeMicros() - start) * MILLI);
} else if (LogAcceptCategory(BCLog::CUSTOMTXBENCH)) {
std::vector<unsigned char> metadata;
LogPrint(BCLog::CUSTOMTXBENCH, "Bench::ApplyCustomTx: %s Type: %s Time: %.2fms\n", tx.GetHash().ToString(), ToString(GuessCustomTxType(tx, metadata, false)), (GetTimeMicros() - start) * MILLI);
}
}

/** Apply the effects of this block (with given index) on the UTXO set represented by coins.
* Validity checks that depend on the UTXO set are also done; ConnectBlock ()
* can fail if those validity checks fail (among other reasons). */
Expand Down Expand Up @@ -2878,7 +2889,9 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
}

CHistoryWriters writers{paccountHistoryDB.get(), pburnHistoryDB.get(), pvaultHistoryDB.get()};
const auto applyCustomTxTime = GetTimeMicros();
const auto res = ApplyCustomTx(accountsView, view, tx, chainparams.GetConsensus(), pindex->nHeight, pindex->GetBlockTime(), nullptr, i, &writers);
LogApplyCustomTx(tx, applyCustomTxTime);
if (!res.ok && (res.code & CustomTxErrCodes::Fatal)) {
if (pindex->nHeight >= chainparams.GetConsensus().EunosHeight) {
return state.Invalid(ValidationInvalidReason::CONSENSUS,
Expand Down