@@ -11,14 +11,14 @@ use futures_util::stream::{SplitSink, TryFilter};
1111use tokio_tungstenite:: { tungstenite:: Message , MaybeTlsStream , WebSocketStream } ;
1212
1313use crate :: communication:: serialization:: { cbor_deserialize, cbor_serialize} ;
14- use crate :: core:: types:: BatchInclusionData ;
14+ use crate :: core:: types:: { BatchInclusionData , SubmitProofMessage } ;
1515use crate :: {
1616 communication:: batch:: process_batcher_response,
1717 core:: {
1818 errors:: SubmitError ,
1919 types:: {
20- AlignedVerificationData , ClientMessage , NoncedVerificationData , ResponseMessage ,
21- VerificationData , VerificationDataCommitment ,
20+ AlignedVerificationData , ClientMessage , NoncedVerificationData ,
21+ SubmitProofResponseMessage , VerificationData , VerificationDataCommitment ,
2222 } ,
2323 } ,
2424} ;
@@ -36,26 +36,28 @@ pub async fn send_messages(
3636 ws_write : Arc < Mutex < SplitSink < WebSocketStream < MaybeTlsStream < TcpStream > > , Message > > > ,
3737 payment_service_addr : Address ,
3838 verification_data : & [ VerificationData ] ,
39- max_fees : & [ U256 ] ,
39+ max_fee : U256 ,
4040 wallet : Wallet < SigningKey > ,
4141 mut nonce : U256 ,
4242) -> Vec < Result < NoncedVerificationData , SubmitError > > {
4343 let chain_id = U256 :: from ( wallet. chain_id ( ) ) ;
4444 let mut ws_write = ws_write. lock ( ) . await ;
4545 let mut sent_verification_data: Vec < Result < NoncedVerificationData , SubmitError > > = Vec :: new ( ) ;
4646
47- for ( idx, verification_data ) in verification_data. iter ( ) . enumerate ( ) {
47+ for ( idx, verification_data_i ) in verification_data. iter ( ) . enumerate ( ) {
4848 // Build each message to send
4949 let verification_data = NoncedVerificationData :: new (
50- verification_data . clone ( ) ,
50+ verification_data_i . clone ( ) ,
5151 nonce,
52- max_fees [ idx ] ,
52+ max_fee ,
5353 chain_id,
5454 payment_service_addr,
5555 ) ;
5656
5757 nonce += U256 :: one ( ) ;
58- let msg = ClientMessage :: new ( verification_data. clone ( ) , wallet. clone ( ) ) . await ;
58+ let data = SubmitProofMessage :: new ( verification_data. clone ( ) , wallet. clone ( ) ) . await ;
59+ let msg = ClientMessage :: SubmitProof ( Box :: new ( data) ) ;
60+
5961 let msg_bin = match cbor_serialize ( & msg) {
6062 Ok ( bin) => bin,
6163 Err ( e) => {
@@ -168,49 +170,52 @@ pub async fn receive(
168170async fn handle_batcher_response ( msg : Message ) -> Result < BatchInclusionData , SubmitError > {
169171 let data = msg. into_data ( ) ;
170172 match cbor_deserialize ( data. as_slice ( ) ) {
171- Ok ( ResponseMessage :: BatchInclusionData ( batch_inclusion_data) ) => {
173+ Ok ( SubmitProofResponseMessage :: BatchInclusionData ( batch_inclusion_data) ) => {
172174 //OK case. Proofs was valid and it was included in this batch.
173175 Ok ( batch_inclusion_data)
174176 }
175- Ok ( ResponseMessage :: InvalidNonce ) => {
177+ Ok ( SubmitProofResponseMessage :: InvalidNonce ) => {
176178 error ! ( "Batcher responded with invalid nonce" ) ;
177179 Err ( SubmitError :: InvalidNonce )
178180 }
179- Ok ( ResponseMessage :: InvalidSignature ) => {
181+ Ok ( SubmitProofResponseMessage :: InvalidSignature ) => {
180182 error ! ( "Batcher responded with invalid signature" ) ;
181183 Err ( SubmitError :: InvalidSignature )
182184 }
183- Ok ( ResponseMessage :: ProofTooLarge ) => {
185+ Ok ( SubmitProofResponseMessage :: ProofTooLarge ) => {
184186 error ! ( "Batcher responded with proof too large" ) ;
185187 Err ( SubmitError :: ProofTooLarge )
186188 }
187- Ok ( ResponseMessage :: InvalidMaxFee ) => {
189+ Ok ( SubmitProofResponseMessage :: InvalidMaxFee ) => {
188190 error ! ( "Batcher responded with invalid max fee" ) ;
189191 Err ( SubmitError :: InvalidMaxFee )
190192 }
191- Ok ( ResponseMessage :: InsufficientBalance ( addr) ) => {
193+ Ok ( SubmitProofResponseMessage :: InsufficientBalance ( addr) ) => {
192194 error ! ( "Batcher responded with insufficient balance" ) ;
193195 Err ( SubmitError :: InsufficientBalance ( addr) )
194196 }
195- Ok ( ResponseMessage :: InvalidChainId ) => {
197+ Ok ( SubmitProofResponseMessage :: InvalidChainId ) => {
196198 error ! ( "Batcher responded with invalid chain id" ) ;
197199 Err ( SubmitError :: InvalidChainId )
198200 }
199- Ok ( ResponseMessage :: InvalidReplacementMessage ) => {
201+ Ok ( SubmitProofResponseMessage :: InvalidReplacementMessage ) => {
200202 error ! ( "Batcher responded with invalid replacement message" ) ;
201203 Err ( SubmitError :: InvalidReplacementMessage )
202204 }
203- Ok ( ResponseMessage :: AddToBatchError ) => {
205+ Ok ( SubmitProofResponseMessage :: AddToBatchError ) => {
204206 error ! ( "Batcher responded with add to batch error" ) ;
205207 Err ( SubmitError :: AddToBatchError )
206208 }
207- Ok ( ResponseMessage :: EthRpcError ) => {
209+ Ok ( SubmitProofResponseMessage :: EthRpcError ) => {
208210 error ! ( "Batcher experienced Eth RPC connection error" ) ;
209211 Err ( SubmitError :: EthereumProviderError (
210212 "Batcher experienced Eth RPC connection error" . to_string ( ) ,
211213 ) )
212214 }
213- Ok ( ResponseMessage :: InvalidPaymentServiceAddress ( received_addr, expected_addr) ) => {
215+ Ok ( SubmitProofResponseMessage :: InvalidPaymentServiceAddress (
216+ received_addr,
217+ expected_addr,
218+ ) ) => {
214219 error ! (
215220 "Batcher responded with invalid payment service address: {:?}, expected: {:?}" ,
216221 received_addr, expected_addr
@@ -220,11 +225,11 @@ async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, Sub
220225 expected_addr,
221226 ) )
222227 }
223- Ok ( ResponseMessage :: InvalidProof ( reason) ) => {
228+ Ok ( SubmitProofResponseMessage :: InvalidProof ( reason) ) => {
224229 error ! ( "Batcher responded with invalid proof: {}" , reason) ;
225230 Err ( SubmitError :: InvalidProof ( reason) )
226231 }
227- Ok ( ResponseMessage :: CreateNewTaskError ( merkle_root, error) ) => {
232+ Ok ( SubmitProofResponseMessage :: CreateNewTaskError ( merkle_root, error) ) => {
228233 error ! ( "Batcher responded with create new task error: {}" , error) ;
229234 Err ( SubmitError :: BatchSubmissionFailed (
230235 "Could not create task with merkle root " . to_owned ( )
@@ -233,18 +238,18 @@ async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, Sub
233238 + & error,
234239 ) )
235240 }
236- Ok ( ResponseMessage :: ProtocolVersion ( _) ) => {
241+ Ok ( SubmitProofResponseMessage :: ProtocolVersion ( _) ) => {
237242 error ! ( "Batcher responded with protocol version instead of batch inclusion data" ) ;
238243 Err ( SubmitError :: UnexpectedBatcherResponse (
239244 "Batcher responded with protocol version instead of batch inclusion data"
240245 . to_string ( ) ,
241246 ) )
242247 }
243- Ok ( ResponseMessage :: BatchReset ) => {
248+ Ok ( SubmitProofResponseMessage :: BatchReset ) => {
244249 error ! ( "Batcher responded with batch reset" ) ;
245250 Err ( SubmitError :: ProofQueueFlushed )
246251 }
247- Ok ( ResponseMessage :: Error ( e) ) => {
252+ Ok ( SubmitProofResponseMessage :: Error ( e) ) => {
248253 error ! ( "Batcher responded with error: {}" , e) ;
249254 Err ( SubmitError :: GenericError ( e) )
250255 }
0 commit comments