@@ -143,7 +143,7 @@ protected virtual async Task OnAuthorizeAsync(StratumConnection connection, Time
143143
144144 banManager . Ban ( connection . RemoteEndpoint . Address , loginFailureBanTimeout ) ;
145145
146- CloseConnection ( connection ) ;
146+ Disconnect ( connection ) ;
147147 }
148148 }
149149
@@ -175,12 +175,10 @@ protected virtual async Task OnSubmitAsync(StratumConnection connection, Timesta
175175 else if ( ! context . IsSubscribed )
176176 throw new StratumException ( StratumError . NotSubscribed , "not subscribed" ) ;
177177
178- // submit
179178 var requestParams = request . ParamsAs < string [ ] > ( ) ;
180- var poolEndpoint = poolConfig . Ports [ connection . LocalEndpoint . Port ] ;
181179
180+ // submit
182181 var share = await manager . SubmitShareAsync ( connection , requestParams , ct ) ;
183-
184182 await connection . RespondAsync ( true , request . Id ) ;
185183
186184 // publish
@@ -197,7 +195,8 @@ protected virtual async Task OnSubmitAsync(StratumConnection connection, Timesta
197195
198196 // update client stats
199197 context . Stats . ValidShares ++ ;
200- await UpdateVarDiffAsync ( connection ) ;
198+
199+ await UpdateVarDiffAsync ( connection , false , ct ) ;
201200 }
202201
203202 catch ( StratumException ex )
@@ -315,26 +314,23 @@ private void ConfigureMinimumDiff(StratumConnection connection, BitcoinWorkerCon
315314 }
316315 }
317316
318- protected virtual Task OnNewJobAsync ( object jobParams )
317+ protected virtual async Task OnNewJobAsync ( object jobParams )
319318 {
320319 currentJobParams = jobParams ;
321320
322- logger . Info ( ( ) => "Broadcasting job" ) ;
321+ logger . Info ( ( ) => $ "Broadcasting job { ( ( object [ ] ) jobParams ) [ 0 ] } ") ;
323322
324- return Guard ( Task . WhenAll ( TaskForEach ( async connection =>
323+ await Guard ( ( ) => ForEachMinerAsync ( async ( connection , ct ) =>
325324 {
326325 var context = connection . ContextAs < BitcoinWorkerContext > ( ) ;
327326
328- if ( ! context . IsSubscribed || ! context . IsAuthorized || CloseIfDead ( connection , context ) )
329- return ;
330-
331327 // varDiff: if the client has a pending difficulty change, apply it now
332328 if ( context . ApplyPendingDifficulty ( ) )
333329 await connection . NotifyAsync ( BitcoinStratumMethods . SetDifficulty , new object [ ] { context . Difficulty } ) ;
334330
335331 // send job
336332 await connection . NotifyAsync ( BitcoinStratumMethods . MiningNotify , currentJobParams ) ;
337- } ) ) , ex => logger . Debug ( ( ) => $ " { nameof ( OnNewJobAsync ) } : { ex . Message } " ) ) ;
333+ } ) ) ;
338334 }
339335
340336 public override double HashrateFromShares ( double shares , double interval )
@@ -458,16 +454,13 @@ protected override async Task OnRequestAsync(StratumConnection connection,
458454 }
459455 }
460456
461- protected override async Task OnVarDiffUpdateAsync ( StratumConnection connection , double newDiff )
457+ protected override async Task OnVarDiffUpdateAsync ( StratumConnection connection , double newDiff , CancellationToken ct )
462458 {
463- var context = connection . ContextAs < BitcoinWorkerContext > ( ) ;
464-
465- context . EnqueueNewDifficulty ( newDiff ) ;
459+ await base . OnVarDiffUpdateAsync ( connection , newDiff , ct ) ;
466460
467- // apply immediately and notify
468- if ( context . ApplyPendingDifficulty ( ) )
461+ if ( connection . Context . ApplyPendingDifficulty ( ) )
469462 {
470- await connection . NotifyAsync ( BitcoinStratumMethods . SetDifficulty , new object [ ] { context . Difficulty } ) ;
463+ await connection . NotifyAsync ( BitcoinStratumMethods . SetDifficulty , new object [ ] { connection . Context . Difficulty } ) ;
471464 await connection . NotifyAsync ( BitcoinStratumMethods . MiningNotify , currentJobParams ) ;
472465 }
473466 }
0 commit comments