@@ -53,6 +53,7 @@ use types::errors::{BatcherError, TransactionSendError};
5353
5454use crate :: config:: { ConfigFromYaml , ContractDeploymentOutput } ;
5555use crate :: telemetry:: sender:: TelemetrySender ;
56+ use crate :: types:: non_paying:: NonPayingData ;
5657
5758mod config;
5859mod connection;
@@ -585,14 +586,15 @@ impl Batcher {
585586 return Ok ( ( ) ) ;
586587 }
587588
588- let Some ( addr) = self
589+ let Some ( mut addr) = self
589590 . msg_signature_is_valid ( & client_msg, & ws_conn_sink)
590591 . await
591592 else {
592593 return Ok ( ( ) ) ;
593594 } ;
594595
595- let nonced_verification_data = client_msg. verification_data . clone ( ) ;
596+ let mut nonced_verification_data = client_msg. verification_data . clone ( ) ;
597+ let mut signature = client_msg. signature . clone ( ) ;
596598
597599 // When pre-verification is enabled, batcher will verify proofs for faster feedback with clients
598600 if self . pre_verification_is_enabled {
@@ -635,13 +637,22 @@ impl Batcher {
635637 }
636638
637639 if self . is_nonpaying ( & addr) {
638- // TODO: Non paying msg and paying should share some logic
639- return self
640- . handle_nonpaying_msg ( ws_conn_sink. clone ( ) , & client_msg)
640+ 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 :: NonPayingAddressError ,
646+ )
641647 . await ;
648+ return Ok ( ( ) ) ;
649+ } ;
650+ addr = non_paying_data. address ;
651+ nonced_verification_data = non_paying_data. nonced_verification_data ;
652+ signature = non_paying_data. signature ;
642653 }
643654
644- info ! ( "Handling paying message" ) ;
655+ info ! ( "Handling message" ) ;
645656
646657 // We don't need a batch state lock here, since if the user locks its funds
647658 // after the check, some blocks should pass until he can withdraw.
@@ -867,7 +878,7 @@ impl Batcher {
867878 batch_state_lock,
868879 nonced_verification_data,
869880 ws_conn_sink. clone ( ) ,
870- client_msg . signature ,
881+ signature,
871882 addr,
872883 )
873884 . await
@@ -1756,83 +1767,36 @@ impl Batcher {
17561767 }
17571768
17581769 /// Only relevant for testing and for users to easily use Aligned in testnet.
1759- async fn handle_nonpaying_msg (
1770+ async fn generate_non_paying_data (
17601771 & self ,
1761- ws_sink : WsMessageSink ,
17621772 client_msg : & SubmitProofMessage ,
1763- ) -> Result < ( ) , Error > {
1773+ ) -> Result < NonPayingData , TransactionSendError > {
17641774 info ! ( "Handling nonpaying message" ) ;
17651775 let Some ( non_paying_config) = self . non_paying_config . as_ref ( ) else {
17661776 warn ! ( "There isn't a non-paying configuration loaded. This message will be ignored" ) ;
1767- send_message ( ws_sink. clone ( ) , SubmitProofResponseMessage :: InvalidNonce ) . await ;
1768- return Ok ( ( ) ) ;
1769- } ;
1770-
1771- let replacement_addr = non_paying_config. replacement . address ( ) ;
1772- let Some ( replacement_user_balance) = self . get_user_balance ( & replacement_addr) . await else {
1773- error ! ( "Could not get balance for non-paying address {replacement_addr:?}" ) ;
1774- send_message (
1775- ws_sink. clone ( ) ,
1776- SubmitProofResponseMessage :: InsufficientBalance ( replacement_addr) ,
1777- )
1778- . await ;
1779- return Ok ( ( ) ) ;
1777+ return Err ( TransactionSendError :: NonPayingAddressNotAllowed ) ;
17801778 } ;
17811779
1782- if replacement_user_balance == U256 :: from ( 0 ) {
1783- error ! ( "Insufficient funds for non-paying address {replacement_addr:?}" ) ;
1784- send_message (
1785- ws_sink. clone ( ) ,
1786- SubmitProofResponseMessage :: InsufficientBalance ( replacement_addr) ,
1787- )
1788- . await ;
1789- return Ok ( ( ) ) ;
1790- }
1791-
1792- let batch_state_lock = self . batch_state . lock ( ) . await ;
1793-
1794- if batch_state_lock. is_queue_full ( ) {
1795- error ! ( "Can't add new entry, the batcher queue is full" ) ;
1796- send_message (
1797- ws_sink. clone ( ) ,
1798- SubmitProofResponseMessage :: UnderpricedProof ,
1799- )
1800- . await ;
1801- return Ok ( ( ) ) ;
1802- }
1803-
18041780 let nonced_verification_data = NoncedVerificationData :: new (
18051781 client_msg. verification_data . verification_data . clone ( ) ,
18061782 client_msg. verification_data . nonce ,
1807- DEFAULT_MAX_FEE_PER_PROOF . into ( ) , // 2_000 gas per proof * 100 gwei gas price (upper bound)
1783+ ( DEFAULT_MAX_FEE_PER_PROOF * 100 ) . into ( ) , // 2_000 gas per proof * 100 gwei gas price (upper bound) * 100 to make sure it is enough
18081784 self . chain_id ,
18091785 self . payment_service . address ( ) ,
18101786 ) ;
18111787
18121788 let client_msg = SubmitProofMessage :: new (
1813- nonced_verification_data . clone ( ) ,
1789+ client_msg . verification_data . clone ( ) ,
18141790 non_paying_config. replacement . clone ( ) ,
18151791 )
18161792 . await ;
18171793
1818- let signature = client_msg. signature ;
1819- if let Err ( e) = self
1820- . add_to_batch (
1821- batch_state_lock,
1822- nonced_verification_data,
1823- ws_sink. clone ( ) ,
1824- signature,
1825- replacement_addr,
1826- )
1827- . await
1828- {
1829- info ! ( "Error while adding nonpaying address entry to batch: {e:?}" ) ;
1830- send_message ( ws_sink, SubmitProofResponseMessage :: AddToBatchError ) . await ;
1831- return Ok ( ( ) ) ;
1832- } ;
1833-
18341794 info ! ( "Non-paying verification data message handled" ) ;
1835- Ok ( ( ) )
1795+ Ok ( NonPayingData {
1796+ address : non_paying_config. replacement . address ( ) ,
1797+ nonced_verification_data,
1798+ signature : client_msg. signature ,
1799+ } )
18361800 }
18371801
18381802 /// Gets the balance of user with address `addr` from Ethereum.
0 commit comments