@@ -31,9 +31,7 @@ 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+ BumpFeeResponseMessage , BumpUnit , ClientMessage , GetNonceResponseMessage , NoncedVerificationData , ProofInvalidReason , ProvingSystemId , SubmitProofMessage , SubmitProofResponseMessage , VerificationCommitmentBatch , VerificationData , VerificationDataCommitment
3735} ;
3836
3937use aws_sdk_s3:: client:: Client as S3Client ;
@@ -473,6 +471,11 @@ impl Batcher {
473471 . handle_submit_proof_msg ( msg, ws_conn_sink)
474472 . await
475473 }
474+ ClientMessage :: BumpFee ( bump_unit, amout, proof_qty) => {
475+ self . clone ( )
476+ . handle_bump_fee_msg ( bump_unit, amout, proof_qty, ws_conn_sink)
477+ . await
478+ }
476479 }
477480 }
478481
@@ -783,6 +786,9 @@ impl Batcher {
783786
784787 // In this case, the message might be a replacement one. If it is valid,
785788 // we replace the old entry with the new from the replacement message.
789+
790+ // TODO DISABLE THIS FUNCTIONALITY
791+ // IT IS BEING REPLACED WITH BumpFee()
786792 if expected_nonce > msg_nonce {
787793 info ! ( "Possible replacement message received: Expected nonce {expected_nonce:?} - message nonce: {msg_nonce:?}" ) ;
788794 self . handle_replacement_message (
@@ -833,6 +839,84 @@ impl Batcher {
833839 Ok ( ( ) )
834840 }
835841
842+
843+ // TODO add signature
844+ async fn handle_bump_fee_msg (
845+ bump_unit : BumpUnit ,
846+ amount : U256 ,
847+ proof_qty : usize ,
848+ signature : Signature , //TODO add this
849+ signature_content : Vec < u8 > , //TODO add this
850+ ws_conn_sink : WsMessageSink ,
851+ ) -> Result < ( ) , Error > {
852+
853+ // /// The signature of the message is verified, and when it correct, the
854+ // /// recovered address from the signature is returned.
855+ // pub fn verify_signature(&self) -> Result<Address, VerifySignatureError> {
856+ // // Recovers the address from the signed data
857+ // let recovered = self.signature.recover_typed_data(&self.verification_data)?;
858+
859+ // let hashed_data = self.verification_data.encode_eip712()?;
860+
861+ // self.signature.verify(hashed_data, recovered)?;
862+ // Ok(recovered)
863+ // }
864+
865+ info ! ( "Verifying Bump Fee signature..." ) ;
866+ let Ok ( addr) = verify_bump_signature ( signature, signature_content) else {
867+ error ! ( "Signature verification error" ) ;
868+ send_message (
869+ ws_conn_sink. clone ( ) ,
870+ BumpFeeResponseMessage :: InvalidSignature ,
871+ )
872+ . await ;
873+ self . metrics . user_error ( & [ "invalid_bump_fee_signature" , "" ] ) ;
874+ return Ok ( ( ) ) ;
875+ } ;
876+ info ! ( "Bump Fee signature verified" ) ;
877+
878+
879+ let from_proof_nonce = self . get_first_proof ( ) ;
880+ let to_proof_nonce = from_proof_nonce + proof_qty; // exclusive
881+
882+ let batch_state_lock = self . batch_state . lock ( ) . await ;
883+ let batch_queue_copy = batch_state_lock. batch_queue . clone ( ) ;
884+
885+ // TODO check if user has enough funds
886+ while let Some ( ( entry, _) ) = batch_state_lock. batch_queue . peek ( ) {
887+ let entry_nonce = entry. nonced_verification_data . nonce ;
888+ if entry_nonce >= from_proof_nonce && entry_nonce < to_proof_nonce {
889+ if let Err ( bumped_fee) = calculate_bumped_proof_cost ( entry. nonced_verification_data . max_fee , bump_unit, amount) {
890+ send_message (
891+ ws_conn_sink. clone ( ) ,
892+ BumpFeeResponseMessage :: InvalidBumpUnit ,
893+ )
894+ . await ;
895+ self . metrics . user_error ( & [ "invalid_bump_fee_unit" , "" ] ) ;
896+ return Ok ( ( ) ) ;
897+ }
898+ let new_entry = entry. clone ( ) ;
899+ new_entry. nonced_verification_data . max_fee = bumped_fee;
900+
901+ batch_state_lock. update_user_total_fees_in_queue_of_replacement_message ( sender_address, entry_nonce. clone ( ) , bumped_fee) . await ?;
902+ batch_state_lock. replace_entry ( entry, new_entry) ;
903+ }
904+ } ;
905+ return ;
906+
907+ }
908+
909+ fn verify_bump_signature (
910+ & self ,
911+ signature : Signature ,
912+ bump_unit : BumpUnit ,
913+ amount : U256 ,
914+ proof_qty : usize ,
915+ ) -> bool {
916+ // TODO
917+ true
918+ }
919+
836920 async fn is_verifier_disabled ( & self , verifier : ProvingSystemId ) -> bool {
837921 let disabled_verifiers = self . disabled_verifiers . lock ( ) . await ;
838922 zk_utils:: is_verifier_disabled ( * disabled_verifiers, verifier)
0 commit comments