Skip to content

Commit 4705e18

Browse files
authored
Log address on lack of funds error (#2119)
1 parent 27d2913 commit 4705e18

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

crates/batcher/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,8 +1820,9 @@ impl Batcher {
18201820
// decide if i want to flush the queue:
18211821
match e {
18221822
BatcherError::TransactionSendError(
1823-
TransactionSendError::SubmissionInsufficientBalance,
1823+
TransactionSendError::SubmissionInsufficientBalance(address),
18241824
) => {
1825+
warn!("User {:?} has insufficient balance, flushing entire queue as safety measure", address);
18251826
// TODO: In the future, we should re-add the failed batch back to the queue
18261827
// For now, we flush everything as a safety measure
18271828
self.flush_queue_and_clear_nonce_cache().await;

crates/batcher/src/types/errors.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub enum TransactionSendError {
77
NoProofSubmitters,
88
NoFeePerProof,
99
InsufficientFeeForAggregator,
10-
SubmissionInsufficientBalance,
10+
SubmissionInsufficientBalance(Address),
1111
BatchAlreadySubmitted,
1212
InsufficientFunds,
1313
OnlyBatcherAllowed,
@@ -30,8 +30,16 @@ impl From<Bytes> for TransactionSendError {
3030
"0x3102f10c" => TransactionSendError::BatchAlreadySubmitted, // can happen, don't flush
3131
"0x5c54305e" => TransactionSendError::InsufficientFunds, // shouldn't happen, don't flush
3232
"0x152bc288" => TransactionSendError::OnlyBatcherAllowed, // won't happen, don't flush
33-
"0x4f779ceb" => TransactionSendError::SubmissionInsufficientBalance, // shouldn't happen,
34-
// flush can help if something went wrong
33+
"0x4f779ceb" => {
34+
// SubmissionInsufficientBalance(address sender, uint256 balance, uint256 required)
35+
// Try to decode the address parameter (first parameter after selector)
36+
let address = byte_string
37+
.get(34..74) // Skip "0x" + selector (8 chars) + padding (24 chars)
38+
.and_then(|hex_str| hex::decode(hex_str).ok())
39+
.map(|bytes| Address::from_slice(&bytes))
40+
.unwrap_or(Address::zero());
41+
TransactionSendError::SubmissionInsufficientBalance(address)
42+
}
3543
_ => {
3644
// flush because unkown error
3745
TransactionSendError::Generic(format!("Unknown bytestring error: {}", byte_string))
@@ -155,8 +163,12 @@ impl fmt::Display for TransactionSendError {
155163
TransactionSendError::InsufficientFeeForAggregator => {
156164
write!(f, "Insufficient fee for aggregator")
157165
}
158-
TransactionSendError::SubmissionInsufficientBalance => {
159-
write!(f, "Submission insufficient balance")
166+
TransactionSendError::SubmissionInsufficientBalance(address) => {
167+
write!(
168+
f,
169+
"Submission insufficient balance for address: {:?}",
170+
address
171+
)
160172
}
161173
TransactionSendError::BatchAlreadySubmitted => {
162174
write!(f, "Batch already submitted")

0 commit comments

Comments
 (0)