mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
separate background tasks
This commit is contained in:
@@ -27,7 +27,7 @@ export class MiningJob {
|
|||||||
jobTemplate: IJobTemplate
|
jobTemplate: IJobTemplate
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.jobTemplateId = jobTemplate.blockData.id,
|
this.jobTemplateId = jobTemplate.blockData.id;
|
||||||
|
|
||||||
this.coinbaseTransaction = this.createCoinbaseTransaction(payoutInformation, jobTemplate.blockData.coinbasevalue);
|
this.coinbaseTransaction = this.createCoinbaseTransaction(payoutInformation, jobTemplate.blockData.coinbasevalue);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { validate, ValidatorOptions } from 'class-validator';
|
|||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { Socket } from 'net';
|
import { Socket } from 'net';
|
||||||
import { firstValueFrom, Subscription } from 'rxjs';
|
import { firstValueFrom, Subscription } from 'rxjs';
|
||||||
|
import { clearInterval } from 'timers';
|
||||||
|
|
||||||
import { AddressSettingsService } from '../ORM/address-settings/address-settings.service';
|
import { AddressSettingsService } from '../ORM/address-settings/address-settings.service';
|
||||||
import { BlocksService } from '../ORM/blocks/blocks.service';
|
import { BlocksService } from '../ORM/blocks/blocks.service';
|
||||||
@@ -35,7 +36,7 @@ export class StratumV1Client {
|
|||||||
private clientAuthorization: AuthorizationMessage;
|
private clientAuthorization: AuthorizationMessage;
|
||||||
private clientSuggestedDifficulty: SuggestDifficulty;
|
private clientSuggestedDifficulty: SuggestDifficulty;
|
||||||
private stratumSubscription: Subscription;
|
private stratumSubscription: Subscription;
|
||||||
private backgroundWork: NodeJS.Timer;
|
private backgroundWork: NodeJS.Timer[] = [];
|
||||||
|
|
||||||
private statistics: StratumV1ClientStatistics;
|
private statistics: StratumV1ClientStatistics;
|
||||||
private stratumInitialized = false;
|
private stratumInitialized = false;
|
||||||
@@ -87,9 +88,10 @@ export class StratumV1Client {
|
|||||||
if (this.stratumSubscription != null) {
|
if (this.stratumSubscription != null) {
|
||||||
this.stratumSubscription.unsubscribe();
|
this.stratumSubscription.unsubscribe();
|
||||||
}
|
}
|
||||||
if (this.backgroundWork != null) {
|
|
||||||
clearInterval(this.backgroundWork);
|
this.backgroundWork.forEach(work => {
|
||||||
}
|
clearInterval(work);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRandomHexString() {
|
private getRandomHexString() {
|
||||||
@@ -333,6 +335,12 @@ export class StratumV1Client {
|
|||||||
&& this.clientAuthorization != null
|
&& this.clientAuthorization != null
|
||||||
&& this.stratumInitialized == false) {
|
&& this.stratumInitialized == false) {
|
||||||
|
|
||||||
|
await this.initStratum();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async initStratum() {
|
||||||
this.stratumInitialized = true;
|
this.stratumInitialized = true;
|
||||||
|
|
||||||
switch (this.clientSubscription.userAgent) {
|
switch (this.clientSubscription.userAgent) {
|
||||||
@@ -341,7 +349,6 @@ export class StratumV1Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (this.clientSuggestedDifficulty == null) {
|
if (this.clientSuggestedDifficulty == null) {
|
||||||
//console.log(`Setting difficulty to ${this.sessionDifficulty}`)
|
//console.log(`Setting difficulty to ${this.sessionDifficulty}`)
|
||||||
const setDifficulty = JSON.stringify(new SuggestDifficulty().response(this.sessionDifficulty));
|
const setDifficulty = JSON.stringify(new SuggestDifficulty().response(this.sessionDifficulty));
|
||||||
@@ -351,7 +358,6 @@ export class StratumV1Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.stratumSubscription = this.stratumV1JobsService.newMiningJob$.subscribe(async (jobTemplate) => {
|
this.stratumSubscription = this.stratumV1JobsService.newMiningJob$.subscribe(async (jobTemplate) => {
|
||||||
try {
|
try {
|
||||||
await this.sendNewMiningJob(jobTemplate);
|
await this.sendNewMiningJob(jobTemplate);
|
||||||
@@ -361,27 +367,30 @@ export class StratumV1Client {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.backgroundWork = setInterval(async () => {
|
this.backgroundWork.push(
|
||||||
|
setInterval(async () => {
|
||||||
await this.checkDifficulty();
|
await this.checkDifficulty();
|
||||||
await this.statistics.saveShares(this.entity);
|
}, 60 * 1000)
|
||||||
}, 60 * 1000);
|
);
|
||||||
|
|
||||||
}
|
this.backgroundWork.push(
|
||||||
|
setInterval(async () => {
|
||||||
|
await this.statistics.saveShares(this.entity);
|
||||||
|
}, 60 * 1000)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async sendNewMiningJob(jobTemplate: IJobTemplate) {
|
private async sendNewMiningJob(jobTemplate: IJobTemplate) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let payoutInformation;
|
let payoutInformation;
|
||||||
const devFeeAddress = this.configService.get('DEV_FEE_ADDRESS');
|
const devFeeAddress = this.configService.get('DEV_FEE_ADDRESS');
|
||||||
//50Th/s
|
//50Th/s
|
||||||
this.noFee = false;
|
this.noFee = devFeeAddress == null || devFeeAddress.length < 1;
|
||||||
if (this.entity) {
|
if (this.noFee == false && this.entity) {
|
||||||
this.hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonceAndSessionId);
|
this.hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonceAndSessionId);
|
||||||
this.noFee = this.hashRate != 0 && this.hashRate < 50000000000000;
|
this.noFee = this.hashRate != 0 && this.hashRate < 50000000000000;
|
||||||
}
|
}
|
||||||
if (this.noFee || devFeeAddress == null || devFeeAddress.length < 1) {
|
if (this.noFee) {
|
||||||
payoutInformation = [
|
payoutInformation = [
|
||||||
{ address: this.clientAuthorization.address, percent: 100 }
|
{ address: this.clientAuthorization.address, percent: 100 }
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user