mirror of
https://github.com/Retropex/mempool.git
synced 2025-05-13 02:30:41 +02:00
Reset block cache after updating pools
This commit is contained in:
parent
1c9b422db4
commit
ab5c49ea7a
@ -8,6 +8,7 @@ import mining from './mining/mining';
|
|||||||
import transactionUtils from './transaction-utils';
|
import transactionUtils from './transaction-utils';
|
||||||
import BlocksRepository from '../repositories/BlocksRepository';
|
import BlocksRepository from '../repositories/BlocksRepository';
|
||||||
import redisCache from './redis-cache';
|
import redisCache from './redis-cache';
|
||||||
|
import blocks from './blocks';
|
||||||
|
|
||||||
class PoolsParser {
|
class PoolsParser {
|
||||||
miningPools: any[] = [];
|
miningPools: any[] = [];
|
||||||
@ -42,6 +43,8 @@ class PoolsParser {
|
|||||||
await this.$insertUnknownPool();
|
await this.$insertUnknownPool();
|
||||||
|
|
||||||
let reindexUnknown = false;
|
let reindexUnknown = false;
|
||||||
|
let clearCache = false;
|
||||||
|
|
||||||
|
|
||||||
for (const pool of this.miningPools) {
|
for (const pool of this.miningPools) {
|
||||||
if (!pool.id) {
|
if (!pool.id) {
|
||||||
@ -78,17 +81,20 @@ class PoolsParser {
|
|||||||
logger.debug(`Inserting new mining pool ${pool.name}`);
|
logger.debug(`Inserting new mining pool ${pool.name}`);
|
||||||
await PoolsRepository.$insertNewMiningPool(pool, slug);
|
await PoolsRepository.$insertNewMiningPool(pool, slug);
|
||||||
reindexUnknown = true;
|
reindexUnknown = true;
|
||||||
|
clearCache = true;
|
||||||
} else {
|
} else {
|
||||||
if (poolDB.name !== pool.name) {
|
if (poolDB.name !== pool.name) {
|
||||||
// Pool has been renamed
|
// Pool has been renamed
|
||||||
const newSlug = pool.name.replace(/[^a-z0-9]/gi, '').toLowerCase();
|
const newSlug = pool.name.replace(/[^a-z0-9]/gi, '').toLowerCase();
|
||||||
logger.warn(`Renaming ${poolDB.name} mining pool to ${pool.name}. Slug has been updated. Maybe you want to make a redirection from 'https://mempool.space/mining/pool/${poolDB.slug}' to 'https://mempool.space/mining/pool/${newSlug}`);
|
logger.warn(`Renaming ${poolDB.name} mining pool to ${pool.name}. Slug has been updated. Maybe you want to make a redirection from 'https://mempool.space/mining/pool/${poolDB.slug}' to 'https://mempool.space/mining/pool/${newSlug}`);
|
||||||
await PoolsRepository.$renameMiningPool(poolDB.id, newSlug, pool.name);
|
await PoolsRepository.$renameMiningPool(poolDB.id, newSlug, pool.name);
|
||||||
|
clearCache = true;
|
||||||
}
|
}
|
||||||
if (poolDB.link !== pool.link) {
|
if (poolDB.link !== pool.link) {
|
||||||
// Pool link has changed
|
// Pool link has changed
|
||||||
logger.debug(`Updating link for ${pool.name} mining pool`);
|
logger.debug(`Updating link for ${pool.name} mining pool`);
|
||||||
await PoolsRepository.$updateMiningPoolLink(poolDB.id, pool.link);
|
await PoolsRepository.$updateMiningPoolLink(poolDB.id, pool.link);
|
||||||
|
clearCache = true;
|
||||||
}
|
}
|
||||||
if (JSON.stringify(pool.addresses) !== poolDB.addresses ||
|
if (JSON.stringify(pool.addresses) !== poolDB.addresses ||
|
||||||
JSON.stringify(pool.regexes) !== poolDB.regexes) {
|
JSON.stringify(pool.regexes) !== poolDB.regexes) {
|
||||||
@ -96,6 +102,7 @@ class PoolsParser {
|
|||||||
logger.notice(`Updating addresses and/or coinbase tags for ${pool.name} mining pool.`);
|
logger.notice(`Updating addresses and/or coinbase tags for ${pool.name} mining pool.`);
|
||||||
await PoolsRepository.$updateMiningPoolTags(poolDB.id, pool.addresses, pool.regexes);
|
await PoolsRepository.$updateMiningPoolTags(poolDB.id, pool.addresses, pool.regexes);
|
||||||
reindexUnknown = true;
|
reindexUnknown = true;
|
||||||
|
clearCache = true;
|
||||||
await this.$reindexBlocksForPool(poolDB.id);
|
await this.$reindexBlocksForPool(poolDB.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,6 +118,19 @@ class PoolsParser {
|
|||||||
}
|
}
|
||||||
await this.$reindexBlocksForPool(unknownPool.id);
|
await this.$reindexBlocksForPool(unknownPool.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refresh the in-memory block cache with the reindexed data
|
||||||
|
if (clearCache) {
|
||||||
|
for (const block of blocks.getBlocks()) {
|
||||||
|
const reindexedBlock = await blocks.$indexBlock(block.height);
|
||||||
|
if (reindexedBlock.id === block.id) {
|
||||||
|
block.extras.pool = reindexedBlock.extras.pool;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// update persistent cache with the reindexed data
|
||||||
|
diskCache.$saveCacheToDisk();
|
||||||
|
redisCache.$updateBlocks(blocks.getBlocks());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public matchBlockMiner(scriptsig: string, addresses: string[], pools: PoolTag[]): PoolTag | undefined {
|
public matchBlockMiner(scriptsig: string, addresses: string[], pools: PoolTag[]): PoolTag | undefined {
|
||||||
|
Loading…
Reference in New Issue
Block a user