Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: proposer test program #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/aggkit-prover-config/tests/validate_deserialize.rs
expression: config
snapshot_kind: text
---
grpc-endpoint = "127.0.0.1:8081"

Expand Down Expand Up @@ -40,6 +39,10 @@ l1-rpc-endpoint = "http://anvil-mock-l1-rpc:8545/"
proposer-endpoint = "http://proposer-mock-rpc:3000/"
sp1-cluster-endpoint = "https://rpc.production.succinct.xyz/"

[aggchain-proof-service.proposer-service.client.request-timeout]
secs = 600
nanos = 0

[aggchain-proof-service.proposer-service.client.proving-timeout]
secs = 3600
nanos = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/aggkit-prover-config/tests/validate_deserialize.rs
expression: config
snapshot_kind: text
---
grpc-endpoint = "127.0.0.1:8081"

Expand Down Expand Up @@ -43,6 +42,10 @@ l1-rpc-endpoint = "http://anvil-mock-l1-rpc:8545/"
proposer-endpoint = "http://proposer-mock-rpc:3000/"
sp1-cluster-endpoint = "https://rpc.production.succinct.xyz/"

[aggchain-proof-service.proposer-service.client.request-timeout]
secs = 600
nanos = 0

[aggchain-proof-service.proposer-service.client.proving-timeout]
secs = 3600
nanos = 0
Expand Down
68 changes: 68 additions & 0 deletions crates/proposer-client/src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::sync::Arc;
use std::time::Duration;

use sp1_sdk::SP1ProofWithPublicValues;

use crate::network_prover::AggSpanProver;
use crate::rpc::{
AggregationProofProposer, AggregationProofProposerRequest, AggregationProofProposerResponse,
};
use crate::{error, Error, ProposerClient, RequestId};

/// Implementation of the proposer client.
/// The Proposer client is responsible for retrieval of the AggregationProof.
/// AggregationProof is the aggregated proof of the multiple
/// block span full execution proofs.
///
/// The proposer client communicates with the proposer API to
/// request creation of the AggSpanProof (getting the proof ID in return),
/// and directly communicates with the SP1 cluster using NetworkProver
/// to retrieve the generated proof.
#[derive(Clone)]
pub struct Client<Proposer, Prover> {
proposer_rpc: Arc<Proposer>,
prover_rpc: Arc<Prover>,
proving_timeout: Option<Duration>,
}

impl<Proposer, Prover> Client<Proposer, Prover>
where
Proposer: AggregationProofProposer,
Prover: AggSpanProver,
{
pub fn new(
proposer: Proposer,
prover: Prover,
timeout: Option<Duration>,
) -> Result<Self, error::Error> {
Ok(Self {
proposer_rpc: Arc::new(proposer),
prover_rpc: Arc::new(prover),
proving_timeout: timeout,
})
}
}

#[async_trait::async_trait]
impl<Proposer, Prover> ProposerClient for Client<Proposer, Prover>
where
Proposer: AggregationProofProposer + Sync + Send,
Prover: AggSpanProver + Sync + Send,
{
async fn request_agg_proof(
&self,
request: AggregationProofProposerRequest,
) -> Result<AggregationProofProposerResponse, Error> {
self.proposer_rpc.request_agg_proof(request).await
}

async fn wait_for_proof(
&self,
request_id: RequestId,
) -> Result<SP1ProofWithPublicValues, Error> {
self.prover_rpc
.wait_for_proof(request_id.0, self.proving_timeout)
.await
.map_err(|e| Error::Proving(request_id, e.to_string()))
}
}
16 changes: 12 additions & 4 deletions crates/proposer-client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ const DEFAULT_SP1_CLUSTER_ENDPOINT: &str = "https://rpc.production.succinct.xyz/
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct ProposerClientConfig {
/// The proposer service http endpoint
/// The proposer service http endpoint.
#[serde(default = "default_proposer_service_endpoint")]
pub proposer_endpoint: Url,
/// The sp1 proving cluster endpoint
/// The sp1 proving cluster endpoint.
#[serde(default = "default_sp1_cluster_endpoint")]
pub sp1_cluster_endpoint: Url,
/// Proving timeout in seconds
/// Proposer request timeout in seconds.
#[serde(default = "default_request_timeout")]
pub request_timeout: Duration,
/// Proving timeout in seconds.
#[serde(default = "default_timeout")]
pub proving_timeout: Duration,
}
Expand All @@ -30,6 +33,7 @@ impl Default for ProposerClientConfig {
Self {
proposer_endpoint: default_proposer_service_endpoint(),
sp1_cluster_endpoint: default_sp1_cluster_endpoint(),
request_timeout: default_request_timeout(),
proving_timeout: default_timeout(),
}
}
Expand All @@ -49,6 +53,10 @@ fn default_sp1_cluster_endpoint() -> Url {
)
}

fn default_timeout() -> Duration {
pub fn default_request_timeout() -> Duration {
Duration::from_secs(600)
}

pub fn default_timeout() -> Duration {
Duration::from_secs(3600)
}
18 changes: 9 additions & 9 deletions crates/proposer-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ProofId;
use crate::RequestId;

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand All @@ -11,15 +11,15 @@ pub enum Error {
#[error("Reqwest http error: {0}")]
Reqwest(#[from] reqwest::Error),

#[error("Invalid proof_id: {0:?}")]
InvalidProofId(String),
#[error("Invalid request_id: {0:?}")]
InvalidRequestId(String),

#[error("Proof request with proof_id: {0} timeout")]
Timeout(ProofId),
#[error("Proof request with request_id: {0} timeout")]
Timeout(RequestId),

#[error("Proof request with proof_id: {0} is unfulfillable")]
ProofRequestUnfulfillable(ProofId),
#[error("Proof request with request_id: {0} is unfulfillable")]
ProofRequestUnfulfillable(RequestId),

#[error("Proof request with proof_id {0} error: {1:?}")]
Proving(ProofId, String),
#[error("Proof request with request_id {0} error: {1:?}")]
Proving(RequestId, String),
}
73 changes: 9 additions & 64 deletions crates/proposer-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use std::fmt::Display;
use std::sync::Arc;
use std::time::Duration;

use alloy_primitives::B256;
use serde::{Deserialize, Serialize};
use sp1_sdk::SP1ProofWithPublicValues;

pub use crate::error::Error;
use crate::network_prover::AggSpanProver;
use crate::rpc::{AggSpanProofProposer, AggSpanProofProposerRequest, AggSpanProofProposerResponse};
use crate::rpc::{AggregationProofProposerRequest, AggregationProofProposerResponse};
pub mod config;
pub mod error;
pub mod network_prover;
pub mod rpc;

pub mod client;
#[cfg(test)]
mod tests;

Expand All @@ -22,66 +20,13 @@ mod tests;
pub trait ProposerClient {
async fn request_agg_proof(
&self,
request: AggSpanProofProposerRequest,
) -> Result<AggSpanProofProposerResponse, Error>;
request: AggregationProofProposerRequest,
) -> Result<AggregationProofProposerResponse, Error>;

async fn wait_for_proof(&self, proof_id: ProofId) -> Result<SP1ProofWithPublicValues, Error>;
}

/// The Proposer client is responsible for retrieval of the AggSpanProof.
/// AggSpanProof is the aggregated proof of the multiple
/// block span full execution proofs.
///
/// The proposer client communicates with the proposer API to
/// request creation of the AggSpanProof (getting the proof ID in return),
/// and directly communicates with the SP1 cluster using NetworkProver
/// to retrieve the generated proof.
#[derive(Clone)]
pub struct Client<Proposer, Prover> {
proposer_rpc: Arc<Proposer>,
prover_rpc: Arc<Prover>,
proving_timeout: Option<Duration>,
}

impl<Proposer, Prover> Client<Proposer, Prover>
where
Proposer: AggSpanProofProposer,
Prover: AggSpanProver,
{
pub fn new(
proposer: Proposer,
prover: Prover,
timeout: Option<Duration>,
) -> Result<Self, error::Error> {
Ok(Self {
proposer_rpc: Arc::new(proposer),
prover_rpc: Arc::new(prover),
proving_timeout: timeout,
})
}
}

#[async_trait::async_trait]
impl<Proposer, Prover> ProposerClient for Client<Proposer, Prover>
where
Proposer: AggSpanProofProposer + Sync + Send,
Prover: AggSpanProver + Sync + Send,
{
async fn request_agg_proof(
async fn wait_for_proof(
&self,
request: AggSpanProofProposerRequest,
) -> Result<AggSpanProofProposerResponse, Error> {
self.proposer_rpc.request_agg_proof(request).await
}

async fn wait_for_proof(&self, proof_id: ProofId) -> Result<SP1ProofWithPublicValues, Error> {
let request_id = proof_id.0;

self.prover_rpc
.wait_for_proof(request_id, self.proving_timeout)
.await
.map_err(|e| Error::Proving(proof_id, e.to_string()))
}
request_id: RequestId,
) -> Result<SP1ProofWithPublicValues, Error>;
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand All @@ -99,9 +44,9 @@ pub struct FepProposerResponse {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ProofId(pub B256);
pub struct RequestId(pub B256);

impl Display for ProofId {
impl Display for RequestId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", hex::encode(self.0))
}
Expand Down
Loading
Loading