From ce204d03c65b211f337f2eeffd87cb55c7c83779 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Tue, 21 May 2024 21:47:18 +0000 Subject: [PATCH] Fix local acceleration filter & reindex --- backend/src/api/database-migration.ts | 14 +++++++++++++- backend/src/repositories/AccelerationRepository.ts | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index f1d68c621..c6cd11866 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -7,7 +7,7 @@ import cpfpRepository from '../repositories/CpfpRepository'; import { RowDataPacket } from 'mysql2'; class DatabaseMigration { - private static currentVersion = 78; + private static currentVersion = 79; private queryTimeout = 3600_000; private statisticsAddedIndexed = false; private uniqueLogs: string[] = []; @@ -674,6 +674,18 @@ class DatabaseMigration { await this.$executeQuery('ALTER TABLE `prices` CHANGE `time` `time` datetime NOT NULL'); await this.updateToSchemaVersion(78); } + + if (databaseSchemaVersion < 79 && config.MEMPOOL.NETWORK === 'mainnet') { + // Clear bad data + await this.$executeQuery(`TRUNCATE accelerations`); + this.uniqueLog(logger.notice, `'accelerations' table has been truncated`); + await this.$executeQuery(` + UPDATE state + SET number = 0 + WHERE name = 'last_acceleration_block' + `); + await this.updateToSchemaVersion(79); + } } /** diff --git a/backend/src/repositories/AccelerationRepository.ts b/backend/src/repositories/AccelerationRepository.ts index 34df770f1..eea60fcff 100644 --- a/backend/src/repositories/AccelerationRepository.ts +++ b/backend/src/repositories/AccelerationRepository.ts @@ -244,6 +244,8 @@ class AccelerationRepository { let count = 0; try { while (!done) { + // don't DDoS the services backend + Common.sleep$(500 + (Math.random() * 1000)); const accelerations = await accelerationApi.$fetchAccelerationHistory(page); page++; if (!accelerations?.length) { @@ -309,7 +311,7 @@ class AccelerationRepository { pools: acc.pools.map(pool => pool.pool_unique_id), })) for (const acc of accelerations) { - if (blockTxs[acc.txid]) { + if (blockTxs[acc.txid] && acc.pools.some(pool => pool.pool_unique_id === block.extras.pool.id)) { const tx = blockTxs[acc.txid]; const accelerationInfo = accelerationCosts.getAccelerationInfo(tx, boostRate, transactions); accelerationInfo.cost = Math.max(0, Math.min(acc.feeDelta, accelerationInfo.cost));