metrics: Rework pool metrics in anticipation of transparent pool

notes.created and notes.spent can be collected for the transparent pool
as well as the shielded pools. notes.unspent can only be collected for
the transparent pool, by design.
This commit is contained in:
Jack Grigg 2021-03-14 12:55:31 +13:00
parent 0cab2e7094
commit f8d63a83fc
1 changed files with 34 additions and 8 deletions

View File

@ -3217,7 +3217,9 @@ void PruneAndFlush() {
} }
struct PoolMetrics { struct PoolMetrics {
std::optional<size_t> commitments; std::optional<size_t> created;
std::optional<size_t> spent;
std::optional<size_t> unspent;
std::optional<CAmount> value; std::optional<CAmount> value;
static PoolMetrics Sprout(CBlockIndex *pindex, CCoinsViewCache *view) { static PoolMetrics Sprout(CBlockIndex *pindex, CCoinsViewCache *view) {
@ -3226,7 +3228,7 @@ struct PoolMetrics {
SproutMerkleTree sproutTree; SproutMerkleTree sproutTree;
assert(view->GetSproutAnchorAt(pindex->hashFinalSproutRoot, sproutTree)); assert(view->GetSproutAnchorAt(pindex->hashFinalSproutRoot, sproutTree));
stats.commitments = sproutTree.size(); stats.created = sproutTree.size();
return stats; return stats;
} }
@ -3235,24 +3237,46 @@ struct PoolMetrics {
PoolMetrics stats; PoolMetrics stats;
stats.value = pindex->nChainSaplingValue; stats.value = pindex->nChainSaplingValue;
// Before Sapling activation, stats.commitments will be zero. // Before Sapling activation, the Sapling commitment set is empty.
SaplingMerkleTree saplingTree; SaplingMerkleTree saplingTree;
if (view->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, saplingTree)) { if (view->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, saplingTree)) {
stats.commitments = saplingTree.size(); stats.created = saplingTree.size();
} else { } else {
stats.commitments = 0; stats.created = 0;
} }
return stats; return stats;
} }
static PoolMetrics Transparent(CBlockIndex *pindex, CCoinsViewCache *view) {
PoolMetrics stats;
// TODO: Collect transparent pool value.
// TODO: Figure out a way to efficiently collect UTXO set metrics
// (view->GetStats() is too slow to call during block verification).
return stats;
}
}; };
#define RenderPoolMetrics(poolName, poolMetrics) \ #define RenderPoolMetrics(poolName, poolMetrics) \
do { \ do { \
if (poolMetrics.commitments) { \ if (poolMetrics.created) { \
MetricsStaticGauge( \ MetricsStaticGauge( \
"zcash.pool.commitments", \ "zcash.pool.notes.created", \
poolMetrics.commitments.value(), \ poolMetrics.created.value(), \
"name", poolName); \
} \
if (poolMetrics.spent) { \
MetricsStaticGauge( \
"zcash.pool.notes.spent", \
poolMetrics.spent.value(), \
"name", poolName); \
} \
if (poolMetrics.unspent) { \
MetricsStaticGauge( \
"zcash.pool.notes.unspent", \
poolMetrics.unspent.value(), \
"name", poolName); \ "name", poolName); \
} \ } \
if (poolMetrics.value) { \ if (poolMetrics.value) { \
@ -3292,10 +3316,12 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
auto sproutPool = PoolMetrics::Sprout(pindexNew, pcoinsTip); auto sproutPool = PoolMetrics::Sprout(pindexNew, pcoinsTip);
auto saplingPool = PoolMetrics::Sapling(pindexNew, pcoinsTip); auto saplingPool = PoolMetrics::Sapling(pindexNew, pcoinsTip);
auto transparentPool = PoolMetrics::Transparent(pindexNew, pcoinsTip);
MetricsGauge("zcash.chain.verified.block.height", pindexNew->nHeight); MetricsGauge("zcash.chain.verified.block.height", pindexNew->nHeight);
RenderPoolMetrics("sprout", sproutPool); RenderPoolMetrics("sprout", sproutPool);
RenderPoolMetrics("sapling", saplingPool); RenderPoolMetrics("sapling", saplingPool);
RenderPoolMetrics("transparent", transparentPool);
cvBlockChange.notify_all(); cvBlockChange.notify_all();
} }