Skip to content

Commit

Permalink
[validation]: log received block percentile fee rates
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelsadeeq committed Jul 11, 2024
1 parent 778f545 commit 5e2faa8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/kernel/mempool_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ struct RemovedMempoolTransactionInfo {
TransactionInfo info;
explicit RemovedMempoolTransactionInfo(const CTxMemPoolEntry& entry)
: info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {}

explicit RemovedMempoolTransactionInfo(const CTransactionRef& tx, const CAmount& fee, const int64_t vsize, const unsigned int height)
: info(tx, fee, vsize, height) {}
};

struct NewMempoolTransactionInfo {
Expand Down
29 changes: 27 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <logging/timer.h>
#include <node/blockstorage.h>
#include <node/utxo_snapshot.h>
#include <policy/fees_util.h>
#include <policy/policy.h>
#include <policy/rbf.h>
#include <policy/settings.h>
Expand Down Expand Up @@ -2617,15 +2618,16 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
int nInputs = 0;
int64_t nSigOpsCost = 0;
blockundo.vtxundo.reserve(block.vtx.size() - 1);
std::vector<RemovedMempoolTransactionInfo> block_txs;
for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const CTransaction &tx = *(block.vtx[i]);

nInputs += tx.vin.size();

CAmount txfee = 0;
if (!tx.IsCoinBase())
{
CAmount txfee = 0;
TxValidationState tx_state;
if (!Consensus::CheckTxInputs(tx, tx_state, view, pindex->nHeight, txfee)) {
// Any transaction validation failure in ConnectBlock is a block consensus failure
Expand Down Expand Up @@ -2658,7 +2660,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
// * legacy (always)
// * p2sh (when P2SH enabled in flags and excludes coinbase)
// * witness (when witness enabled in flags and excludes coinbase)
nSigOpsCost += GetTransactionSigOpCost(tx, view, flags);
int64_t txSigOpCost = GetTransactionSigOpCost(tx, view, flags);
nSigOpsCost += txSigOpCost;
if (nSigOpsCost > MAX_BLOCK_SIGOPS_COST) {
LogPrintf("ERROR: ConnectBlock(): too many sigops\n");
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blk-sigops");
Expand All @@ -2678,6 +2681,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
return false;
}
control.Add(std::move(vChecks));
int64_t txVsize = GetVirtualTransactionSize(GetTransactionWeight(tx), txSigOpCost, nBytesPerSigOp);
auto tx_info = RemovedMempoolTransactionInfo(block.vtx[i], txfee, txVsize, /*height=*/0);
block_txs.push_back(tx_info);
}

CTxUndo undoDummy;
Expand All @@ -2686,6 +2692,25 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
}
UpdateCoins(tx, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight);
}

auto linearizedTxs = LinearizeTransactions(block_txs);
const auto size_per_feerate = linearizedTxs.size_per_feerate;
if (size_per_feerate.size() > 0) {
auto block_percentiles = CalculateBlockPercentiles(size_per_feerate);
CAmount lowest_fee_rate = std::get<0>(size_per_feerate[size_per_feerate.size() - 1]).GetFeePerK();
CAmount highest_fee_rate = std::get<0>(size_per_feerate[0]).GetFeePerK();
LogInfo("Connected Block: %s, %s, %s, %s, %s, %s, %s, %s\n",
pindex->GetBlockHash().ToString(), pindex->nHeight, highest_fee_rate, block_percentiles.p75.GetFeePerK(), block_percentiles.p50.GetFeePerK(), block_percentiles.p25.GetFeePerK(), block_percentiles.p5.GetFeePerK(), lowest_fee_rate);
TRACE8(validation, block_connected_fees,
block_hash.data(),
pindex->nHeight,
highest_fee_rate,
block_percentiles.p75.GetFeePerK(),
block_percentiles.p50.GetFeePerK(),
block_percentiles.p25.GetFeePerK(),
block_percentiles.p5.GetFeePerK(),
lowest_fee_rate);
}
const auto time_3{SteadyClock::now()};
time_connect += time_3 - time_2;
LogPrint(BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\n", (unsigned)block.vtx.size(),
Expand Down

0 comments on commit 5e2faa8

Please sign in to comment.