Disable mining pools update if AUTOMATIC_BLOCK_REINDEXING is not set - Re-index unknown blocks when a new pool is added

This commit is contained in:
nymkappa 2023-02-12 22:44:04 +09:00
parent d87fb04a92
commit 117aa1375d
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
2 changed files with 16 additions and 0 deletions

View File

@ -37,6 +37,7 @@ class PoolsParser {
const slug = pool.name.replace(/[^a-z0-9]/gi, '').toLowerCase();
logger.debug(`Inserting new mining pool ${pool.name}`);
await PoolsRepository.$insertNewMiningPool(pool, slug);
await this.$deleteUnknownBlocks();
} else {
if (poolDB.name !== pool.name) {
// Pool has been renamed
@ -126,6 +127,16 @@ class PoolsParser {
[pool.id]
);
}
private async $deleteUnknownBlocks(): Promise<void> {
const [unknownPool] = await DB.query(`SELECT id from pools where slug = "unknown"`);
logger.notice(`Deleting blocks with unknown mining pool from height 130635 for re-indexing`);
await DB.query(`
DELETE FROM blocks
WHERE pool_id = ? AND height >= 130635`,
[unknownPool[0].id]
);
}
}
export default new PoolsParser();

View File

@ -17,6 +17,11 @@ class PoolsUpdater {
treeUrl: string = config.MEMPOOL.POOLS_JSON_TREE_URL;
public async updatePoolsJson(): Promise<void> {
if (config.MEMPOOL.AUTOMATIC_BLOCK_REINDEXING === false) {
logger.info(`Not updating mining pools to avoid inconsistency because AUTOMATIC_BLOCK_REINDEXING is set to false`)
return;
}
if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false) {
return;
}