Skip to content

Commit

Permalink
fix: add verbosity for verification compilation error (#703)
Browse files Browse the repository at this point in the history
* fix: add verbosity to compiler error verification requests

* fix: update based on review comments

* fix: update based on review comments
  • Loading branch information
dutterbutter authored Nov 6, 2024
1 parent 772d1d8 commit 81a9bad
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions crates/verify/src/zksync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl VerificationProvider for ZkVerificationProvider {
let verification_status =
self.retry_verification_status(&client, &url, max_retries, delay_in_seconds).await?;

self.process_status_response(Some(verification_status))
self.process_status_response(Some(verification_status), &url)
}
}

Expand Down Expand Up @@ -234,15 +234,6 @@ impl ZkVerificationProvider {

let resp: ContractVerificationStatusResponse = serde_json::from_str(&text)?;

if resp.error_exists() {
eyre::bail!("Verification error: {}", resp.get_error());
}
if resp.is_verification_success() {
return Ok(resp);
}
if resp.is_verification_failure() {
eyre::bail!("Verification failed: {}", resp.get_error());
}
if resp.is_pending() || resp.is_queued() {
if retries >= max_retries {
println!("Verification is still pending after {max_retries} retries.");
Expand All @@ -251,24 +242,32 @@ impl ZkVerificationProvider {

retries += 1;

// Calculate the next delay and wait
let delay_in_ms = calculate_retry_delay(retries, delay_in_seconds);
sleep(Duration::from_millis(delay_in_ms));
continue;
}

if resp.is_verification_success() || resp.is_verification_failure() {
return Ok(resp);
}
}
}

fn process_status_response(
&self,
response: Option<ContractVerificationStatusResponse>,
verification_url: &str,
) -> Result<()> {
trace!("Processing verification status response. {:?}", response);

if let Some(resp) = response {
match resp.status {
VerificationStatusEnum::Successful => {
println!("Verification was successful.");
}
VerificationStatusEnum::Failed => {
let error_message = resp.get_error();
eyre::bail!("Verification failed: {}", error_message);
let error_message = resp.get_error(verification_url);
eyre::bail!("Verification failed:\n\n{}", error_message);
}
VerificationStatusEnum::Queued => {
println!("Verification is queued.");
Expand Down Expand Up @@ -303,25 +302,36 @@ pub enum VerificationStatusEnum {
pub struct ContractVerificationStatusResponse {
pub status: VerificationStatusEnum,
pub error: Option<String>,
#[serde(rename = "compilationErrors")]
pub compilation_errors: Option<Vec<String>>,
}

impl ContractVerificationStatusResponse {
pub fn error_exists(&self) -> bool {
self.error.is_some() || self.compilation_errors.is_some()
}
pub fn get_error(&self) -> String {
let mut errors = String::new();
pub fn get_error(&self, verification_url: &str) -> String {
let mut error_message = String::new();

if let Some(ref error) = self.error {
errors.push_str(error);
error_message.push_str("Error:\n");
error_message.push_str(error);
}

// Detailed compilation errors, if any
if let Some(ref compilation_errors) = self.compilation_errors {
errors.push_str(&compilation_errors.join("\n"));
if !compilation_errors.is_empty() {
let detailed_errors = compilation_errors
.iter()
.map(|e| format!("- {e}"))
.collect::<Vec<_>>()
.join("\n");
error_message.push_str("\n\nError Details:\n");
error_message.push_str(&detailed_errors);
}
}

errors
error_message.push_str("\n\nView verification response:\n");
error_message.push_str(verification_url);

error_message.trim_end().to_string()
}
pub fn is_pending(&self) -> bool {
matches!(self.status, VerificationStatusEnum::InProgress)
Expand Down

0 comments on commit 81a9bad

Please sign in to comment.