Skip to content

Commit 2ee60bc

Browse files
committed
v3.3.8
1 parent da295aa commit 2ee60bc

File tree

3 files changed

+86
-41
lines changed

3 files changed

+86
-41
lines changed

modules/master.ts

+38-11
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ export class HyperionMaster {
287287
this.total_range = this.head - msg.block_num;
288288
}
289289
},
290+
'kill_worker': (msg: any) => {
291+
for (let workersKey in cluster.workers) {
292+
const w = cluster.workers[workersKey];
293+
if (w.id === parseInt(msg.id)) {
294+
const idx = this.workerMap.findIndex(value => value.worker_id === w.id);
295+
this.workerMap.splice(idx, 1);
296+
w.kill();
297+
}
298+
}
299+
},
290300
'completed': (msg: any) => {
291301
if (msg.id === this.doctorId.toString()) {
292302
hLog('repair worker completed', msg);
@@ -645,7 +655,7 @@ export class HyperionMaster {
645655
index: new_index
646656
});
647657
} catch (e) {
648-
console.log(e);
658+
hLog(e);
649659
process.exit(1);
650660
}
651661

@@ -657,7 +667,7 @@ export class HyperionMaster {
657667
name: `${queue_prefix}-${index.type}`
658668
});
659669
} catch (e) {
660-
console.log(e);
670+
hLog(e);
661671
process.exit(1);
662672
}
663673

@@ -1500,7 +1510,11 @@ export class HyperionMaster {
15001510
hLog(log_msg.join(' | '));
15011511
}
15021512

1503-
if (this.indexedObjects === 0 && this.deserializedActions === 0 && this.consumedBlocks === 0 && !this.mode_transition) {
1513+
if(this.liveConsumedBlocks > 0 && this.consumedBlocks === 0 && this.conf.indexer.abi_scan_mode) {
1514+
hLog('Warning: Live reading on ABI SCAN mode')
1515+
}
1516+
1517+
if (this.liveConsumedBlocks + this.indexedObjects + this.deserializedActions + this.consumedBlocks === 0 && !this.mode_transition) {
15041518

15051519
// Report completed range (parallel reading)
15061520
if (this.total_blocks === this.total_range && !this.range_completed) {
@@ -1549,6 +1563,13 @@ export class HyperionMaster {
15491563
}
15501564
} else {
15511565
if (!this.shutdownStarted) {
1566+
const readers = this.workerMap.filter(value => {
1567+
return value.worker_role === 'reader' || value.worker_role === 'continuous_reader';
1568+
});
1569+
if (readers.length === 0) {
1570+
hLog(`No more active workers, stopping now...`);
1571+
process.exit();
1572+
}
15521573
const idleMsg = 'No blocks are being processed, please check your state-history node!';
15531574
if (this.idle_count === 2) {
15541575
this.emitAlert('warning', idleMsg);
@@ -1715,7 +1736,16 @@ export class HyperionMaster {
17151736
this.ioRedisClient = new IORedis(this.manager.conn.redis);
17161737

17171738
// Remove first indexed block from cache (v2/health)
1718-
await this.ioRedisClient.del(`${this.manager.chain}::fib`)
1739+
await this.ioRedisClient.del(`${this.manager.chain}::fib`);
1740+
1741+
// check nodeos
1742+
try {
1743+
const info = await this.rpc.get_info();
1744+
hLog(`Nodeos version: ${info.server_version_string}`);
1745+
} catch (e) {
1746+
hLog(`Chain API Error: ${e.message}`);
1747+
process.exit();
1748+
}
17191749

17201750
// Elasticsearch
17211751
this.client = this.manager.elasticsearchClient;
@@ -1822,9 +1852,9 @@ export class HyperionMaster {
18221852
// handle worker disconnection events
18231853
cluster.on('disconnect', (worker) => {
18241854
if (!this.mode_transition && !this.shutdownStarted) {
1825-
hLog(`The worker #${worker.id} has disconnected, attempting to re-launch in 5 seconds...`);
18261855
const workerReference = this.workerMap.find(value => value.worker_id === worker.id);
18271856
if (workerReference) {
1857+
hLog(`The worker #${worker.id} has disconnected, attempting to re-launch in 5 seconds...`);
18281858
workerReference.wref = null;
18291859
workerReference.failures++;
18301860
hLog(`New worker defined: ${workerReference.worker_role} for ${workerReference.worker_queue}`);
@@ -1840,7 +1870,7 @@ export class HyperionMaster {
18401870
}, 1000);
18411871
}, 5000);
18421872
} else {
1843-
console.log(`Worker #${worker.id} not found in map!`);
1873+
hLog(`The worker #${worker.id} has disconnected`);
18441874
}
18451875
}
18461876
});
@@ -2216,9 +2246,7 @@ export class HyperionMaster {
22162246
await this.setupIndexers();
22172247
await this.setupStreaming();
22182248
await this.setupDSPool();
2219-
this.addWorker({
2220-
worker_role: "delta_updater"
2221-
});
2249+
this.addWorker({worker_role: "delta_updater"});
22222250
}
22232251

22242252
private async findRange() {
@@ -2244,8 +2272,7 @@ export class HyperionMaster {
22442272
try {
22452273
this.chain_data = await this.rpc.get_info();
22462274
} catch (e) {
2247-
console.log(e.message);
2248-
console.error('failed to connect to chain api');
2275+
hLog('Failed to connect to chain api: ' + e.message);
22492276
process.exit(1);
22502277
}
22512278
this.head = this.chain_data.head_block_num;

workers/ds-pool.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,24 @@ export default class DSPoolWorker extends HyperionWorker {
602602

603603
pushToActionStreamingQueue(payload, uniqueAction) {
604604
if (this.allowStreaming && this.conf.features['streaming'].traces) {
605-
const notifArray = new Set();
606-
uniqueAction.act.authorization.forEach(auth => {
607-
notifArray.add(auth.actor);
608-
});
609-
uniqueAction.notified.forEach(acc => {
610-
notifArray.add(acc);
611-
});
612-
const headers = {
613-
event: 'trace',
614-
account: uniqueAction['act']['account'],
615-
name: uniqueAction['act']['name'],
616-
notified: [...notifArray].join(",")
617-
};
618-
this.ch.publish('', this.chain + ':stream', payload, {headers});
605+
try {
606+
const notifArray = new Set();
607+
uniqueAction.act.authorization.forEach(auth => {
608+
notifArray.add(auth.actor);
609+
});
610+
uniqueAction.receipts.forEach(rec => {
611+
notifArray.add(rec.receiver);
612+
});
613+
const headers = {
614+
event: 'trace',
615+
account: uniqueAction['act']['account'],
616+
name: uniqueAction['act']['name'],
617+
notified: [...notifArray].join(",")
618+
};
619+
this.ch.publish('', this.chain + ':stream', payload, {headers});
620+
} catch (e) {
621+
hLog(e);
622+
}
619623
}
620624
}
621625

workers/state-reader.ts

+30-16
Original file line numberDiff line numberDiff line change
@@ -317,46 +317,55 @@ export default class StateReader extends HyperionWorker {
317317

318318
// NORMAL OPERATION MODE
319319
if (!this.recovery) {
320+
320321
const result = deserialize('result', data, this.txEnc, this.txDec, this.types);
322+
323+
// ship status message
321324
if (result[0] === 'get_status_result_v0') {
322325
this.shipInitStatus = result[1];
323326
hLog(`\n| SHIP Status Report\n| Init block: ${this.shipInitStatus['chain_state_begin_block']}\n| Head block: ${this.shipInitStatus['chain_state_end_block']}`);
324327
const chain_state_begin_block = this.shipInitStatus['chain_state_begin_block'];
325328
if (!this.conf.indexer.disable_reading) {
329+
326330
switch (process.env['worker_role']) {
331+
332+
// range reader setup
327333
case 'reader': {
328334
if (chain_state_begin_block > process.env.first_block) {
335+
336+
// skip snapshot block until a solution to parse it is found
337+
const nextBlock = chain_state_begin_block + 2;
329338
hLog(`First saved block is ahead of requested range! - Req: ${process.env.first_block} | First: ${chain_state_begin_block}`);
330-
hLog('Requesting a single block');
331-
if (this.conf.settings.ignore_snapshot) {
332-
this.local_block_num = chain_state_begin_block;
333-
process.send({event: 'update_init_block', block_num: chain_state_begin_block + 2,});
334-
this.newRange({
335-
first_block: chain_state_begin_block + 1,
336-
last_block: chain_state_begin_block + this.conf.scaling.batch_size
337-
});
338-
} else {
339-
process.send({event: 'update_init_block', block_num: chain_state_begin_block + 1});
340-
this.newRange({
341-
first_block: chain_state_begin_block,
342-
last_block: chain_state_begin_block + 1
343-
});
344-
}
339+
this.local_block_num = nextBlock - 1;
340+
process.send({
341+
event: 'update_init_block',
342+
block_num: nextBlock
343+
});
344+
this.newRange({
345+
first_block: nextBlock,
346+
last_block: nextBlock + this.conf.scaling.batch_size
347+
});
345348
} else {
346349
this.requestBlocks(0);
347350
}
348351
break;
349352
}
353+
354+
// live reader setup
350355
case 'continuous_reader': {
351356
this.requestBlocks(parseInt(process.env['worker_last_processed_block'], 10));
352357
break;
353358
}
359+
354360
}
355361
} else {
356362
this.ship.close();
357363
process.exit(1);
358364
}
365+
359366
} else {
367+
368+
// ship block message
360369
const res = result[1];
361370

362371
if (res['this_block']) {
@@ -440,7 +449,12 @@ export default class StateReader extends HyperionWorker {
440449
}
441450
}
442451
} else {
443-
return 0;
452+
hLog(`Reader is idle! - Head at: ${result[1].head.block_num}`);
453+
this.ship.close();
454+
process.send({
455+
event: 'kill_worker',
456+
id: process.env['worker_id']
457+
});
444458
}
445459
}
446460

0 commit comments

Comments
 (0)