From fc767fa770c89f8d1de34b60a259283c1e4b9d3c Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Sun, 14 Jan 2024 14:10:47 -0500 Subject: [PATCH] reduce heartbeat updates --- src/ORM/client/client.service.ts | 4 ++-- src/models/StratumV1Client.ts | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ORM/client/client.service.ts b/src/ORM/client/client.service.ts index 29e427d..14b6539 100644 --- a/src/ORM/client/client.service.ts +++ b/src/ORM/client/client.service.ts @@ -28,8 +28,8 @@ export class ClientService { .execute(); } - public async heartbeat(address: string, clientName: string, sessionId: string, hashRate: number) { - return await this.clientRepository.update({ address, clientName, sessionId }, { hashRate, deletedAt: null, updatedAt: new Date() }); + public async heartbeat(address: string, clientName: string, sessionId: string, hashRate: number, updatedAt: Date) { + return await this.clientRepository.update({ address, clientName, sessionId }, { hashRate, deletedAt: null, updatedAt }); } // public async save(client: Partial) { diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index 379b68e..d04e098 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -507,7 +507,13 @@ export class StratumV1Client { } try { await this.statistics.addShares(this.sessionDifficulty); - await this.clientService.heartbeat(this.entity.address, this.entity.clientName, this.entity.sessionId, this.hashRate); + const now = new Date(); + // only update every minute + if (now.getTime() - this.entity.updatedAt.getTime() > 1000 * 60) { + await this.clientService.heartbeat(this.entity.address, this.entity.clientName, this.entity.sessionId, this.hashRate, now); + this.entity.updatedAt = now; + } + } catch (e) { console.log(e); const err = new StratumErrorMessage(