defer session create

This commit is contained in:
Ben Wilson 2023-08-08 23:39:52 -04:00
parent 2e0b66577d
commit 10f6ffa91f
3 changed files with 12 additions and 10 deletions

View File

@ -4,7 +4,6 @@ import { DateTimeTransformer } from '../utils/DateTimeTransformer';
import { TrackedEntity } from '../utils/TrackedEntity.entity';
@Entity()
@Index(['address', 'clientName', 'sessionId'], { unique: true })
export class ClientEntity extends TrackedEntity {
@PrimaryGeneratedColumn()
@ -20,7 +19,8 @@ export class ClientEntity extends TrackedEntity {
@Column({ length: 128, type: 'varchar', nullable: true })
userAgent: string;
@Column({ length: 8, type: 'varchar' })
@Index()
@Column({ length: 8, type: 'varchar', unique: true })
sessionId: string;
@Column({ type: 'datetime', transformer: new DateTimeTransformer() })

View File

@ -111,12 +111,7 @@ export class StratumV1Client {
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) {
case eRequestMethod.SUBSCRIBE: {
@ -133,6 +128,14 @@ export class StratumV1Client {
const errors = await validate(subscriptionMessage, validatorOptions);
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;
const success = await this.write(JSON.stringify(this.clientSubscription.response(this.extraNonceAndSessionId)) + '\n');
if (!success) {
@ -274,6 +277,7 @@ export class StratumV1Client {
if (this.stratumInitialized == false) {
console.log('Submit before initalized');
await this.socket.end();
return;
}

View File

@ -42,8 +42,6 @@ export class StratumV1JobsService {
private readonly bitcoinRpcService: BitcoinRpcService
) {
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) => {