Skip to content

Commit 4a10b20

Browse files
committed
feat: proposer test program
1 parent abd6a3f commit 4a10b20

13 files changed

+313
-153
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/aggkit-prover-config/tests/snapshots/validate_deserialize__empty_rpcs.snap

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/aggkit-prover-config/tests/validate_deserialize.rs
33
expression: config
4-
snapshot_kind: text
54
---
65
grpc-endpoint = "127.0.0.1:8081"
76

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

42+
[aggchain-proof-service.proposer-service.client.request-timeout]
43+
secs = 600
44+
nanos = 0
45+
4346
[aggchain-proof-service.proposer-service.client.proving-timeout]
4447
secs = 3600
4548
nanos = 0

crates/aggkit-prover-config/tests/snapshots/validate_deserialize__prover_grpc_max_decoding_message_size.snap

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/aggkit-prover-config/tests/validate_deserialize.rs
33
expression: config
4-
snapshot_kind: text
54
---
65
grpc-endpoint = "127.0.0.1:8081"
76

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

45+
[aggchain-proof-service.proposer-service.client.request-timeout]
46+
secs = 600
47+
nanos = 0
48+
4649
[aggchain-proof-service.proposer-service.client.proving-timeout]
4750
secs = 3600
4851
nanos = 0

crates/proposer-client/src/client.rs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use std::sync::Arc;
2+
use std::time::Duration;
3+
4+
use sp1_sdk::SP1ProofWithPublicValues;
5+
6+
use crate::network_prover::AggSpanProver;
7+
use crate::rpc::{
8+
AggregationProofProposer, AggregationProofProposerRequest, AggregationProofProposerResponse,
9+
};
10+
use crate::{error, Error, ProposerClient, RequestId};
11+
12+
/// Implementation of the proposer client.
13+
/// The Proposer client is responsible for retrieval of the AggregationProof.
14+
/// AggregationProof is the aggregated proof of the multiple
15+
/// block span full execution proofs.
16+
///
17+
/// The proposer client communicates with the proposer API to
18+
/// request creation of the AggSpanProof (getting the proof ID in return),
19+
/// and directly communicates with the SP1 cluster using NetworkProver
20+
/// to retrieve the generated proof.
21+
#[derive(Clone)]
22+
pub struct Client<Proposer, Prover> {
23+
proposer_rpc: Arc<Proposer>,
24+
prover_rpc: Arc<Prover>,
25+
proving_timeout: Option<Duration>,
26+
}
27+
28+
impl<Proposer, Prover> Client<Proposer, Prover>
29+
where
30+
Proposer: AggregationProofProposer,
31+
Prover: AggSpanProver,
32+
{
33+
pub fn new(
34+
proposer: Proposer,
35+
prover: Prover,
36+
timeout: Option<Duration>,
37+
) -> Result<Self, error::Error> {
38+
Ok(Self {
39+
proposer_rpc: Arc::new(proposer),
40+
prover_rpc: Arc::new(prover),
41+
proving_timeout: timeout,
42+
})
43+
}
44+
}
45+
46+
#[async_trait::async_trait]
47+
impl<Proposer, Prover> ProposerClient for Client<Proposer, Prover>
48+
where
49+
Proposer: AggregationProofProposer + Sync + Send,
50+
Prover: AggSpanProver + Sync + Send,
51+
{
52+
async fn request_agg_proof(
53+
&self,
54+
request: AggregationProofProposerRequest,
55+
) -> Result<AggregationProofProposerResponse, Error> {
56+
self.proposer_rpc.request_agg_proof(request).await
57+
}
58+
59+
async fn wait_for_proof(
60+
&self,
61+
request_id: RequestId,
62+
) -> Result<SP1ProofWithPublicValues, Error> {
63+
self.prover_rpc
64+
.wait_for_proof(request_id.0, self.proving_timeout)
65+
.await
66+
.map_err(|e| Error::Proving(request_id, e.to_string()))
67+
}
68+
}

crates/proposer-client/src/config.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ const DEFAULT_SP1_CLUSTER_ENDPOINT: &str = "https://rpc.production.succinct.xyz/
1414
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
1515
#[serde(rename_all = "kebab-case")]
1616
pub struct ProposerClientConfig {
17-
/// The proposer service http endpoint
17+
/// The proposer service http endpoint.
1818
#[serde(default = "default_proposer_service_endpoint")]
1919
pub proposer_endpoint: Url,
20-
/// The sp1 proving cluster endpoint
20+
/// The sp1 proving cluster endpoint.
2121
#[serde(default = "default_sp1_cluster_endpoint")]
2222
pub sp1_cluster_endpoint: Url,
23-
/// Proving timeout in seconds
23+
/// Proposer request timeout in seconds.
24+
#[serde(default = "default_request_timeout")]
25+
pub request_timeout: Duration,
26+
/// Proving timeout in seconds.
2427
#[serde(default = "default_timeout")]
2528
pub proving_timeout: Duration,
2629
}
@@ -30,6 +33,7 @@ impl Default for ProposerClientConfig {
3033
Self {
3134
proposer_endpoint: default_proposer_service_endpoint(),
3235
sp1_cluster_endpoint: default_sp1_cluster_endpoint(),
36+
request_timeout: default_request_timeout(),
3337
proving_timeout: default_timeout(),
3438
}
3539
}
@@ -49,6 +53,10 @@ fn default_sp1_cluster_endpoint() -> Url {
4953
)
5054
}
5155

52-
fn default_timeout() -> Duration {
56+
pub fn default_request_timeout() -> Duration {
57+
Duration::from_secs(600)
58+
}
59+
60+
pub fn default_timeout() -> Duration {
5361
Duration::from_secs(3600)
5462
}

crates/proposer-client/src/error.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ProofId;
1+
use crate::RequestId;
22

33
#[derive(Debug, thiserror::Error)]
44
pub enum Error {
@@ -11,15 +11,15 @@ pub enum Error {
1111
#[error("Reqwest http error: {0}")]
1212
Reqwest(#[from] reqwest::Error),
1313

14-
#[error("Invalid proof_id: {0:?}")]
15-
InvalidProofId(String),
14+
#[error("Invalid request_id: {0:?}")]
15+
InvalidRequestId(String),
1616

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

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

23-
#[error("Proof request with proof_id {0} error: {1:?}")]
24-
Proving(ProofId, String),
23+
#[error("Proof request with request_id {0} error: {1:?}")]
24+
Proving(RequestId, String),
2525
}

crates/proposer-client/src/lib.rs

+9-64
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
use std::fmt::Display;
2-
use std::sync::Arc;
3-
use std::time::Duration;
42

53
use alloy_primitives::B256;
64
use serde::{Deserialize, Serialize};
75
use sp1_sdk::SP1ProofWithPublicValues;
86

97
pub use crate::error::Error;
10-
use crate::network_prover::AggSpanProver;
11-
use crate::rpc::{AggSpanProofProposer, AggSpanProofProposerRequest, AggSpanProofProposerResponse};
8+
use crate::rpc::{AggregationProofProposerRequest, AggregationProofProposerResponse};
129
pub mod config;
1310
pub mod error;
1411
pub mod network_prover;
1512
pub mod rpc;
1613

14+
pub mod client;
1715
#[cfg(test)]
1816
mod tests;
1917

@@ -22,66 +20,13 @@ mod tests;
2220
pub trait ProposerClient {
2321
async fn request_agg_proof(
2422
&self,
25-
request: AggSpanProofProposerRequest,
26-
) -> Result<AggSpanProofProposerResponse, Error>;
23+
request: AggregationProofProposerRequest,
24+
) -> Result<AggregationProofProposerResponse, Error>;
2725

28-
async fn wait_for_proof(&self, proof_id: ProofId) -> Result<SP1ProofWithPublicValues, Error>;
29-
}
30-
31-
/// The Proposer client is responsible for retrieval of the AggSpanProof.
32-
/// AggSpanProof is the aggregated proof of the multiple
33-
/// block span full execution proofs.
34-
///
35-
/// The proposer client communicates with the proposer API to
36-
/// request creation of the AggSpanProof (getting the proof ID in return),
37-
/// and directly communicates with the SP1 cluster using NetworkProver
38-
/// to retrieve the generated proof.
39-
#[derive(Clone)]
40-
pub struct Client<Proposer, Prover> {
41-
proposer_rpc: Arc<Proposer>,
42-
prover_rpc: Arc<Prover>,
43-
proving_timeout: Option<Duration>,
44-
}
45-
46-
impl<Proposer, Prover> Client<Proposer, Prover>
47-
where
48-
Proposer: AggSpanProofProposer,
49-
Prover: AggSpanProver,
50-
{
51-
pub fn new(
52-
proposer: Proposer,
53-
prover: Prover,
54-
timeout: Option<Duration>,
55-
) -> Result<Self, error::Error> {
56-
Ok(Self {
57-
proposer_rpc: Arc::new(proposer),
58-
prover_rpc: Arc::new(prover),
59-
proving_timeout: timeout,
60-
})
61-
}
62-
}
63-
64-
#[async_trait::async_trait]
65-
impl<Proposer, Prover> ProposerClient for Client<Proposer, Prover>
66-
where
67-
Proposer: AggSpanProofProposer + Sync + Send,
68-
Prover: AggSpanProver + Sync + Send,
69-
{
70-
async fn request_agg_proof(
26+
async fn wait_for_proof(
7127
&self,
72-
request: AggSpanProofProposerRequest,
73-
) -> Result<AggSpanProofProposerResponse, Error> {
74-
self.proposer_rpc.request_agg_proof(request).await
75-
}
76-
77-
async fn wait_for_proof(&self, proof_id: ProofId) -> Result<SP1ProofWithPublicValues, Error> {
78-
let request_id = proof_id.0;
79-
80-
self.prover_rpc
81-
.wait_for_proof(request_id, self.proving_timeout)
82-
.await
83-
.map_err(|e| Error::Proving(proof_id, e.to_string()))
84-
}
28+
request_id: RequestId,
29+
) -> Result<SP1ProofWithPublicValues, Error>;
8530
}
8631

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

10146
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
102-
pub struct ProofId(pub B256);
47+
pub struct RequestId(pub B256);
10348

104-
impl Display for ProofId {
49+
impl Display for RequestId {
10550
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10651
write!(f, "{}", hex::encode(self.0))
10752
}

0 commit comments

Comments
 (0)