1use metrics::{describe_counter, describe_gauge, describe_histogram, Unit};
9
10pub const LABELS: &[(&str, &[&str])] = &[
20 (
21 "zebra.consensus.batch.duration_seconds",
22 &["verifier", "result"],
23 ),
24 ("zebra.consensus.cache.hit", &["verifier"]),
25 ("zebra.consensus.cache.miss", &["verifier"]),
26 ("zebra.consensus.cache.insert", &["verifier"]),
27 ("zebra.consensus.cache.evict", &["verifier"]),
28 ("zebra.consensus.cache.size", &["verifier"]),
29 ("zebra.consensus.block.phase.duration_seconds", &["phase"]),
30];
31
32pub const FAILURE_COUNTERS: &[&str] = &[
40 "signatures.ed25519.invalid",
41 "signatures.redjubjub.invalid",
42 "signatures.redpallas.invalid",
43 "proofs.halo2.invalid",
44 "proofs.sapling.invalid",
45];
46
47pub fn register_failure_counters() {
50 for name in FAILURE_COUNTERS {
51 metrics::counter!(*name).increment(0);
52 }
53}
54
55pub fn describe() {
57 describe_gauge!(
59 "checkpoint.verified.height",
60 Unit::Count,
61 "Height of the latest block verified by the checkpoint verifier."
62 );
63 describe_gauge!(
64 "checkpoint.verified.count",
65 Unit::Count,
66 "Number of checkpoints verified so far."
67 );
68 describe_counter!(
69 "checkpoint.verified.block.count",
70 Unit::Count,
71 "Blocks verified against checkpoints."
72 );
73 describe_gauge!(
74 "checkpoint.processing.next.height",
75 Unit::Count,
76 "Height of the next checkpoint the checkpoint verifier is waiting to reach."
77 );
78 describe_gauge!(
79 "checkpoint.queued.max.height",
80 Unit::Count,
81 "Highest block height queued in the checkpoint verifier, or NaN when none are queued."
82 );
83 describe_gauge!(
84 "checkpoint.queued.continuous.height",
85 Unit::Count,
86 "Height of the end of the continuous run of queued blocks after the verified tip."
87 );
88 describe_gauge!(
89 "checkpoint.queued_slots",
90 Unit::Count,
91 "Number of heights with blocks queued in the checkpoint verifier."
92 );
93 describe_counter!(
94 "checkpoint.waiting.count",
95 Unit::Count,
96 "Times the checkpoint verifier waited for more blocks before it could verify a range."
97 );
98
99 describe_histogram!(
101 "zebra.consensus.block.phase.duration_seconds",
102 Unit::Seconds,
103 "Time each phase of full block verification took, for blocks that aren't block \
104 proposals: the header and structure checks, transaction verification, and the state \
105 commit. The first two phases are recorded when they pass, even if a later phase rejects \
106 the block. The state commit is recorded only for committed blocks, and includes any \
107 wait for the parent block."
108 );
109
110 describe_histogram!(
112 "zebra.consensus.batch.duration_seconds",
113 Unit::Seconds,
114 "Time taken to verify one batch of signatures or proofs."
115 );
116 describe_counter!(
117 "signatures.ed25519.validated",
118 Unit::Count,
119 "Ed25519 signatures that passed batch verification."
120 );
121 describe_counter!(
122 "signatures.ed25519.invalid",
123 Unit::Count,
124 "Ed25519 signatures in batches that failed verification, including valid ones that pass when verified on their own."
125 );
126 describe_counter!(
127 "signatures.redjubjub.validated",
128 Unit::Count,
129 "RedJubjub signatures that passed batch verification. zebrad verifies these signatures with their Sapling bundles, so it leaves this at zero."
130 );
131 describe_counter!(
132 "signatures.redjubjub.invalid",
133 Unit::Count,
134 "RedJubjub signatures in batches that failed verification, including valid ones that pass when verified on their own. zebrad verifies these signatures with their Sapling bundles, so it leaves this at zero."
135 );
136 describe_counter!(
137 "signatures.redpallas.validated",
138 Unit::Count,
139 "RedPallas signatures that passed batch verification. zebrad verifies these signatures with their Orchard bundles, so it leaves this at zero."
140 );
141 describe_counter!(
142 "signatures.redpallas.invalid",
143 Unit::Count,
144 "RedPallas signatures in batches that failed verification, including valid ones that pass when verified on their own. zebrad verifies these signatures with their Orchard bundles, so it leaves this at zero."
145 );
146 describe_counter!(
147 "proofs.halo2.verified",
148 Unit::Count,
149 "Orchard bundles whose Halo2 proofs and signatures passed batch verification."
150 );
151 describe_counter!(
152 "proofs.halo2.invalid",
153 Unit::Count,
154 "Orchard bundles in batches that failed verification, including valid ones that pass when verified on their own."
155 );
156 describe_counter!(
157 "proofs.sapling.verified",
158 Unit::Count,
159 "Sapling bundles whose Groth16 proofs and signatures passed batch verification."
160 );
161 describe_counter!(
162 "proofs.sapling.invalid",
163 Unit::Count,
164 "Sapling bundles in batches that failed verification, including valid ones that pass when verified on their own."
165 );
166
167 describe_counter!(
169 "zebra.consensus.cache.hit",
170 Unit::Count,
171 "Verifications answered from a verification cache."
172 );
173 describe_counter!(
174 "zebra.consensus.cache.miss",
175 Unit::Count,
176 "Verifications that a verification cache passed to its verifier."
177 );
178 describe_counter!(
179 "zebra.consensus.cache.insert",
180 Unit::Count,
181 "Keys recorded as verified in a verification cache."
182 );
183 describe_counter!(
184 "zebra.consensus.cache.evict",
185 Unit::Count,
186 "Keys dropped from a verification cache to stay within its capacity."
187 );
188 describe_gauge!(
189 "zebra.consensus.cache.size",
190 Unit::Count,
191 "Number of keys a verification cache currently remembers."
192 );
193}