Skip to content

Commit 8401c50

Browse files
author
Victor Castell
authored
refactor: vanilla (#329)
This pull request introduces a new utility function for waiting on proof completion in the `ProposerDBClient`, adds a new dependency for interoperability, and refactors the `ProposerService` test setup to use a constructor method for improved clarity and maintainability. **Core functionality improvements:** * Added a new async method `wait_for_proof_completion` to `ProposerDBClient` that polls for a proof's completion, handling retries and error cases such as failure, cancellation, or timeout. **Dependency updates:** * Added `agglayer-interop-types` as a workspace dependency in `crates/proposer-service/Cargo.toml` to improve interoperability with other ecosystem components. **Test and codebase refactoring:** * Updated the `ProposerService` test setup to use the `ProposerService::new` constructor and the `ProofBackend::Grpc` variant, replacing direct struct initialization for better encapsulation and maintainability in `crates/proposer-service/src/tests/mod.rs`. [[1]](diffhunk://#diff-d9386ae9b1b2b470dad4ccbda209e421925557caa6d602f50a2b46298da7fa9bL142-R155) [[2]](diffhunk://#diff-d9386ae9b1b2b470dad4ccbda209e421925557caa6d602f50a2b46298da7fa9bL209-R223) * Added `ProofBackend` to the imports in the test module to support the new test setup.
1 parent cff7937 commit 8401c50

5 files changed

Lines changed: 410 additions & 220 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/proposer-db-client/src/client.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,40 @@ impl ProposerDBClient {
178178
tokio::time::sleep(tokio::time::Duration::from_millis(poll_interval_ms)).await;
179179
}
180180
}
181+
182+
/// Polls the database until the request reaches Complete status.
183+
/// Returns the proof bytes once available.
184+
pub async fn wait_for_proof_completion(
185+
&self,
186+
request_id: i64,
187+
poll_interval_ms: u64,
188+
max_retries: u32,
189+
) -> Result<Vec<u8>, Error> {
190+
let mut retries = 0;
191+
192+
loop {
193+
let request = self.get_request_by_id(request_id).await?;
194+
195+
match request.status {
196+
RequestStatus::Failed => return Err(Error::ProofGenerationFailed(request_id)),
197+
RequestStatus::Cancelled => {
198+
return Err(Error::ProofGenerationCancelled(request_id))
199+
}
200+
RequestStatus::Complete | RequestStatus::Relayed => {
201+
if let Some(proof) = request.proof {
202+
return Ok(proof);
203+
}
204+
return Err(Error::ProofNotFound);
205+
}
206+
// Still in progress (Unrequested, WitnessGeneration, Execution, Prove)
207+
_ => {}
208+
}
209+
210+
if retries >= max_retries {
211+
return Err(Error::ProofGenerationTimeout(request_id));
212+
}
213+
retries += 1;
214+
tokio::time::sleep(tokio::time::Duration::from_millis(poll_interval_ms)).await;
215+
}
216+
}
181217
}

crates/proposer-service/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ mockall = { workspace = true, optional = true }
5252

5353
op-succinct-validity.workspace = true
5454

55+
# Ecosystem dependencies
56+
agglayer-interop-types.workspace = true
57+
5558
[features]
5659
testutils = ["mockall"]
5760

0 commit comments

Comments
 (0)