mirror of
https://github.com/mempool/mempool.git
synced 2024-11-19 09:52:14 +01:00
Roll back local acceleration data on reorg
This commit is contained in:
parent
5f36cb88ab
commit
91493e8769
@ -29,6 +29,7 @@ import websocketHandler from './websocket-handler';
|
||||
import redisCache from './redis-cache';
|
||||
import rbfCache from './rbf-cache';
|
||||
import { calcBitsDifference } from './difficulty-adjustment';
|
||||
import AccelerationRepository from '../repositories/AccelerationRepository';
|
||||
|
||||
class Blocks {
|
||||
private blocks: BlockExtended[] = [];
|
||||
@ -872,6 +873,7 @@ class Blocks {
|
||||
await BlocksRepository.$deleteBlocksFrom(lastBlock.height - 10);
|
||||
await HashratesRepository.$deleteLastEntries();
|
||||
await cpfpRepository.$deleteClustersFrom(lastBlock.height - 10);
|
||||
await AccelerationRepository.$deleteAccelerationsFrom(lastBlock.height - 10);
|
||||
this.blocks = this.blocks.slice(0, -10);
|
||||
this.updateTimerProgress(timer, `rolled back chain divergence from ${this.currentBlockHeight}`);
|
||||
for (let i = 10; i >= 0; --i) {
|
||||
|
@ -317,6 +317,26 @@ class AccelerationRepository {
|
||||
|
||||
logger.debug(`Indexing accelerations completed`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete accelerations from the database above blockHeight
|
||||
*/
|
||||
public async $deleteAccelerationsFrom(blockHeight: number): Promise<void> {
|
||||
logger.info(`Delete newer accelerations from height ${blockHeight} from the database`);
|
||||
try {
|
||||
const currentSyncedHeight = await this.$getLastSyncedHeight();
|
||||
if (currentSyncedHeight >= blockHeight) {
|
||||
await DB.query(`
|
||||
UPDATE state
|
||||
SET number = ?
|
||||
WHERE name = 'last_acceleration_block'
|
||||
`, [blockHeight - 1]);
|
||||
}
|
||||
await DB.query(`DELETE FROM accelerations where height >= ${blockHeight}`);
|
||||
} catch (e) {
|
||||
logger.err('Cannot delete indexed accelerations. Reason: ' + (e instanceof Error ? e.message : e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new AccelerationRepository();
|
||||
|
Loading…
Reference in New Issue
Block a user