@@ -180,6 +180,31 @@ async def _update_proofs_count(self, challenge_weight):
180180 del self .active_discriminants_start_time [active_disc ]
181181 self .done_discriminants .append (active_disc )
182182
183+ async def send_iterations (self , challenge_hash , writer ):
184+ alive_discriminant = True
185+ while (alive_discriminant ):
186+ async with self .lock :
187+ if (challenge_hash in self .active_discriminants ) and (
188+ challenge_hash in self .pending_iters
189+ ):
190+ if challenge_hash not in self .submitted_iters :
191+ self .submitted_iters [challenge_hash ] = []
192+ for iter in sorted (self .pending_iters [challenge_hash ]):
193+ if iter in self .submitted_iters [challenge_hash ]:
194+ continue
195+ self .submitted_iters [challenge_hash ].append (iter )
196+ if len (str (iter )) < 10 :
197+ iter_size = "0" + str (len (str (iter )))
198+ else :
199+ iter_size = str (len (str (iter )))
200+ writer .write ((iter_size + str (iter )).encode ())
201+ await writer .drain ()
202+ log .info (f"New iteration submitted: { iter } " )
203+ await asyncio .sleep (3 )
204+ async with self .lock :
205+ if (challenge_hash in self .done_discriminants ):
206+ alive_discriminant = False
207+
183208 async def _do_process_communication (
184209 self , challenge_hash , challenge_weight , ip , port
185210 ):
@@ -219,29 +244,10 @@ async def _do_process_communication(
219244 self .active_discriminants [challenge_hash ] = (writer , challenge_weight , ip )
220245 self .active_discriminants_start_time [challenge_hash ] = time .time ()
221246
247+ asyncio .create_task (self .send_iterations (challenge_hash , writer ))
248+
222249 # Listen to the server until "STOP" is received.
223250 while True :
224- async with self .lock :
225- if (challenge_hash in self .active_discriminants ) and (
226- challenge_hash in self .pending_iters
227- ):
228- if challenge_hash not in self .submitted_iters :
229- self .submitted_iters [challenge_hash ] = []
230- log .info (
231- f"Pending: { self .pending_iters [challenge_hash ]} "
232- f"Submitted: { self .submitted_iters [challenge_hash ]} Hash: { challenge_hash } "
233- )
234- for iter in sorted (self .pending_iters [challenge_hash ]):
235- if iter in self .submitted_iters [challenge_hash ]:
236- continue
237- self .submitted_iters [challenge_hash ].append (iter )
238- if len (str (iter )) < 10 :
239- iter_size = "0" + str (len (str (iter )))
240- else :
241- iter_size = str (len (str (iter )))
242- writer .write ((iter_size + str (iter )).encode ())
243- await writer .drain ()
244-
245251 try :
246252 data = await reader .readexactly (4 )
247253 except (asyncio .IncompleteReadError , ConnectionResetError ) as e :
@@ -259,21 +265,6 @@ async def _do_process_communication(
259265 len_server = len (self .free_servers )
260266 log .info (f"Process ended... Server length { len_server } " )
261267 break
262- elif data .decode () == "POLL" :
263- async with self .lock :
264- # If I have a newer discriminant... Free up the VDF server
265- if (
266- len (self .discriminant_queue ) > 0
267- and challenge_weight
268- < max ([h for _ , h in self .discriminant_queue ])
269- and challenge_hash in self .active_discriminants
270- ):
271- log .info ("Got poll, stopping the challenge!" )
272- writer .write (b"010" )
273- await writer .drain ()
274- del self .active_discriminants [challenge_hash ]
275- del self .active_discriminants_start_time [challenge_hash ]
276- self .done_discriminants .append (challenge_hash )
277268 else :
278269 try :
279270 # This must be a proof, read the continuation.
0 commit comments