@@ -95,11 +95,14 @@ pub async fn send_messages(
9595pub async fn receive (
9696 response_stream : Arc < Mutex < ResponseStream > > ,
9797 mut sent_verification_data_rev : Vec < Result < NoncedVerificationData , SubmitError > > ,
98+ first_nonce : U256 ,
9899) -> Vec < Result < AlignedVerificationData , SubmitError > > {
99100 // Responses are filtered to only admit binary or close messages.
100101 let mut response_stream = response_stream. lock ( ) . await ;
101102 let mut aligned_submitted_data: Vec < Result < AlignedVerificationData , SubmitError > > = Vec :: new ( ) ;
102- let mut last_proof_nonce = get_biggest_nonce ( & sent_verification_data_rev) ;
103+ let last_sent_proof_nonce = get_biggest_nonce ( & sent_verification_data_rev) ;
104+ let mut last_proof_nonce = last_sent_proof_nonce;
105+ info ! ( "last_sent_proof_nonce: {}" , last_sent_proof_nonce) ;
103106
104107 // read from WS
105108 while let Some ( Ok ( msg) ) = response_stream. next ( ) . await {
@@ -123,18 +126,25 @@ pub async fn receive(
123126 let batch_inclusion_data_message = match handle_batcher_response ( msg) . await {
124127 Ok ( data) => data,
125128 Err ( e) => {
126- // In the case of an insufficient balance we still want to read and return the proofs.
129+ warn ! ( "Error while handling batcher response: {:?}" , e) ;
130+ // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there
131+ // insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved.
127132 // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance.
128133 // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance.
129134 if let SubmitError :: InsufficientBalance ( _, last_valid_nonce) = e {
130135 aligned_submitted_data. push ( Err ( e) ) ;
131- last_proof_nonce = last_valid_nonce - 1 ;
136+ // last_valid_nonce = last_nonce - 1. In the case
137+ info ! ( "last_proof_nonce: {}" , last_proof_nonce) ;
138+ info ! ( "last_valid_nonce: {}" , last_valid_nonce) ;
139+ // In the case all proofs are insufficient balance we go over them.
140+ last_proof_nonce -= U256 :: from ( 1 ) ;
141+ if last_proof_nonce <= first_nonce {
142+ break ;
143+ }
132144 continue ;
133- } else {
134- warn ! ( "Error while handling batcher response: {:?}" , e) ;
135- aligned_submitted_data. push ( Err ( e) ) ;
136- break ;
137145 }
146+ aligned_submitted_data. push ( Err ( e) ) ;
147+ break ;
138148 }
139149 } ;
140150
@@ -168,6 +178,9 @@ pub async fn receive(
168178 aligned_submitted_data. push ( Ok ( aligned_verification_data) ) ;
169179 debug ! ( "Message response handled successfully" ) ;
170180
181+ info ! ( "last_proof_nonce: {}" , last_proof_nonce) ;
182+ info ! ( "batch_inclusion_data_message.user_nonce: {}" , batch_inclusion_data_message. user_nonce) ;
183+
171184 if batch_inclusion_data_message. user_nonce == last_proof_nonce {
172185 break ;
173186 }
@@ -314,4 +327,4 @@ fn get_biggest_nonce(
314327 }
315328 }
316329 biggest_nonce
317- }
330+ }
0 commit comments