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 redisCache from './redis-cache';
|
||||||
import rbfCache from './rbf-cache';
|
import rbfCache from './rbf-cache';
|
||||||
import { calcBitsDifference } from './difficulty-adjustment';
|
import { calcBitsDifference } from './difficulty-adjustment';
|
||||||
|
import AccelerationRepository from '../repositories/AccelerationRepository';
|
||||||
|
|
||||||
class Blocks {
|
class Blocks {
|
||||||
private blocks: BlockExtended[] = [];
|
private blocks: BlockExtended[] = [];
|
||||||
@ -872,6 +873,7 @@ class Blocks {
|
|||||||
await BlocksRepository.$deleteBlocksFrom(lastBlock.height - 10);
|
await BlocksRepository.$deleteBlocksFrom(lastBlock.height - 10);
|
||||||
await HashratesRepository.$deleteLastEntries();
|
await HashratesRepository.$deleteLastEntries();
|
||||||
await cpfpRepository.$deleteClustersFrom(lastBlock.height - 10);
|
await cpfpRepository.$deleteClustersFrom(lastBlock.height - 10);
|
||||||
|
await AccelerationRepository.$deleteAccelerationsFrom(lastBlock.height - 10);
|
||||||
this.blocks = this.blocks.slice(0, -10);
|
this.blocks = this.blocks.slice(0, -10);
|
||||||
this.updateTimerProgress(timer, `rolled back chain divergence from ${this.currentBlockHeight}`);
|
this.updateTimerProgress(timer, `rolled back chain divergence from ${this.currentBlockHeight}`);
|
||||||
for (let i = 10; i >= 0; --i) {
|
for (let i = 10; i >= 0; --i) {
|
||||||
|
@ -317,6 +317,26 @@ class AccelerationRepository {
|
|||||||
|
|
||||||
logger.debug(`Indexing accelerations completed`);
|
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();
|
export default new AccelerationRepository();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user