@@ -149,7 +149,7 @@ async def _update_avg_ips(self, challenge_hash, iterations_needed, ip):
149149 new_avg_ips = int ((prev_avg_ips * trials + ips ) / (trials + 1 ))
150150 self .avg_ips [ip ] = (new_avg_ips , trials + 1 )
151151 log .info (f"New estimate: { new_avg_ips } " )
152- # self.pending_iters[challenge_hash].remove(iterations_needed)
152+ self .pending_iters [challenge_hash ].remove (iterations_needed )
153153 else :
154154 log .info (
155155 f"Finished PoT chall:{ challenge_hash [:10 ].hex ()} .. { iterations_needed } "
@@ -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.
@@ -341,9 +332,25 @@ async def _manage_discriminant_queue(self):
341332 )
342333 self .discriminant_queue .clear ()
343334 else :
344- disc = next (
335+ max_weight_disc = [
345336 d for d , h in self .discriminant_queue if h == max_weight
346- )
337+ ]
338+ with_iters = [
339+ d for d in max_weight_disc
340+ if d in self .pending_iters
341+ and len (self .pending_iters [d ]) != 0
342+ ]
343+ if (len (with_iters ) == 0 ):
344+ disc = max_weight_disc [0 ]
345+ else :
346+ min_iter = min ([
347+ min (self .pending_iters [d ])
348+ for d in with_iters
349+ ])
350+ disc = next (
351+ d for d in with_iters
352+ if min (self .pending_iters [d ]) == min_iter
353+ )
347354 if len (self .free_servers ) != 0 :
348355 ip , port = self .free_servers [0 ]
349356 self .free_servers = self .free_servers [1 :]
@@ -415,10 +422,14 @@ async def proof_of_space_info(
415422
416423 if proof_of_space_info .challenge_hash not in self .pending_iters :
417424 self .pending_iters [proof_of_space_info .challenge_hash ] = []
425+ if proof_of_space_info .challenge_hash not in self .submitted_iters :
426+ self .submitted_iters [proof_of_space_info .challenge_hash ] = []
418427
419428 if (
420429 proof_of_space_info .iterations_needed
421430 not in self .pending_iters [proof_of_space_info .challenge_hash ]
431+ and proof_of_space_info .iterations_needed
432+ not in self .submitted_iters [proof_of_space_info .challenge_hash ]
422433 ):
423434 log .info (
424435 f"proof_of_space_info { proof_of_space_info .challenge_hash } adding "
0 commit comments