Skip to content

Commit 1bbfcc5

Browse files
committed
chore: fix error handling for invalid proof in sdk client
1 parent a3223dc commit 1bbfcc5

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

batcher/aligned-sdk/src/communication/messaging.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub async fn send_messages(
9696
}
9797
ValidityResponseMessage::InvalidProof(reason) => {
9898
error!("Invalid Proof!: {}", reason);
99-
return Err(SubmitError::InvalidProof);
99+
return Err(SubmitError::InvalidProof(reason));
100100
}
101101
ValidityResponseMessage::InvalidMaxFee => {
102102
error!("Invalid Max Fee!");
@@ -220,6 +220,9 @@ async fn process_batch_inclusion_data(
220220
"Could not create task with merkle root ".to_owned() + &merkle_root,
221221
));
222222
}
223+
Ok(ResponseMessage::InvalidProof(reason)) => {
224+
return Err(SubmitError::InvalidProof(reason));
225+
}
223226
Err(e) => {
224227
return Err(SubmitError::SerializationError(e));
225228
}

batcher/aligned-sdk/src/core/errors.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use tokio_tungstenite::tungstenite::protocol::CloseFrame;
99

1010
use crate::communication::serialization::SerializationError;
1111

12+
use super::types::ProofInvalidReason;
13+
1214
#[derive(Debug)]
1315
pub enum AlignedError {
1416
SubmitError(SubmitError),
@@ -84,7 +86,7 @@ pub enum SubmitError {
8486
ProofQueueFlushed,
8587
InvalidSignature,
8688
InvalidChainId,
87-
InvalidProof,
89+
InvalidProof(ProofInvalidReason),
8890
ProofTooLarge,
8991
InvalidReplacementMessage,
9092
InsufficientBalance,
@@ -187,7 +189,7 @@ impl fmt::Display for SubmitError {
187189
SubmitError::GenericError(e) => write!(f, "Generic error: {}", e),
188190
SubmitError::InvalidSignature => write!(f, "Invalid Signature"),
189191
SubmitError::InvalidChainId => write!(f, "Invalid chain Id"),
190-
SubmitError::InvalidProof => write!(f, "Invalid proof"),
192+
SubmitError::InvalidProof(reason) => write!(f, "Invalid proof: {}", reason),
191193
SubmitError::ProofTooLarge => write!(f, "Proof too Large"),
192194
SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"),
193195
SubmitError::InsufficientBalance => write!(f, "Insufficient balance"),

batcher/aligned-sdk/src/core/types.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub enum ValidityResponseMessage {
349349
pub enum ProofInvalidReason {
350350
RejectedProof,
351351
VerifierNotSupported,
352-
DisabledVerifier,
352+
DisabledVerifier(ProvingSystemId),
353353
}
354354

355355
impl Display for ValidityResponseMessage {
@@ -387,7 +387,9 @@ impl Display for ProofInvalidReason {
387387
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
388388
match self {
389389
ProofInvalidReason::VerifierNotSupported => write!(f, "Verifier not supported"),
390-
ProofInvalidReason::DisabledVerifier => write!(f, "Disabled verifier"),
390+
ProofInvalidReason::DisabledVerifier(id) => {
391+
write!(f, "Disabled {} verifier ", id)
392+
}
391393
ProofInvalidReason::RejectedProof => write!(f, "Proof did not verify"),
392394
}
393395
}
@@ -398,6 +400,7 @@ pub enum ResponseMessage {
398400
BatchInclusionData(BatchInclusionData),
399401
ProtocolVersion(u16),
400402
CreateNewTaskError(String),
403+
InvalidProof(ProofInvalidReason),
401404
BatchReset,
402405
Error(String),
403406
}

batcher/aligned-sdk/src/sdk.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use log::debug;
3838

3939
use futures_util::{
4040
stream::{SplitSink, SplitStream},
41-
StreamExt, TryStreamExt,
41+
SinkExt, StreamExt, TryStreamExt,
4242
};
4343

4444
/// Submits multiple proofs to the batcher to be verified in Aligned and waits for the verification on-chain.
@@ -241,16 +241,22 @@ pub async fn submit_multiple(
241241

242242
let ws_write = Arc::new(Mutex::new(ws_write));
243243

244-
_submit_multiple(
245-
ws_write,
244+
let submit_result = _submit_multiple(
245+
ws_write.clone(),
246246
ws_read,
247247
network,
248248
verification_data,
249249
max_fees,
250250
wallet,
251251
nonce,
252252
)
253-
.await
253+
.await;
254+
255+
if submit_result.is_err() {
256+
let mut ws_write = ws_write.lock().await;
257+
ws_write.close().await?;
258+
}
259+
submit_result
254260
}
255261

256262
pub fn get_payment_service_address(network: Network) -> ethers::types::H160 {

0 commit comments

Comments
 (0)