Read best difficulty in API workers

This commit is contained in:
Ben
2026-06-21 17:45:00 -04:00
parent 12f3983c8f
commit 126b05224f
2 changed files with 29 additions and 3 deletions
@@ -105,6 +105,34 @@ describe('ClientController', () => {
})); }));
}); });
it('should read address best difficulty in API-only mode', async () => {
const originalApiOnly = process.env.API_ONLY;
process.env.API_ONLY = 'true';
try {
addressSettingsService.getSettings.mockResolvedValue({ bestDifficulty: 8192 });
shareAccountingService.getSessionSummaries.mockResolvedValue(new Map());
shareAccountingService.getAddressSummary.mockResolvedValue({
totalAcceptedShares: 10,
totalCreditedDifficulty: 100,
bestSubmissionDifficulty: 0,
});
await expect(controller.getClientInfo('bc1qtest')).resolves.toEqual(expect.objectContaining({
bestDifficulty: 8192,
accounting: expect.objectContaining({
bestSubmissionDifficulty: 8192,
}),
}));
expect(addressSettingsService.getSettings).toHaveBeenCalledWith('bc1qtest', false);
} finally {
if (originalApiOnly == null) {
delete process.env.API_ONLY;
} else {
process.env.API_ONLY = originalApiOnly;
}
}
});
it('should expose the latest current PPLNS expected payout for an address', async () => { it('should expose the latest current PPLNS expected payout for an address', async () => {
addressSettingsService.getSettings.mockResolvedValue(null); addressSettingsService.getSettings.mockResolvedValue(null);
shareAccountingService.getAddressSummary.mockResolvedValue({ shareAccountingService.getAddressSummary.mockResolvedValue({
+1 -3
View File
@@ -28,9 +28,7 @@ export class ClientController {
const workers = await this.getActiveAddressWorkers(address, mode); const workers = await this.getActiveAddressWorkers(address, mode);
const sessionSummaries = await this.shareAccountingService.getSessionSummaries(workers.map(worker => worker.clientId)); const sessionSummaries = await this.shareAccountingService.getSessionSummaries(workers.map(worker => worker.clientId));
const addressSettings = process.env.API_ONLY === 'true' const addressSettings = await this.addressSettingsService.getSettings(address, false);
? null
: await this.addressSettingsService.getSettings(address, false);
const bestDifficulty = addressSettings?.bestDifficulty ?? workers.reduce((best, worker) => { const bestDifficulty = addressSettings?.bestDifficulty ?? workers.reduce((best, worker) => {
return Math.max(best, Number(worker.bestDifficulty ?? 0)); return Math.max(best, Number(worker.bestDifficulty ?? 0));
}, 0); }, 0);