@@ -31,9 +31,10 @@ use aligned_sdk::core::constants::{
3131 RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER ,
3232} ;
3333use aligned_sdk:: core:: types:: {
34- ClientMessage , GetNonceResponseMessage , NoncedVerificationData , ProofInvalidReason ,
35- ProvingSystemId , SubmitProofMessage , SubmitProofResponseMessage , VerificationCommitmentBatch ,
36- VerificationData , VerificationDataCommitment ,
34+ ClientMessage , GetFirstNonceInQueueResponseMessage , GetNonceResponseMessage ,
35+ NoncedVerificationData , ProofInvalidReason , ProvingSystemId , SubmitProofMessage ,
36+ SubmitProofResponseMessage , VerificationCommitmentBatch , VerificationData ,
37+ VerificationDataCommitment ,
3738} ;
3839
3940use aws_sdk_s3:: client:: Client as S3Client ;
@@ -473,6 +474,11 @@ impl Batcher {
473474 . handle_submit_proof_msg ( msg, ws_conn_sink)
474475 . await
475476 }
477+ ClientMessage :: GetFirstNonceInQueueForAddress ( address) => {
478+ self . clone ( )
479+ . handle_get_first_nonce_in_queue_for_address_msg ( address, ws_conn_sink)
480+ . await
481+ }
476482 }
477483 }
478484
@@ -533,6 +539,65 @@ impl Batcher {
533539 Ok ( ( ) )
534540 }
535541
542+ async fn handle_get_first_nonce_in_queue_for_address_msg (
543+ self : Arc < Self > ,
544+ mut address : Address ,
545+ ws_conn_sink : WsMessageSink ,
546+ ) -> Result < ( ) , Error > {
547+ if self . is_nonpaying ( & address) {
548+ info ! ( "Handling nonpaying message" ) ;
549+ let Some ( non_paying_config) = self . non_paying_config . as_ref ( ) else {
550+ warn ! (
551+ "There isn't a non-paying configuration loaded. This message will be ignored"
552+ ) ;
553+ send_message (
554+ ws_conn_sink. clone ( ) ,
555+ GetFirstNonceInQueueResponseMessage :: InvalidRequest (
556+ "There isn't a non-paying configuration loaded." . to_string ( ) ,
557+ ) ,
558+ )
559+ . await ;
560+ return Ok ( ( ) ) ;
561+ } ;
562+ let replacement_addr = non_paying_config. replacement . address ( ) ;
563+ address = replacement_addr;
564+ }
565+
566+ let ( cached_user_nonce, proof_count) = {
567+ let batch_state_lock = self . batch_state . lock ( ) . await ;
568+ (
569+ batch_state_lock. get_user_nonce ( & address) . await ,
570+ batch_state_lock. get_user_proof_count ( & address) . await ,
571+ )
572+ } ;
573+
574+ let Some ( user_nonce) = cached_user_nonce else {
575+ send_message (
576+ ws_conn_sink. clone ( ) ,
577+ GetFirstNonceInQueueResponseMessage :: NoProofsInQueue ,
578+ )
579+ . await ;
580+ return Ok ( ( ) ) ;
581+ } ;
582+
583+ let Some ( proof_count) = proof_count else {
584+ send_message (
585+ ws_conn_sink. clone ( ) ,
586+ GetFirstNonceInQueueResponseMessage :: NoProofsInQueue ,
587+ )
588+ . await ;
589+ return Ok ( ( ) ) ;
590+ } ;
591+
592+ send_message (
593+ ws_conn_sink. clone ( ) ,
594+ GetFirstNonceInQueueResponseMessage :: Nonce ( user_nonce - proof_count) ,
595+ )
596+ . await ;
597+
598+ Ok ( ( ) )
599+ }
600+
536601 async fn handle_submit_proof_msg (
537602 self : Arc < Self > ,
538603 client_msg : Box < SubmitProofMessage > ,
0 commit comments