Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions crates/adapters/sp1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ native = [
"sov-metrics?/native",
"sov-sp1-adapter/native",
]
metrics = ["sov-metrics"]
bench = [
"sov-metrics/sp1",
"sov-sp1-adapter/bench",
Expand Down
61 changes: 60 additions & 1 deletion crates/adapters/sp1/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@ use sp1_sdk::prover::{ProveRequest, Prover};
use sp1_sdk::HashableKey;
use sp1_sdk::{NetworkProver, ProverClient, ProvingKey, SP1ProvingKey, SP1Stdin};

#[cfg(feature = "metrics")]
mod metrics {
use std::io::Write;

use sov_metrics::Metric;

/// Metrics emitted when the SP1 proving network fulfills a proof request.
#[derive(Debug)]
pub(super) struct SP1ProofFulfillmentMetrics {
Comment thread
bkolad marked this conversation as resolved.
Outdated
/// The hex-encoded proof request ID.
pub request_id: String,
/// Time from proof request creation to fulfillment, in seconds, as reported by the SP1
/// network.
pub fulfillment_duration_secs: u64,
}

impl Metric for SP1ProofFulfillmentMetrics {
fn measurement_name(&self) -> &'static str {
"sov_rollup_sp1_proof_fulfillment"
}

fn serialize_for_telegraf(&self, buffer: &mut Vec<u8>) -> std::io::Result<()> {
write!(
buffer,
"{} request_id=\"{}\",fulfillment_duration_secs={}i",
self.measurement_name(),
self.request_id,
self.fulfillment_duration_secs,
)
}
}
}

/// Re-export of the proof handle type used by the SP1 network.
pub type ProofHandle = B256;

Expand Down Expand Up @@ -38,6 +71,27 @@ impl SP1Network {
}
}

#[cfg(feature = "metrics")]
Comment thread
bkolad marked this conversation as resolved.
Outdated
impl SP1Network {
async fn emit_fulfillment_metric(&self, request_id: B256) {
let proof_request = match self.prover.get_proof_request(request_id).await {
Ok(Some(req)) => req,
// Best-effort: silently skip metric if request details are unavailable.
Ok(None) | Err(_) => return,
};

if let Some(fulfilled_at) = proof_request.fulfilled_at {
let fulfillment_duration_secs = fulfilled_at - proof_request.created_at;
sov_metrics::track_metrics(|tracker| {
tracker.submit(metrics::SP1ProofFulfillmentMetrics {
request_id: format!("{request_id}"),
fulfillment_duration_secs,
});
});
}
}
}

impl ZkvmNetwork for SP1Network {
type Guest = SP1Guest;
type ProofHandle = ProofHandle;
Expand Down Expand Up @@ -68,7 +122,12 @@ impl ZkvmNetwork for SP1Network {
}

match maybe_proof {
Some(proof) => Ok(Some(bincode::serialize(&proof)?)),
Some(proof) => {
#[cfg(feature = "metrics")]
self.emit_fulfillment_metric(*handle).await;

Ok(Some(bincode::serialize(&proof)?))
}
None => Ok(None),
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-rollup/sov-soak-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sov-address = { workspace = true }
demo-stf = { workspace = true, features = ["native", "arbitrary"] }
sov-soak-testing-lib = { workspace = true }
sov-db = { workspace = true }
sov-sp1-adapter = { workspace = true, features = ["native", "arbitrary"] }
sov-sp1-adapter = { workspace = true, features = ["native", "arbitrary", "metrics"] }
sov-stf-runner = { workspace = true }
sp1 = { path = "../provers/sp1" }

Expand Down
Loading