Skip to content

Commit 16f5291

Browse files
committed
refactor: simplify non-paying code
1 parent 135825c commit 16f5291

4 files changed

Lines changed: 7 additions & 28 deletions

File tree

batcher/aligned-batcher/src/lib.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -636,17 +636,9 @@ impl Batcher {
636636
}
637637
}
638638

639-
if self.is_nonpaying(&addr) {
639+
if self.is_nonpaying(&addr) && self.non_paying_config.is_some() {
640640
info!("Generating non-paying data");
641-
let Ok(non_paying_data) = self.generate_non_paying_data(&client_msg).await else {
642-
error!("Failed to generate non paying data");
643-
send_message(
644-
ws_conn_sink.clone(),
645-
SubmitProofResponseMessage::NonPayingNotAllowed,
646-
)
647-
.await;
648-
return Ok(());
649-
};
641+
let non_paying_data = self.generate_non_paying_data(&client_msg).await;
650642
addr = non_paying_data.address;
651643
nonced_verification_data = non_paying_data.nonced_verification_data;
652644
signature = non_paying_data.signature;
@@ -1770,12 +1762,9 @@ impl Batcher {
17701762
async fn generate_non_paying_data(
17711763
&self,
17721764
client_msg: &SubmitProofMessage,
1773-
) -> Result<NonPayingReplacementData, TransactionSendError> {
1774-
info!("Handling nonpaying message");
1775-
let Some(non_paying_config) = self.non_paying_config.as_ref() else {
1776-
warn!("There isn't a non-paying configuration loaded. This message will be ignored");
1777-
return Err(TransactionSendError::NonPayingNotAllowed);
1778-
};
1765+
) -> NonPayingReplacementData {
1766+
// This unwrap is safe because we check if the non-paying config is set before calling this function.
1767+
let non_paying_config = self.non_paying_config.as_ref().unwrap();
17791768

17801769
let nonced_verification_data = NoncedVerificationData::new(
17811770
client_msg.verification_data.verification_data.clone(),
@@ -1792,12 +1781,11 @@ impl Batcher {
17921781
)
17931782
.await;
17941783

1795-
info!("Non-paying verification data message handled");
1796-
Ok(NonPayingReplacementData {
1784+
NonPayingReplacementData {
17971785
address: non_paying_config.replacement.address(),
17981786
nonced_verification_data,
17991787
signature: non_paying_replacement_msg.signature,
1800-
})
1788+
}
18011789
}
18021790

18031791
/// Gets the balance of user with address `addr` from Ethereum.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub enum TransactionSendError {
1111
BatchAlreadySubmitted,
1212
InsufficientFunds,
1313
OnlyBatcherAllowed,
14-
NonPayingNotAllowed,
1514
Generic(String),
1615
}
1716

@@ -171,9 +170,6 @@ impl fmt::Display for TransactionSendError {
171170
TransactionSendError::Generic(e) => {
172171
write!(f, "Generic error: {}", e)
173172
}
174-
TransactionSendError::NonPayingNotAllowed => {
175-
write!(f, "Non-paying not allowed")
176-
}
177173
}
178174
}
179175
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ pub enum SubmitProofResponseMessage {
399399
EthRpcError,
400400
InvalidPaymentServiceAddress(Address, Address),
401401
UnderpricedProof,
402-
NonPayingNotAllowed,
403402
}
404403

405404
#[derive(Debug, Clone, Serialize, Deserialize)]

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, Sub
276276
);
277277
Err(SubmitError::SerializationError(e))
278278
}
279-
Ok(SubmitProofResponseMessage::NonPayingNotAllowed) => {
280-
error!("Batcher responded with: non-paying not allowed.");
281-
Err(SubmitError::NonPayingAddressError)
282-
}
283279
}
284280
}
285281

0 commit comments

Comments
 (0)