mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Isolate API process from mining workers
This commit is contained in:
@@ -1,12 +1,28 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [
|
apps: [
|
||||||
|
// API instance
|
||||||
|
{
|
||||||
|
name: 'api',
|
||||||
|
script: './dist/main.js',
|
||||||
|
instances: 1,
|
||||||
|
exec_mode: 'fork',
|
||||||
|
env: {
|
||||||
|
MASTER: 'false',
|
||||||
|
API_ONLY: 'true',
|
||||||
|
API_ENABLED: 'true',
|
||||||
|
NODE_CLUSTER_SCHED_POLICY: 'none',
|
||||||
|
},
|
||||||
|
time: true
|
||||||
|
},
|
||||||
// Master instance
|
// Master instance
|
||||||
{
|
{
|
||||||
name: 'master',
|
name: 'master',
|
||||||
script: './dist/main.js',
|
script: './dist/main.js',
|
||||||
instances: 1,
|
instances: 1,
|
||||||
|
exec_mode: 'fork',
|
||||||
env: {
|
env: {
|
||||||
MASTER: 'true',
|
MASTER: 'true',
|
||||||
|
API_ENABLED: 'false',
|
||||||
NODE_CLUSTER_SCHED_POLICY: 'none',
|
NODE_CLUSTER_SCHED_POLICY: 'none',
|
||||||
},
|
},
|
||||||
time: true
|
time: true
|
||||||
@@ -19,6 +35,7 @@ module.exports = {
|
|||||||
exec_mode: "cluster",
|
exec_mode: "cluster",
|
||||||
env: {
|
env: {
|
||||||
MASTER: 'false',
|
MASTER: 'false',
|
||||||
|
API_ENABLED: 'false',
|
||||||
NODE_CLUSTER_SCHED_POLICY: 'none',
|
NODE_CLUSTER_SCHED_POLICY: 'none',
|
||||||
},
|
},
|
||||||
time: true
|
time: true
|
||||||
|
|||||||
+2
-1
@@ -15,7 +15,8 @@ async function bootstrap() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const serveApi = process.env.MASTER !== 'false';
|
const apiEnabled = process.env.API_ENABLED?.toLowerCase();
|
||||||
|
const serveApi = apiEnabled == null ? process.env.MASTER !== 'false' : apiEnabled === 'true';
|
||||||
const secure = serveApi && process.env.API_SECURE?.toLowerCase() === 'true';
|
const secure = serveApi && process.env.API_SECURE?.toLowerCase() === 'true';
|
||||||
const currentDirectory = process.cwd();
|
const currentDirectory = process.cwd();
|
||||||
const keyPath = path.join(currentDirectory, 'secrets', 'key.pem');
|
const keyPath = path.join(currentDirectory, 'secrets', 'key.pem');
|
||||||
|
|||||||
@@ -47,6 +47,23 @@ export class BitcoinRpcService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`MASTER? ${process.env.MASTER}`)
|
||||||
|
if (process.env.MASTER != 'true') {
|
||||||
|
await this.loadLatestMiningInfoForReplayProcess();
|
||||||
|
if (process.env.API_ONLY != 'true') {
|
||||||
|
await this.loadLatestTemplateForWorker();
|
||||||
|
}
|
||||||
|
await this.redisMessagingService.subscribeMiningInfoUpdates(async (miningInfo: IMiningInfo) => {
|
||||||
|
this.miningInfo = miningInfo;
|
||||||
|
if (process.env.API_ONLY != 'true') {
|
||||||
|
await this.loadTemplateForWorker(miningInfo.blocks);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (process.env.API_ONLY == 'true') {
|
||||||
|
console.log('API-only process using Redis mining info replay');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
this.callRpc('getrpcinfo').then((res) => {
|
this.callRpc('getrpcinfo').then((res) => {
|
||||||
console.log('Bitcoin RPC connected');
|
console.log('Bitcoin RPC connected');
|
||||||
}, () => {
|
}, () => {
|
||||||
@@ -54,15 +71,6 @@ export class BitcoinRpcService implements OnModuleInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.miningInfo = await this.getMiningInfo();
|
this.miningInfo = await this.getMiningInfo();
|
||||||
|
|
||||||
console.log(`MASTER? ${process.env.MASTER}`)
|
|
||||||
if (process.env.MASTER != 'true') {
|
|
||||||
await this.loadLatestTemplateForWorker();
|
|
||||||
await this.redisMessagingService.subscribeMiningInfoUpdates(async (miningInfo: IMiningInfo) => {
|
|
||||||
this.miningInfo = miningInfo;
|
|
||||||
await this.loadTemplateForWorker(miningInfo.blocks);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log('Using ZMQ');
|
console.log('Using ZMQ');
|
||||||
const sock = new zmq.Subscriber;
|
const sock = new zmq.Subscriber;
|
||||||
|
|
||||||
@@ -91,6 +99,13 @@ export class BitcoinRpcService implements OnModuleInit {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async loadLatestMiningInfoForReplayProcess() {
|
||||||
|
const latestMiningInfo = await this.redisMessagingService.getLatestMiningInfo();
|
||||||
|
if (latestMiningInfo != null) {
|
||||||
|
this.miningInfo = latestMiningInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async listenForNewBlocks(sock: zmq.Subscriber) {
|
private async listenForNewBlocks(sock: zmq.Subscriber) {
|
||||||
for await (const [topic, msg] of sock) {
|
for await (const [topic, msg] of sock) {
|
||||||
console.log("New Block");
|
console.log("New Block");
|
||||||
|
|||||||
@@ -68,6 +68,11 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
async onModuleInit(): Promise<void> {
|
async onModuleInit(): Promise<void> {
|
||||||
|
|
||||||
|
if (process.env.API_ONLY == 'true') {
|
||||||
|
console.log('API-only process skipping Stratum socket listeners');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.MASTER == 'true') {
|
if (process.env.MASTER == 'true') {
|
||||||
await this.clientService.deleteAll();
|
await this.clientService.deleteAll();
|
||||||
await this.redisMessagingService?.clearClientPresence();
|
await this.redisMessagingService?.clearClientPresence();
|
||||||
|
|||||||
Reference in New Issue
Block a user