mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
WITHOUT ROWID
This commit is contained in:
@@ -1,27 +1,32 @@
|
|||||||
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, Entity, Index, PrimaryColumn } from 'typeorm';
|
||||||
|
|
||||||
import { DateTimeTransformer } from '../utils/DateTimeTransformer';
|
import { DateTimeTransformer } from '../utils/DateTimeTransformer';
|
||||||
import { TrackedEntity } from '../utils/TrackedEntity.entity';
|
import { TrackedEntity } from '../utils/TrackedEntity.entity';
|
||||||
|
|
||||||
@Entity()
|
//https://www.sqlite.org/withoutrowid.html
|
||||||
|
|
||||||
|
//The WITHOUT ROWID optimization is likely to be helpful for tables that have non-integer
|
||||||
|
// or composite (multi-column) PRIMARY KEYs and that do not store large strings or BLOBs.
|
||||||
|
//WITHOUT ROWID tables work best when individual rows are not too large.
|
||||||
|
@Entity({ withoutRowid: true })
|
||||||
|
@Index(['address', 'clientName', 'sessionId'], { unique: true })
|
||||||
export class ClientEntity extends TrackedEntity {
|
export class ClientEntity extends TrackedEntity {
|
||||||
|
|
||||||
@PrimaryGeneratedColumn()
|
|
||||||
id: number;
|
|
||||||
|
|
||||||
|
@PrimaryColumn({ length: 62, type: 'varchar' })
|
||||||
@Column({ length: 62, type: 'varchar' })
|
|
||||||
address: string;
|
address: string;
|
||||||
|
|
||||||
@Column({ length: 64, type: 'varchar' })
|
@PrimaryColumn({ length: 64, type: 'varchar' })
|
||||||
clientName: string;
|
clientName: string;
|
||||||
|
|
||||||
|
@PrimaryColumn({ length: 8, type: 'varchar' })
|
||||||
|
sessionId: string;
|
||||||
|
|
||||||
|
|
||||||
@Column({ length: 128, type: 'varchar', nullable: true })
|
@Column({ length: 128, type: 'varchar', nullable: true })
|
||||||
userAgent: string;
|
userAgent: string;
|
||||||
|
|
||||||
@Index()
|
|
||||||
@Column({ length: 8, type: 'varchar', unique: true })
|
|
||||||
sessionId: string;
|
|
||||||
|
|
||||||
@Column({ type: 'datetime', transformer: new DateTimeTransformer() })
|
@Column({ type: 'datetime', transformer: new DateTimeTransformer() })
|
||||||
startTime: Date;
|
startTime: Date;
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ export class StratumV1Client {
|
|||||||
private stratumInitialized = false;
|
private stratumInitialized = false;
|
||||||
private usedSuggestedDifficulty = false;
|
private usedSuggestedDifficulty = false;
|
||||||
private sessionDifficulty: number = 16384;
|
private sessionDifficulty: number = 16384;
|
||||||
|
|
||||||
private entity: ClientEntity;
|
private entity: ClientEntity;
|
||||||
|
private creatingEntity: Promise<void>;
|
||||||
|
|
||||||
public extraNonceAndSessionId: string;
|
public extraNonceAndSessionId: string;
|
||||||
public sessionStart: Date;
|
public sessionStart: Date;
|
||||||
@@ -416,14 +418,27 @@ export class StratumV1Client {
|
|||||||
private async handleMiningSubmission(submission: MiningSubmitMessage) {
|
private async handleMiningSubmission(submission: MiningSubmitMessage) {
|
||||||
|
|
||||||
if (this.entity == null) {
|
if (this.entity == null) {
|
||||||
this.entity = await this.clientService.insert({
|
if (this.creatingEntity == null) {
|
||||||
sessionId: this.extraNonceAndSessionId,
|
this.creatingEntity = new Promise(async (resolve, reject) => {
|
||||||
address: this.clientAuthorization.address,
|
try {
|
||||||
clientName: this.clientAuthorization.worker,
|
this.entity = await this.clientService.insert({
|
||||||
userAgent: this.clientSubscription.userAgent,
|
sessionId: this.extraNonceAndSessionId,
|
||||||
startTime: new Date(),
|
address: this.clientAuthorization.address,
|
||||||
bestDifficulty: 0
|
clientName: this.clientAuthorization.worker,
|
||||||
});
|
userAgent: this.clientSubscription.userAgent,
|
||||||
|
startTime: new Date(),
|
||||||
|
bestDifficulty: 0
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
await this.creatingEntity;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
await this.creatingEntity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,11 +42,6 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
private startSocketServer() {
|
private startSocketServer() {
|
||||||
const server = new Server(async (socket: Socket) => {
|
const server = new Server(async (socket: Socket) => {
|
||||||
|
|
||||||
// socket.setTimeout(5000, () => {
|
|
||||||
// console.log(`Client ${client.extraNonceAndSessionId} timeout`);
|
|
||||||
// socket.destroy();
|
|
||||||
// });
|
|
||||||
|
|
||||||
const client = new StratumV1Client(
|
const client = new StratumV1Client(
|
||||||
socket,
|
socket,
|
||||||
this.stratumV1JobsService,
|
this.stratumV1JobsService,
|
||||||
|
|||||||
Reference in New Issue
Block a user