Skip to content

Commit 89602d1

Browse files
JulianVenturaJulian Venturaavilagaston9uri-99
authored
fix: parse error codes from createNewTask ethereum contract function (#1503)
Co-authored-by: Julian Ventura <[email protected]> Co-authored-by: avilagaston9 <[email protected]> Co-authored-by: Urix <[email protected]>
1 parent d3fb100 commit 89602d1

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

batcher/aligned-batcher/src/retry/batcher_retryables.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
utils::get_current_nonce,
1111
},
1212
retry::RetryError,
13-
types::errors::BatcherError,
13+
types::errors::{BatcherError, TransactionSendError},
1414
};
1515

1616
pub async fn get_user_balance_retryable(
@@ -130,7 +130,7 @@ pub async fn create_new_task_retryable(
130130
// Since transaction was reverted, we don't want to retry with fallback.
131131
warn!("Transaction reverted {:?}", err);
132132
return Err(RetryError::Permanent(BatcherError::TransactionSendError(
133-
err.to_string(),
133+
TransactionSendError::from(err),
134134
)));
135135
}
136136
_ => {
@@ -149,12 +149,12 @@ pub async fn create_new_task_retryable(
149149
Err(ContractError::Revert(err)) => {
150150
warn!("Transaction reverted {:?}", err);
151151
return Err(RetryError::Permanent(BatcherError::TransactionSendError(
152-
err.to_string(),
152+
TransactionSendError::from(err),
153153
)));
154154
}
155155
Err(err) => {
156156
return Err(RetryError::Transient(BatcherError::TransactionSendError(
157-
err.to_string(),
157+
TransactionSendError::Generic(err.to_string()),
158158
)))
159159
}
160160
}

batcher/aligned-batcher/src/types/errors.rs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
use std::fmt;
22

3-
use ethers::types::{Address, SignatureError};
3+
use ethers::types::{Address, Bytes, SignatureError};
44
use tokio_tungstenite::tungstenite;
55

6+
pub enum TransactionSendError {
7+
NoProofSubmitters,
8+
NoFeePerProof,
9+
InsufficientFeeForAggregator,
10+
SubmissionInsufficientBalance,
11+
BatchAlreadySubmitted,
12+
InsufficientFunds,
13+
OnlyBatcherAllowed,
14+
Generic(String),
15+
}
16+
17+
impl From<Bytes> for TransactionSendError {
18+
fn from(e: Bytes) -> Self {
19+
let byte_string = e.to_string();
20+
let str_code = if byte_string.len() >= 10 {
21+
&byte_string[..10] // Extract the error code only
22+
} else {
23+
"" // Not gonna match
24+
};
25+
match str_code {
26+
"0xc43ac290" => TransactionSendError::NoProofSubmitters, // can't happen, don't flush
27+
"0xa3a8658a" => TransactionSendError::NoFeePerProof, // can't happen, don't flush
28+
"0x7899ec71" => TransactionSendError::InsufficientFeeForAggregator, // shouldn't happen, don't flush
29+
// returning the proofs and retrying later may help
30+
"0x4f779ceb" => TransactionSendError::SubmissionInsufficientBalance, // shouldn't happen,
31+
// flush can help if something went wrong
32+
"0x3102f10c" => TransactionSendError::BatchAlreadySubmitted, // can happen, don't flush
33+
"0x5c54305e" => TransactionSendError::InsufficientFunds, // shouldn't happen, don't flush
34+
"0x152bc288" => TransactionSendError::OnlyBatcherAllowed, // won't happen, don't flush
35+
_ => {
36+
TransactionSendError::Generic(format!("Unknown bytestring error: {}", byte_string))
37+
}
38+
}
39+
}
40+
}
41+
642
pub enum BatcherError {
743
TcpListenerError(String),
844
ConnectionError(tungstenite::Error),
@@ -12,7 +48,7 @@ pub enum BatcherError {
1248
BatchUploadError(String),
1349
TaskCreationError(String),
1450
ReceiptNotFoundError,
15-
TransactionSendError(String),
51+
TransactionSendError(TransactionSendError),
1652
MaxRetriesReachedError,
1753
SerializationError(String),
1854
GasPriceError,
@@ -101,3 +137,34 @@ impl fmt::Debug for BatcherError {
101137
}
102138
}
103139
}
140+
141+
impl fmt::Display for TransactionSendError {
142+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
143+
match self {
144+
TransactionSendError::NoProofSubmitters => {
145+
write!(f, "No proof submitter error")
146+
}
147+
TransactionSendError::NoFeePerProof => {
148+
write!(f, "No fee per proof")
149+
}
150+
TransactionSendError::InsufficientFeeForAggregator => {
151+
write!(f, "Insufficient fee for aggregator")
152+
}
153+
TransactionSendError::SubmissionInsufficientBalance => {
154+
write!(f, "Submission insufficient balance")
155+
}
156+
TransactionSendError::BatchAlreadySubmitted => {
157+
write!(f, "Batch already submitted")
158+
}
159+
TransactionSendError::InsufficientFunds => {
160+
write!(f, "Insufficient funds")
161+
}
162+
TransactionSendError::OnlyBatcherAllowed => {
163+
write!(f, "Only batcher allowed")
164+
}
165+
TransactionSendError::Generic(e) => {
166+
write!(f, "Generic error: {}", e)
167+
}
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)