@@ -143,7 +143,7 @@ protected virtual async Task OnAuthorizeAsync(StratumConnection connection, Time
143
143
144
144
banManager . Ban ( connection . RemoteEndpoint . Address , loginFailureBanTimeout ) ;
145
145
146
- CloseConnection ( connection ) ;
146
+ Disconnect ( connection ) ;
147
147
}
148
148
}
149
149
@@ -175,12 +175,10 @@ protected virtual async Task OnSubmitAsync(StratumConnection connection, Timesta
175
175
else if ( ! context . IsSubscribed )
176
176
throw new StratumException ( StratumError . NotSubscribed , "not subscribed" ) ;
177
177
178
- // submit
179
178
var requestParams = request . ParamsAs < string [ ] > ( ) ;
180
- var poolEndpoint = poolConfig . Ports [ connection . LocalEndpoint . Port ] ;
181
179
180
+ // submit
182
181
var share = await manager . SubmitShareAsync ( connection , requestParams , ct ) ;
183
-
184
182
await connection . RespondAsync ( true , request . Id ) ;
185
183
186
184
// publish
@@ -197,7 +195,8 @@ protected virtual async Task OnSubmitAsync(StratumConnection connection, Timesta
197
195
198
196
// update client stats
199
197
context . Stats . ValidShares ++ ;
200
- await UpdateVarDiffAsync ( connection ) ;
198
+
199
+ await UpdateVarDiffAsync ( connection , false , ct ) ;
201
200
}
202
201
203
202
catch ( StratumException ex )
@@ -315,26 +314,23 @@ private void ConfigureMinimumDiff(StratumConnection connection, BitcoinWorkerCon
315
314
}
316
315
}
317
316
318
- protected virtual Task OnNewJobAsync ( object jobParams )
317
+ protected virtual async Task OnNewJobAsync ( object jobParams )
319
318
{
320
319
currentJobParams = jobParams ;
321
320
322
- logger . Info ( ( ) => "Broadcasting job" ) ;
321
+ logger . Info ( ( ) => $ "Broadcasting job { ( ( object [ ] ) jobParams ) [ 0 ] } ") ;
323
322
324
- return Guard ( Task . WhenAll ( TaskForEach ( async connection =>
323
+ await Guard ( ( ) => ForEachMinerAsync ( async ( connection , ct ) =>
325
324
{
326
325
var context = connection . ContextAs < BitcoinWorkerContext > ( ) ;
327
326
328
- if ( ! context . IsSubscribed || ! context . IsAuthorized || CloseIfDead ( connection , context ) )
329
- return ;
330
-
331
327
// varDiff: if the client has a pending difficulty change, apply it now
332
328
if ( context . ApplyPendingDifficulty ( ) )
333
329
await connection . NotifyAsync ( BitcoinStratumMethods . SetDifficulty , new object [ ] { context . Difficulty } ) ;
334
330
335
331
// send job
336
332
await connection . NotifyAsync ( BitcoinStratumMethods . MiningNotify , currentJobParams ) ;
337
- } ) ) , ex => logger . Debug ( ( ) => $ " { nameof ( OnNewJobAsync ) } : { ex . Message } " ) ) ;
333
+ } ) ) ;
338
334
}
339
335
340
336
public override double HashrateFromShares ( double shares , double interval )
@@ -458,16 +454,13 @@ protected override async Task OnRequestAsync(StratumConnection connection,
458
454
}
459
455
}
460
456
461
- protected override async Task OnVarDiffUpdateAsync ( StratumConnection connection , double newDiff )
457
+ protected override async Task OnVarDiffUpdateAsync ( StratumConnection connection , double newDiff , CancellationToken ct )
462
458
{
463
- var context = connection . ContextAs < BitcoinWorkerContext > ( ) ;
464
-
465
- context . EnqueueNewDifficulty ( newDiff ) ;
459
+ await base . OnVarDiffUpdateAsync ( connection , newDiff , ct ) ;
466
460
467
- // apply immediately and notify
468
- if ( context . ApplyPendingDifficulty ( ) )
461
+ if ( connection . Context . ApplyPendingDifficulty ( ) )
469
462
{
470
- await connection . NotifyAsync ( BitcoinStratumMethods . SetDifficulty , new object [ ] { context . Difficulty } ) ;
463
+ await connection . NotifyAsync ( BitcoinStratumMethods . SetDifficulty , new object [ ] { connection . Context . Difficulty } ) ;
471
464
await connection . NotifyAsync ( BitcoinStratumMethods . MiningNotify , currentJobParams ) ;
472
465
}
473
466
}
0 commit comments