mirror of
https://github.com/mempool/mempool.git
synced 2025-01-17 18:52:34 +01:00
Fix for Bisq blocks data watchers stopps working randomly. Restaring watcher when block height has diverged.
This commit is contained in:
parent
f4a78a0e78
commit
3450de774f
@ -3,6 +3,7 @@ import * as fs from 'fs';
|
||||
import * as request from 'request';
|
||||
import { BisqBlocks, BisqBlock, BisqTransaction, BisqStats, BisqTrade } from './interfaces';
|
||||
import { Common } from '../common';
|
||||
import { Block } from '../../interfaces';
|
||||
|
||||
class Bisq {
|
||||
private static BLOCKS_JSON_FILE_PATH = '/all/blocks.json';
|
||||
@ -35,6 +36,14 @@ class Bisq {
|
||||
this.startSubDirectoryWatcher();
|
||||
}
|
||||
|
||||
handleNewBitcoinBlock(block: Block): void {
|
||||
if (block.height - 2 > this.latestBlockHeight && this.latestBlockHeight !== 0) {
|
||||
console.log(`Bitcoin block height (#${block.height}) has diverged from the latest Bisq block height (#${this.latestBlockHeight}). Restarting watchers...`);
|
||||
this.startTopDirectoryWatcher();
|
||||
this.startSubDirectoryWatcher();
|
||||
}
|
||||
}
|
||||
|
||||
getTransaction(txId: string): BisqTransaction | undefined {
|
||||
return this.transactionIndex[txId];
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class Blocks {
|
||||
private blocks: Block[] = [];
|
||||
private currentBlockHeight = 0;
|
||||
private lastDifficultyAdjustmentTime = 0;
|
||||
private newBlockCallback: ((block: Block, txIds: string[], transactions: TransactionExtended[]) => void) | undefined;
|
||||
private newBlockCallbacks: ((block: Block, txIds: string[], transactions: TransactionExtended[]) => void)[] = [];
|
||||
|
||||
constructor() { }
|
||||
|
||||
@ -21,7 +21,7 @@ class Blocks {
|
||||
}
|
||||
|
||||
public setNewBlockCallback(fn: (block: Block, txIds: string[], transactions: TransactionExtended[]) => void) {
|
||||
this.newBlockCallback = fn;
|
||||
this.newBlockCallbacks.push(fn);
|
||||
}
|
||||
|
||||
public async updateBlocks() {
|
||||
@ -95,8 +95,8 @@ class Blocks {
|
||||
this.blocks.shift();
|
||||
}
|
||||
|
||||
if (this.newBlockCallback) {
|
||||
this.newBlockCallback(block, txIds, transactions);
|
||||
if (this.newBlockCallbacks.length) {
|
||||
this.newBlockCallbacks.forEach((cb) => cb(block, txIds, transactions));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,7 @@ class Server {
|
||||
if (config.BISQ_ENABLED) {
|
||||
bisq.startBisqService();
|
||||
bisq.setPriceCallbackFunction((price) => websocketHandler.setExtraInitProperties('bsq-price', price));
|
||||
blocks.setNewBlockCallback(bisq.handleNewBitcoinBlock.bind(bisq));
|
||||
}
|
||||
|
||||
if (config.BISQ_MARKET_ENABLED) {
|
||||
|
Loading…
Reference in New Issue
Block a user