Skip to content

Commit 2827f85

Browse files
committed
v3.3.8 stable
- fix readers stopping before having finished
1 parent 2ee60bc commit 2827f85

File tree

5 files changed

+166
-114
lines changed

5 files changed

+166
-114
lines changed

connections/state-history.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export class StateHistorySocket {
66
private ws;
77
private readonly shipUrl;
88
private readonly max_payload_mb;
9+
retryOnDisconnect = true;
10+
connected = false;
911

1012
constructor(ship_url, max_payload_mb) {
1113
this.shipUrl = ship_url;
@@ -17,29 +19,35 @@ export class StateHistorySocket {
1719
}
1820

1921
connect(onMessage, onDisconnect, onError, onConnected) {
20-
2122
debugLog(`Connecting to ${this.shipUrl}...`);
2223
this.ws = new WebSocket(this.shipUrl, {
2324
perMessageDeflate: false,
2425
maxPayload: this.max_payload_mb * 1024 * 1024,
2526
});
2627
this.ws.on('open', () => {
28+
this.connected = true;
2729
hLog('Websocket connected!');
2830
if (onConnected) {
2931
onConnected();
3032
}
3133
});
3234
this.ws.on('message', (data) => onMessage(data));
3335
this.ws.on('close', () => {
36+
this.connected = false;
3437
hLog('Websocket disconnected!');
35-
onDisconnect();
38+
if(this.retryOnDisconnect) {
39+
onDisconnect();
40+
}
3641
});
3742
this.ws.on('error', (err) => {
3843
hLog(`${this.shipUrl} :: ${err.message}`);
3944
});
4045
}
4146

42-
close() {
47+
close(graceful: boolean) {
48+
if(graceful) {
49+
this.retryOnDisconnect = false;
50+
}
4351
this.ws.close();
4452
}
4553

modules/master.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ export class HyperionMaster {
234234
tx: msg.trx_ids
235235
});
236236

237+
this.lastProducedBlockNum = msg.block_num;
238+
237239
if (this.conf.settings.bp_monitoring && !this.conf.indexer.abi_scan_mode) {
238240
this.liveBlockQueue.push(msg).catch(reason => {
239241
hLog('Error handling consumed_block:', reason);
@@ -326,17 +328,38 @@ export class HyperionMaster {
326328
if (end > this.head) {
327329
end = this.head;
328330
}
329-
this.lastAssignedBlock += this.maxBatchSize;
330331
const def = {
331332
first_block: start,
332333
last_block: end
333334
};
335+
this.lastAssignedBlock = def.last_block;
334336
this.activeReadersCount++;
335337
messageAllWorkers(cluster, {
336338
event: 'new_range',
337339
target: msg.id,
338340
data: def
339341
});
342+
} else {
343+
if (this.lastAssignedBlock >= this.head) {
344+
hLog(`Parallel readers finished the requested range`);
345+
const readers = this.workerMap.filter(value => value.worker_role === 'reader');
346+
this.workerMap = this.workerMap.filter(value => value.worker_role !== 'reader');
347+
readers.forEach(value => value.wref.kill());
348+
// for (let hyperionWorkerDef of this.workerMap) {
349+
// if (hyperionWorkerDef.worker_role === 'reader') {
350+
// hyperionWorkerDef.wref.kill();
351+
// }
352+
// }
353+
// for (let workersKey in cluster.workers) {
354+
// const w = cluster.workers[workersKey];
355+
// console.log(w);
356+
// if (w.id === parseInt(msg.id)) {
357+
// const idx = this.workerMap.findIndex(value => value.worker_id === w.id);
358+
// this.workerMap.splice(idx, 1);
359+
// w.kill();
360+
// }
361+
// }
362+
}
340363
}
341364
}
342365
},
@@ -1461,6 +1484,12 @@ export class HyperionMaster {
14611484
avg_consume_rate = consume_rate;
14621485
}
14631486
const log_msg = [];
1487+
1488+
// print current head for live reading
1489+
if (this.lastProducedBlockNum > 0) {
1490+
log_msg.push(`#${this.lastProducedBlockNum}`);
1491+
}
1492+
14641493
log_msg.push(`W:${_workers}`);
14651494

14661495
const _r = (this.pushedBlocks + this.livePushedBlocks) / tScale;
@@ -1484,9 +1513,12 @@ export class HyperionMaster {
14841513
this.metrics.indexingRate?.set(_ir);
14851514

14861515
if (this.total_blocks < this.total_range && !this.conf.indexer.live_only_mode) {
1487-
const remaining = this.total_range - this.total_blocks;
1488-
const estimated_time = Math.round(remaining / avg_consume_rate);
1489-
const time_string = moment().add(estimated_time, 'seconds').fromNow(false);
1516+
let time_string = 'waiting for indexer';
1517+
if (avg_consume_rate > 0) {
1518+
const remaining = this.total_range - this.total_blocks;
1519+
const estimated_time = Math.round(remaining / avg_consume_rate);
1520+
time_string = moment().add(estimated_time, 'seconds').fromNow(false);
1521+
}
14901522
const pct_parsed = ((this.total_blocks / this.total_range) * 100).toFixed(1);
14911523
const pct_read = ((this.total_read / this.total_range) * 100).toFixed(1);
14921524
log_msg.push(`${this.total_blocks}/${this.total_read}/${this.total_range}`);
@@ -1510,7 +1542,7 @@ export class HyperionMaster {
15101542
hLog(log_msg.join(' | '));
15111543
}
15121544

1513-
if(this.liveConsumedBlocks > 0 && this.consumedBlocks === 0 && this.conf.indexer.abi_scan_mode) {
1545+
if (this.liveConsumedBlocks > 0 && this.consumedBlocks === 0 && this.conf.indexer.abi_scan_mode) {
15141546
hLog('Warning: Live reading on ABI SCAN mode')
15151547
}
15161548

0 commit comments

Comments
 (0)