mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
delete old templates and jobs
This commit is contained in:
@@ -20,7 +20,7 @@ export class MiningJob {
|
|||||||
|
|
||||||
public jobTemplateId: string;
|
public jobTemplateId: string;
|
||||||
public networkDifficulty: number;
|
public networkDifficulty: number;
|
||||||
|
public creation: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
configService: ConfigService,
|
configService: ConfigService,
|
||||||
@@ -30,6 +30,7 @@ export class MiningJob {
|
|||||||
jobTemplate: IJobTemplate
|
jobTemplate: IJobTemplate
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
this.creation = new Date().getTime();
|
||||||
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);
|
||||||
|
|||||||
@@ -468,7 +468,7 @@ export class StratumV1Client {
|
|||||||
|
|
||||||
const job = this.stratumV1JobsService.getJobById(submission.jobId);
|
const job = this.stratumV1JobsService.getJobById(submission.jobId);
|
||||||
|
|
||||||
// a miner may submit a job that doesn't exist anymore if it was removed by a new block notification
|
// a miner may submit a job that doesn't exist anymore if it was removed by a new block notification (or expired, 5 min)
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
const err = new StratumErrorMessage(
|
const err = new StratumErrorMessage(
|
||||||
submission.id,
|
submission.id,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export interface IJobTemplate {
|
|||||||
merkle_branch: string[];
|
merkle_branch: string[];
|
||||||
blockData: {
|
blockData: {
|
||||||
id: string,
|
id: string,
|
||||||
|
creation: number,
|
||||||
coinbasevalue: number;
|
coinbasevalue: number;
|
||||||
networkDifficulty: number;
|
networkDifficulty: number;
|
||||||
height: number;
|
height: number;
|
||||||
@@ -114,6 +115,7 @@ export class StratumV1JobsService {
|
|||||||
merkle_branch,
|
merkle_branch,
|
||||||
blockData: {
|
blockData: {
|
||||||
id,
|
id,
|
||||||
|
creation: new Date().getTime(),
|
||||||
coinbasevalue,
|
coinbasevalue,
|
||||||
networkDifficulty,
|
networkDifficulty,
|
||||||
height,
|
height,
|
||||||
@@ -125,6 +127,20 @@ export class StratumV1JobsService {
|
|||||||
if (data.blockData.clearJobs) {
|
if (data.blockData.clearJobs) {
|
||||||
this.blocks = {};
|
this.blocks = {};
|
||||||
this.jobs = {};
|
this.jobs = {};
|
||||||
|
}else{
|
||||||
|
const now = new Date().getTime();
|
||||||
|
// Delete old templates (5 minutes)
|
||||||
|
for(const templateId in this.blocks){
|
||||||
|
if(now - this.blocks[templateId].blockData.creation > (1000 * 60 * 5)){
|
||||||
|
delete this.blocks[templateId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Delete old jobs (5 minutes)
|
||||||
|
for (const jobId in this.jobs) {
|
||||||
|
if(now - this.jobs[jobId].creation > (1000 * 60 * 5)){
|
||||||
|
delete this.jobs[jobId];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.blocks[data.blockData.id] = data;
|
this.blocks[data.blockData.id] = data;
|
||||||
}),
|
}),
|
||||||
@@ -138,7 +154,8 @@ export class StratumV1JobsService {
|
|||||||
|
|
||||||
const target: number = mantissa * Math.pow(256, (exponent - 3)); // Calculate the target value
|
const target: number = mantissa * Math.pow(256, (exponent - 3)); // Calculate the target value
|
||||||
|
|
||||||
const difficulty: number = (Math.pow(2, 208) * 65535) / target; // Calculate the difficulty
|
const maxTarget = Math.pow(2, 208) * 65535; // Easiest target (max_target)
|
||||||
|
const difficulty: number = maxTarget / target; // Calculate the difficulty
|
||||||
|
|
||||||
return difficulty;
|
return difficulty;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user