Skip to content

Commit 228a95c

Browse files
authored
feat: add signature aggregation counter metrics (#60)
* feat: add PQ aggregation counter metrics * docs: update metrics checklist * docs: update metrics checklist with old metrics
1 parent 740507e commit 228a95c

3 files changed

Lines changed: 78 additions & 8 deletions

File tree

crates/blockchain/src/metrics.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,56 @@ pub fn time_attestation_validation() -> TimingGuard {
150150
});
151151
TimingGuard::new(&LEAN_ATTESTATION_VALIDATION_TIME_SECONDS)
152152
}
153+
154+
/// Increment the PQ aggregated signatures counter.
155+
pub fn inc_pq_sig_aggregated_signatures() {
156+
static LEAN_PQ_SIG_AGGREGATED_SIGNATURES_TOTAL: std::sync::LazyLock<IntCounter> =
157+
std::sync::LazyLock::new(|| {
158+
register_int_counter!(
159+
"lean_pq_sig_aggregated_signatures_total",
160+
"Total number of aggregated signatures"
161+
)
162+
.unwrap()
163+
});
164+
LEAN_PQ_SIG_AGGREGATED_SIGNATURES_TOTAL.inc();
165+
}
166+
167+
/// Increment the attestations in aggregated signatures counter.
168+
pub fn inc_pq_sig_attestations_in_aggregated_signatures(count: u64) {
169+
static LEAN_PQ_SIG_ATTESTATIONS_IN_AGGREGATED_SIGNATURES_TOTAL: std::sync::LazyLock<
170+
IntCounter,
171+
> = std::sync::LazyLock::new(|| {
172+
register_int_counter!(
173+
"lean_pq_sig_attestations_in_aggregated_signatures_total",
174+
"Total number of attestations included into aggregated signatures"
175+
)
176+
.unwrap()
177+
});
178+
LEAN_PQ_SIG_ATTESTATIONS_IN_AGGREGATED_SIGNATURES_TOTAL.inc_by(count);
179+
}
180+
181+
/// Increment the valid aggregated signatures counter.
182+
pub fn inc_pq_sig_aggregated_signatures_valid() {
183+
static LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VALID_TOTAL: std::sync::LazyLock<IntCounter> =
184+
std::sync::LazyLock::new(|| {
185+
register_int_counter!(
186+
"lean_pq_sig_aggregated_signatures_valid_total",
187+
"Total number of valid aggregated signatures"
188+
)
189+
.unwrap()
190+
});
191+
LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VALID_TOTAL.inc();
192+
}
193+
194+
/// Increment the invalid aggregated signatures counter.
195+
pub fn inc_pq_sig_aggregated_signatures_invalid() {
196+
static LEAN_PQ_SIG_AGGREGATED_SIGNATURES_INVALID_TOTAL: std::sync::LazyLock<IntCounter> =
197+
std::sync::LazyLock::new(|| {
198+
register_int_counter!(
199+
"lean_pq_sig_aggregated_signatures_invalid_total",
200+
"Total number of invalid aggregated signatures"
201+
)
202+
.unwrap()
203+
});
204+
LEAN_PQ_SIG_AGGREGATED_SIGNATURES_INVALID_TOTAL.inc();
205+
}

crates/blockchain/src/store.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,9 @@ fn compute_aggregated_signatures(
875875
};
876876
let aggregate_proof = AggregatedSignatureProof::new(participants, proof_data);
877877
results.push((aggregated_attestation, aggregate_proof));
878+
879+
metrics::inc_pq_sig_aggregated_signatures();
880+
metrics::inc_pq_sig_attestations_in_aggregated_signatures(gossip_ids.len() as u64);
878881
}
879882

880883
// Phase 2: Fallback to existing proofs
@@ -910,6 +913,10 @@ fn compute_aggregated_signatures(
910913
data: data.clone(),
911914
};
912915
results.push((aggregate, proof.clone()));
916+
917+
metrics::inc_pq_sig_aggregated_signatures();
918+
metrics::inc_pq_sig_attestations_in_aggregated_signatures(covered.len() as u64);
919+
913920
for vid in covered {
914921
remaining.remove(&vid);
915922
}
@@ -962,8 +969,18 @@ fn verify_signatures(
962969
})
963970
.collect::<Result<_, _>>()?;
964971

965-
verify_aggregated_signature(&aggregated_proof.proof_data, public_keys, &message, epoch)
966-
.map_err(StoreError::AggregateVerificationFailed)?;
972+
match verify_aggregated_signature(
973+
&aggregated_proof.proof_data,
974+
public_keys,
975+
&message,
976+
epoch,
977+
) {
978+
Ok(()) => metrics::inc_pq_sig_aggregated_signatures_valid(),
979+
Err(e) => {
980+
metrics::inc_pq_sig_aggregated_signatures_invalid();
981+
return Err(StoreError::AggregateVerificationFailed(e));
982+
}
983+
}
967984
}
968985

969986
let proposer_attestation = &signed_block.message.proposer_attestation;

docs/metrics.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ The exposed metrics follow [the leanMetrics specification](https://github.com/le
2020
|--------|-------|-------|-------------------------|--------|---------|-----------|
2121
| `lean_pq_sig_attestation_signing_time_seconds` | Histogram | Time taken to sign an attestation | On each attestation signing | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 ||
2222
| `lean_pq_sig_attestation_verification_time_seconds` | Histogram | Time taken to verify an attestation signature | On each `signature.verify()` on an attestation | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 ||
23-
| `lean_pq_sig_aggregated_signatures_total` | Counter | Total number of aggregated signatures | On `build_attestation_signatures()` | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
24-
| `lean_pq_sig_attestations_in_aggregated_signatures_total` | Counter | Total number of attestations included into aggregated signatures | On `build_attestation_signatures()` | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
23+
| `lean_pq_sig_aggregated_signatures_total` | Counter | Total number of aggregated signatures | On `build_attestation_signatures()` | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
24+
| `lean_pq_sig_attestations_in_aggregated_signatures_total` | Counter | Total number of attestations included into aggregated signatures | On `build_attestation_signatures()` | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
2525
| `lean_pq_sig_attestation_signatures_building_time_seconds` | Histogram | Time taken to verify an aggregated attestation signature | On `build_attestation_signatures()` | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 ||
2626
| `lean_pq_sig_aggregated_signatures_verification_time_seconds` | Histogram | Time taken to verify an aggregated attestation signature | On validate aggregated signature | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 ||
27-
| `lean_pq_sig_aggregated_signatures_valid_total`| Counter | Total number of valid aggregated signatures | On validate aggregated signature | | | |
28-
| `lean_pq_sig_aggregated_signatures_invalid_total`| Counter | Total number of invalid aggregated signatures | On validate aggregated signature | | | |
27+
| `lean_pq_sig_aggregated_signatures_valid_total`| Counter | Total number of valid aggregated signatures | On validate aggregated signature | | | |
28+
| `lean_pq_sig_aggregated_signatures_invalid_total`| Counter | Total number of invalid aggregated signatures | On validate aggregated signature | | | |
2929

3030
## Fork-Choice Metrics
3131

@@ -34,10 +34,10 @@ The exposed metrics follow [the leanMetrics specification](https://github.com/le
3434
| `lean_head_slot` | Gauge | Latest slot of the lean chain | On get fork choice head | | ||
3535
| `lean_current_slot` | Gauge | Current slot of the lean chain | On scrape | | | ✅(*) |
3636
| `lean_safe_target_slot` | Gauge | Safe target slot | On safe target update | | ||
37-
|`lean_fork_choice_block_processing_time_seconds`| Histogram | Time taken to process block | On fork choice process block | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
37+
|`lean_fork_choice_block_processing_time_seconds`| Histogram | Time taken to process block | On fork choice process block | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
3838
|`lean_attestations_valid_total`| Counter | Total number of valid attestations | On validate attestation | source=block,gossip | ||
3939
|`lean_attestations_invalid_total`| Counter | Total number of invalid attestations | On validate attestation | source=block,gossip | ||
40-
|`lean_attestation_validation_time_seconds`| Histogram | Time taken to validate attestation | On validate attestation | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
40+
|`lean_attestation_validation_time_seconds`| Histogram | Time taken to validate attestation | On validate attestation | | 0.005, 0.01, 0.025, 0.05, 0.1, 1 | |
4141
| `lean_fork_choice_reorgs_total` | Counter | Total number of fork choice reorgs | On fork choice reorg | | ||
4242
| `lean_fork_choice_reorg_depth` | Histogram | Depth of fork choice reorgs (in blocks) | On fork choice reorg | | 1, 2, 3, 5, 7, 10, 20, 30, 50, 100 ||
4343

0 commit comments

Comments
 (0)