@@ -99,7 +99,7 @@ pub async fn receive(
9999 // Responses are filtered to only admit binary or close messages.
100100 let mut response_stream = response_stream. lock ( ) . await ;
101101 let mut aligned_submitted_data: Vec < Result < AlignedVerificationData , SubmitError > > = Vec :: new ( ) ;
102- let last_proof_nonce = get_biggest_nonce ( & sent_verification_data_rev) ;
102+ let mut last_proof_nonce = get_biggest_nonce ( & sent_verification_data_rev) ;
103103
104104 // read from WS
105105 while let Some ( Ok ( msg) ) = response_stream. next ( ) . await {
@@ -123,9 +123,18 @@ pub async fn receive(
123123 let batch_inclusion_data_message = match handle_batcher_response ( msg) . await {
124124 Ok ( data) => data,
125125 Err ( e) => {
126- warn ! ( "Error while handling batcher response: {:?}" , e) ;
127- aligned_submitted_data. push ( Err ( e) ) ;
128- break ;
126+ // In the case of an insufficient balance we still want to read and return the proofs.
127+ // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance.
128+ // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance.
129+ if let SubmitError :: InsufficientBalance ( _, last_valid_nonce) = e {
130+ aligned_submitted_data. push ( Err ( e) ) ;
131+ last_proof_nonce = last_valid_nonce - 1 ;
132+ continue ;
133+ } else {
134+ warn ! ( "Error while handling batcher response: {:?}" , e) ;
135+ aligned_submitted_data. push ( Err ( e) ) ;
136+ break ;
137+ }
129138 }
130139 } ;
131140
@@ -191,6 +200,7 @@ async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, Sub
191200 Err ( SubmitError :: InvalidMaxFee )
192201 }
193202 Ok ( SubmitProofResponseMessage :: InsufficientBalance ( addr, last_sent_valid_nonce) ) => {
203+ // If we receive an invalid balance we should grab the last_sent_valid_nonce.
194204 error ! ( "Batcher responded with insufficient balance" ) ;
195205 Err ( SubmitError :: InsufficientBalance ( addr, last_sent_valid_nonce) )
196206 }
0 commit comments