mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
defer session create
This commit is contained in:
@@ -4,7 +4,6 @@ import { DateTimeTransformer } from '../utils/DateTimeTransformer';
|
|||||||
import { TrackedEntity } from '../utils/TrackedEntity.entity';
|
import { TrackedEntity } from '../utils/TrackedEntity.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
@Index(['address', 'clientName', 'sessionId'], { unique: true })
|
|
||||||
export class ClientEntity extends TrackedEntity {
|
export class ClientEntity extends TrackedEntity {
|
||||||
|
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
@@ -20,7 +19,8 @@ export class ClientEntity extends TrackedEntity {
|
|||||||
@Column({ length: 128, type: 'varchar', nullable: true })
|
@Column({ length: 128, type: 'varchar', nullable: true })
|
||||||
userAgent: string;
|
userAgent: string;
|
||||||
|
|
||||||
@Column({ length: 8, type: 'varchar' })
|
@Index()
|
||||||
|
@Column({ length: 8, type: 'varchar', unique: true })
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
|
|
||||||
@Column({ type: 'datetime', transformer: new DateTimeTransformer() })
|
@Column({ type: 'datetime', transformer: new DateTimeTransformer() })
|
||||||
|
|||||||
@@ -111,12 +111,7 @@ export class StratumV1Client {
|
|||||||
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}, ${this.socket.remoteAddress}:${this.socket.remotePort}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (parsedMessage.method) {
|
switch (parsedMessage.method) {
|
||||||
case eRequestMethod.SUBSCRIBE: {
|
case eRequestMethod.SUBSCRIBE: {
|
||||||
@@ -133,6 +128,14 @@ export class StratumV1Client {
|
|||||||
const errors = await validate(subscriptionMessage, validatorOptions);
|
const errors = await validate(subscriptionMessage, validatorOptions);
|
||||||
|
|
||||||
if (errors.length === 0) {
|
if (errors.length === 0) {
|
||||||
|
|
||||||
|
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}, ${this.socket.remoteAddress}:${this.socket.remotePort}`);
|
||||||
|
}
|
||||||
|
|
||||||
this.clientSubscription = subscriptionMessage;
|
this.clientSubscription = subscriptionMessage;
|
||||||
const success = await this.write(JSON.stringify(this.clientSubscription.response(this.extraNonceAndSessionId)) + '\n');
|
const success = await this.write(JSON.stringify(this.clientSubscription.response(this.extraNonceAndSessionId)) + '\n');
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@@ -274,6 +277,7 @@ export class StratumV1Client {
|
|||||||
if (this.stratumInitialized == false) {
|
if (this.stratumInitialized == false) {
|
||||||
console.log('Submit before initalized');
|
console.log('Submit before initalized');
|
||||||
await this.socket.end();
|
await this.socket.end();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ export class StratumV1JobsService {
|
|||||||
private readonly bitcoinRpcService: BitcoinRpcService
|
private readonly bitcoinRpcService: BitcoinRpcService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
console.log(this.delay)
|
|
||||||
|
|
||||||
this.newMiningJob$ = combineLatest([this.bitcoinRpcService.newBlock$, interval(60000).pipe(delay(this.delay), startWith(-1))]).pipe(
|
this.newMiningJob$ = combineLatest([this.bitcoinRpcService.newBlock$, interval(60000).pipe(delay(this.delay), startWith(-1))]).pipe(
|
||||||
switchMap(([miningInfo, interval]) => {
|
switchMap(([miningInfo, interval]) => {
|
||||||
return from(this.bitcoinRpcService.getBlockTemplate()).pipe(map((blockTemplate) => {
|
return from(this.bitcoinRpcService.getBlockTemplate()).pipe(map((blockTemplate) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user