mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
getSuggestedDifficulty bug
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ const ORMModules = [
|
|||||||
synchronize: true,
|
synchronize: true,
|
||||||
autoLoadEntities: true,
|
autoLoadEntities: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
logging: false,
|
logging: true,
|
||||||
enableWAL: true,
|
enableWAL: true,
|
||||||
busyTimeout: 30 * 1000,
|
busyTimeout: 30 * 1000,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -75,13 +75,13 @@ export class StratumV1Client {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
this.sessionStart = new Date();
|
|
||||||
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService, this.clientService);
|
|
||||||
this.extraNonceAndSessionId = this.getRandomHexString();
|
|
||||||
console.log(`New client ID: : ${this.extraNonceAndSessionId}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public async destroy() {
|
||||||
|
|
||||||
|
await this.clientService.delete(this.extraNonceAndSessionId);
|
||||||
|
|
||||||
if (this.stratumSubscription != null) {
|
if (this.stratumSubscription != null) {
|
||||||
this.stratumSubscription.unsubscribe();
|
this.stratumSubscription.unsubscribe();
|
||||||
}
|
}
|
||||||
@@ -99,18 +99,24 @@ export class StratumV1Client {
|
|||||||
|
|
||||||
|
|
||||||
private async handleMessage(message: string) {
|
private async handleMessage(message: string) {
|
||||||
// console.log(`Received from ${this.extraNonceAndSessionId}`, message);
|
console.log(`Received from ${this.extraNonceAndSessionId}`, message);
|
||||||
|
|
||||||
// Parse the message and check if it's the initial subscription message
|
// Parse the message and check if it's the initial subscription message
|
||||||
let parsedMessage = null;
|
let parsedMessage = null;
|
||||||
try {
|
try {
|
||||||
parsedMessage = JSON.parse(message);
|
parsedMessage = JSON.parse(message);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Invalid JSON");
|
//console.log("Invalid JSON");
|
||||||
await this.socket.end();
|
await this.socket.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.sessionStart == null) {
|
||||||
|
this.sessionStart = new Date();
|
||||||
|
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService, this.clientService);
|
||||||
|
this.extraNonceAndSessionId = this.getRandomHexString();
|
||||||
|
console.log(`New client ID: : ${this.extraNonceAndSessionId}`);
|
||||||
|
}
|
||||||
|
|
||||||
switch (parsedMessage.method) {
|
switch (parsedMessage.method) {
|
||||||
case eRequestMethod.SUBSCRIBE: {
|
case eRequestMethod.SUBSCRIBE: {
|
||||||
@@ -264,6 +270,13 @@ export class StratumV1Client {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case eRequestMethod.SUBMIT: {
|
case eRequestMethod.SUBMIT: {
|
||||||
|
|
||||||
|
if (this.stratumInitialized == false) {
|
||||||
|
console.log('Submit before initalized');
|
||||||
|
await this.socket.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const miningSubmitMessage = plainToInstance(
|
const miningSubmitMessage = plainToInstance(
|
||||||
MiningSubmitMessage,
|
MiningSubmitMessage,
|
||||||
parsedMessage,
|
parsedMessage,
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ export class StratumV1ClientStatistics {
|
|||||||
public getSuggestedDifficulty(clientDifficulty: number) {
|
public getSuggestedDifficulty(clientDifficulty: number) {
|
||||||
|
|
||||||
// miner hasn't submitted shares in one minute
|
// miner hasn't submitted shares in one minute
|
||||||
if (this.submissionCache.length == 0 || (new Date().getTime() - this.submissionCacheStart.getTime()) / 1000 > 60) {
|
if (this.submissionCache.length == 0) {
|
||||||
|
if ((new Date().getTime() - this.submissionCacheStart.getTime()) / 1000 > 60) {
|
||||||
return this.nearestPowerOfTwo(clientDifficulty >> 1);
|
return this.nearestPowerOfTwo(clientDifficulty >> 1);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.submissionCache.length < CACHE_SIZE) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const sum = this.submissionCache.reduce((pre, cur) => {
|
const sum = this.submissionCache.reduce((pre, cur) => {
|
||||||
pre += cur.difficulty;
|
pre += cur.difficulty;
|
||||||
|
|||||||
@@ -36,11 +36,8 @@ export class AppService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cron(CronExpression.EVERY_5_MINUTES)
|
@Cron(CronExpression.EVERY_SECOND)
|
||||||
private async killDeadClients() {
|
private async killDeadClients() {
|
||||||
|
|
||||||
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
|
||||||
await this.clientService.killDeadClients();
|
await this.clientService.killDeadClients();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -58,28 +58,20 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
|
|
||||||
socket.on('end', async (error: Error) => {
|
socket.on('end', async (error: Error) => {
|
||||||
|
if (client.extraNonceAndSessionId != null) {
|
||||||
// Handle socket disconnection
|
// Handle socket disconnection
|
||||||
client.destroy();
|
await client.destroy();
|
||||||
|
console.log(`Client disconnected, ${client.extraNonceAndSessionId}`);
|
||||||
await this.clientService.delete(client.extraNonceAndSessionId);
|
}
|
||||||
|
|
||||||
const clientCount = await this.clientService.connectedClientCount();
|
|
||||||
|
|
||||||
console.log(`Client disconnected, ${client.extraNonceAndSessionId}, ${clientCount} total clients`);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('error', async (error: Error) => {
|
socket.on('error', async (error: Error) => {
|
||||||
|
if (client.extraNonceAndSessionId != null) {
|
||||||
client.destroy();
|
await client.destroy();
|
||||||
|
console.log(`Client disconnected, socket error, ${client.extraNonceAndSessionId}`);
|
||||||
await this.clientService.delete(client.extraNonceAndSessionId);
|
}
|
||||||
|
|
||||||
const clientCount = await this.clientService.connectedClientCount();
|
|
||||||
console.log(`Client disconnected, socket error, ${client.extraNonceAndSessionId}, ${clientCount} total clients`);
|
|
||||||
|
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user