From f8d63a83fc4b649bf22ee9bd93103fc562d807bf Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 14 Mar 2021 12:55:31 +1300 Subject: [PATCH] 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. --- src/main.cpp | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a8d0d360c..2f19c88d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3217,7 +3217,9 @@ void PruneAndFlush() { } struct PoolMetrics { - std::optional commitments; + std::optional created; + std::optional spent; + std::optional unspent; std::optional value; static PoolMetrics Sprout(CBlockIndex *pindex, CCoinsViewCache *view) { @@ -3226,7 +3228,7 @@ struct PoolMetrics { SproutMerkleTree sproutTree; assert(view->GetSproutAnchorAt(pindex->hashFinalSproutRoot, sproutTree)); - stats.commitments = sproutTree.size(); + stats.created = sproutTree.size(); return stats; } @@ -3235,24 +3237,46 @@ struct PoolMetrics { PoolMetrics stats; stats.value = pindex->nChainSaplingValue; - // Before Sapling activation, stats.commitments will be zero. + // Before Sapling activation, the Sapling commitment set is empty. SaplingMerkleTree saplingTree; if (view->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, saplingTree)) { - stats.commitments = saplingTree.size(); + stats.created = saplingTree.size(); } else { - stats.commitments = 0; + stats.created = 0; } 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) \ do { \ - if (poolMetrics.commitments) { \ + if (poolMetrics.created) { \ MetricsStaticGauge( \ - "zcash.pool.commitments", \ - poolMetrics.commitments.value(), \ + "zcash.pool.notes.created", \ + 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); \ } \ if (poolMetrics.value) { \ @@ -3292,10 +3316,12 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) { auto sproutPool = PoolMetrics::Sprout(pindexNew, pcoinsTip); auto saplingPool = PoolMetrics::Sapling(pindexNew, pcoinsTip); + auto transparentPool = PoolMetrics::Transparent(pindexNew, pcoinsTip); MetricsGauge("zcash.chain.verified.block.height", pindexNew->nHeight); RenderPoolMetrics("sprout", sproutPool); RenderPoolMetrics("sapling", saplingPool); + RenderPoolMetrics("transparent", transparentPool); cvBlockChange.notify_all(); }