optimizations and cleanup

This commit is contained in:
Ben Wilson 2023-08-07 23:12:52 -04:00
parent 14f6d5802f
commit b1cfe07222
3 changed files with 15 additions and 15 deletions

View File

@ -115,7 +115,7 @@ 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}`);
console.log(`New client ID: : ${this.extraNonceAndSessionId}, ${this.socket.remoteAddress}:${this.socket.remotePort}`);
}
switch (parsedMessage.method) {
@ -331,7 +331,7 @@ export class StratumV1Client {
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 success = await this.write(setDifficulty + '\n');
if (!success) {
@ -521,7 +521,7 @@ export class StratumV1Client {
}
if (targetDiff != this.sessionDifficulty) {
console.log(`Adjusting difficulty from ${this.sessionDifficulty} to ${targetDiff}`);
console.log(`Adjusting ${this.extraNonceAndSessionId} difficulty from ${this.sessionDifficulty} to ${targetDiff}`);
this.sessionDifficulty = targetDiff;
const data = JSON.stringify({

View File

@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import * as bitcoinjs from 'bitcoinjs-lib';
import * as merkle from 'merkle-lib';
import * as merkleProof from 'merkle-lib/proof';
import { combineLatest, filter, from, interval, map, Observable, shareReplay, startWith, switchMap, tap } from 'rxjs';
import { combineLatest, delay, filter, from, interval, map, Observable, shareReplay, startWith, switchMap, tap } from 'rxjs';
import { MiningJob } from '../models/MiningJob';
import { BitcoinRpcService } from './bitcoin-rpc.service';
@ -35,11 +35,16 @@ export class StratumV1JobsService {
public blocks: { [id: number]: IJobTemplate } = {};
// offset the interval so that all the cluster processes don't try and refresh at the same time.
private delay = process.env.NODE_APP_INSTANCE == null ? 0 : parseInt(process.env.NODE_APP_INSTANCE) * 5000;
constructor(
private readonly bitcoinRpcService: BitcoinRpcService
) {
this.newMiningJob$ = combineLatest([this.bitcoinRpcService.newBlock$, interval(60000).pipe(startWith(-1))]).pipe(
console.log(this.delay)
this.newMiningJob$ = combineLatest([this.bitcoinRpcService.newBlock$, interval(60000).pipe(delay(this.delay), startWith(-1))]).pipe(
switchMap(([miningInfo, interval]) => {
return from(this.bitcoinRpcService.getBlockTemplate()).pipe(map((blockTemplate) => {
return {

View File

@ -57,23 +57,18 @@ export class StratumV1Service implements OnModuleInit {
);
socket.on('end', async (error: Error) => {
socket.on('close', async (hadError: boolean) => {
if (client.extraNonceAndSessionId != null) {
// Handle socket disconnection
await client.destroy();
console.log(`Client disconnected, ${client.extraNonceAndSessionId}`);
console.log(`Client ${client.extraNonceAndSessionId} disconnected, hadError?:${hadError}`);
}
});
socket.on('error', async (error: Error) => {
if (client.extraNonceAndSessionId != null) {
await client.destroy();
console.log(`Client disconnected, socket error, ${client.extraNonceAndSessionId}`);
}
socket.on('error', async (error: Error) => { });
// //console.log(`Client disconnected, socket error, ${client.extraNonceAndSessionId}`);
socket.destroy();
});
});