Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/blockchain/fork_choice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,14 @@ namespace lean {

// Sign proposer attestation
auto payload = sszHash(proposer_attestation);
auto timer =
metrics_->crypto_pq_signature_attestation_signing_time_seconds()
->timer();
crypto::xmss::XmssSignature signature = xmss_provider_->sign(
validator_keys_manifest_->currentNodeXmssKeypair().private_key,
slot,
payload);
timer.stop();
SignedBlockWithAttestation signed_block_with_attestation{
.message =
{
Expand Down Expand Up @@ -459,8 +463,15 @@ namespace lean {
// - The signature was created at the correct epoch (slot)
auto message = sszHash(attestation);
Epoch epoch = attestation.data.slot;
if (not xmss_provider_->verify(
validator.pubkey, message, epoch, signature)) {

auto timer =
metrics_->crypto_pq_signature_attestation_verification_time_seconds()
->timer();
bool verify_result =
xmss_provider_->verify(validator.pubkey, message, epoch, signature);
timer.stop();

if (not verify_result) {
SL_WARN(logger_,
"Attestation signature verification failed for validator {}",
validator_id);
Expand Down Expand Up @@ -633,8 +644,12 @@ namespace lean {
auto payload = sszHash(attestation);
crypto::xmss::XmssKeypair keypair =
validator_keys_manifest_->currentNodeXmssKeypair();
auto timer =
metrics_->crypto_pq_signature_attestation_signing_time_seconds()
->timer();
crypto::xmss::XmssSignature signature =
xmss_provider_->sign(keypair.private_key, current_slot, payload);
timer.stop();
SignedAttestation signed_attestation{.message = attestation,
.signature = signature};

Expand Down
49 changes: 49 additions & 0 deletions src/crypto/crypto_metrics.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @brief Cryptography metrics definitions
*
* Format:
* METRIC_GAUGE(field_name,
* "prometheus_metric_name",
* "help_text")
*
* METRIC_GAUGE_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* METRIC_COUNTER(field_name,
* "prometheus_metric_name",
* "help_text")
*
* METRIC_COUNTER_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* METRIC_HISTOGRAM(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...})
*
* METRIC_HISTOGRAM_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...},
* {"label1", "label2", ...})
*/

// PQ signatures
METRIC_HISTOGRAM(crypto_pq_signature_attestation_signing_time_seconds,
"lean_pq_signature_attestation_signing_time_seconds",
"Time taken to sign an attestation",
(0.005, 0.01, 0.025, 0.05, 0.1, 1))
METRIC_HISTOGRAM(crypto_pq_signature_attestation_verification_time_seconds,
"lean_pq_signature_attestation_verification_time_seconds",
"Time taken to verify an attestation signature",
(0.005, 0.01, 0.025, 0.05, 0.1, 1))
1 change: 1 addition & 0 deletions src/metrics/all_metrics.def
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#include "blockchain/fork_choice_metrics.def"
#include "blockchain/impl/validator_metrics.def"
#include "blockchain/state_transition_metrics.def"
#include "crypto/crypto_metrics.def"
35 changes: 24 additions & 11 deletions src/metrics/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ namespace lean::metrics {
*/
~HistogramTimer() {
if (running_) {
const auto elapsed_time = stop();
if (histogram_) {
histogram_->observe(elapsed_time);
}
stop();
}
}

Expand All @@ -193,10 +190,7 @@ namespace lean::metrics {
HistogramTimer &operator=(HistogramTimer &&other) noexcept {
if (this != &other) {
if (running_) {
const auto elapsed_time = stop();
if (histogram_) {
histogram_->observe(elapsed_time);
}
stop();
}
histogram_ = other.histogram_;
start_time_ = other.start_time_;
Expand All @@ -207,17 +201,36 @@ namespace lean::metrics {
}

/**
* @brief Manually stop the timer
* @brief Stop the timer and record the elapsed time to the histogram
* @return Elapsed time in seconds
*
* After calling stop(), the timer is considered stopped and the destructor
* will not record the time to the histogram.
*/
double stop() {
if (!running_) {
return 0.0;
}

const auto elapsed_time = elapsed();
running_ = false;

// Automatically observe the elapsed time
if (histogram_) {
histogram_->observe(elapsed_time);
}

return elapsed_time;
}

/**
* @brief Stop the timer without recording to the histogram
* @return Elapsed time in seconds
*
*/
double stopWithoutObserving() {
if (!running_) {
return 0.0;
}

const auto elapsed_time = elapsed();
running_ = false;
return elapsed_time;
Expand Down
Loading