Audit past acceleration data
This commit is contained in:
@@ -238,7 +238,7 @@ class AccelerationCosts {
|
||||
private convertToGraphTx(tx: MempoolTransactionExtended): GraphTx {
|
||||
return {
|
||||
txid: tx.txid,
|
||||
vsize: tx.vsize,
|
||||
vsize: Math.ceil(tx.weight / 4),
|
||||
weight: tx.weight,
|
||||
fees: {
|
||||
base: 0, // dummy
|
||||
@@ -256,7 +256,7 @@ class AccelerationCosts {
|
||||
ancestor: tx.fees.base,
|
||||
},
|
||||
ancestorcount: 1,
|
||||
ancestorsize: tx.vsize,
|
||||
ancestorsize: Math.ceil(tx.weight / 4),
|
||||
ancestors: new Map<string, MempoolTx>(),
|
||||
ancestorRate: 0,
|
||||
individualRate: 0,
|
||||
@@ -493,7 +493,7 @@ interface MinerTransaction extends TemplateTransaction {
|
||||
* Build a block using an approximation of the transaction selection algorithm from Bitcoin Core
|
||||
* (see BlockAssembler in https://github.com/bitcoin/bitcoin/blob/master/src/node/miner.cpp)
|
||||
*/
|
||||
function makeBlockTemplate(candidates: IEsploraApi.Transaction[], accelerations: Acceleration[], maxBlocks: number = 8, weightLimit: number = BLOCK_WEIGHT_UNITS, sigopLimit: number = BLOCK_SIGOPS): TemplateTransaction[] {
|
||||
export function makeBlockTemplate(candidates: IEsploraApi.Transaction[], accelerations: Acceleration[], maxBlocks: number = 8, weightLimit: number = BLOCK_WEIGHT_UNITS, sigopLimit: number = BLOCK_SIGOPS): TemplateTransaction[] {
|
||||
const auditPool: Map<string, MinerTransaction> = new Map();
|
||||
const mempoolArray: MinerTransaction[] = [];
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import cpfpRepository from '../repositories/CpfpRepository';
|
||||
import { RowDataPacket } from 'mysql2';
|
||||
|
||||
class DatabaseMigration {
|
||||
private static currentVersion = 73;
|
||||
private static currentVersion = 74;
|
||||
private queryTimeout = 3600_000;
|
||||
private statisticsAddedIndexed = false;
|
||||
private uniqueLogs: string[] = [];
|
||||
@@ -619,6 +619,11 @@ class DatabaseMigration {
|
||||
this.uniqueLog(logger.notice, `'accelerations' table has been truncated`);
|
||||
await this.updateToSchemaVersion(73);
|
||||
}
|
||||
|
||||
if (databaseSchemaVersion < 74 && config.MEMPOOL.NETWORK === 'mainnet') {
|
||||
await this.$executeQuery(`INSERT INTO state(name, number) VALUE ('last_acceleration_block', 0);`);
|
||||
await this.updateToSchemaVersion(74);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,26 @@ export interface Acceleration {
|
||||
txid: string,
|
||||
feeDelta: number,
|
||||
pools: number[],
|
||||
}
|
||||
};
|
||||
|
||||
export interface AccelerationHistory {
|
||||
txid: string,
|
||||
status: string,
|
||||
feePaid: number,
|
||||
added: number,
|
||||
lastUpdated: number,
|
||||
baseFee: number,
|
||||
vsizeFee: number,
|
||||
effectiveFee: number,
|
||||
effectiveVsize: number,
|
||||
feeDelta: number,
|
||||
blockHash: string,
|
||||
blockHeight: number,
|
||||
pools: {
|
||||
pool_unique_id: number,
|
||||
username: string,
|
||||
}[],
|
||||
};
|
||||
|
||||
class AccelerationApi {
|
||||
public async $fetchAccelerations(): Promise<Acceleration[] | null> {
|
||||
@@ -24,6 +43,27 @@ class AccelerationApi {
|
||||
}
|
||||
}
|
||||
|
||||
public async $fetchAccelerationHistory(page?: number, status?: string): Promise<AccelerationHistory[] | null> {
|
||||
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
|
||||
try {
|
||||
const response = await axios.get(`${config.MEMPOOL_SERVICES.API}/accelerator/accelerations/history`, {
|
||||
responseType: 'json',
|
||||
timeout: 10000,
|
||||
params: {
|
||||
page,
|
||||
status,
|
||||
}
|
||||
});
|
||||
return response.data as AccelerationHistory[];
|
||||
} catch (e) {
|
||||
logger.warn('Failed to fetch acceleration history from the mempool services backend: ' + (e instanceof Error ? e.message : e));
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public isAcceleratedBlock(block: BlockExtended, accelerations: Acceleration[]): boolean {
|
||||
let anyAccelerated = false;
|
||||
for (let i = 0; i < accelerations.length && !anyAccelerated; i++) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import { ApiPrice } from '../repositories/PricesRepository';
|
||||
import accelerationApi from './services/acceleration';
|
||||
import mempool from './mempool';
|
||||
import statistics from './statistics/statistics';
|
||||
import accelerationCosts from './acceleration';
|
||||
import accelerationRepository from '../repositories/AccelerationRepository';
|
||||
import bitcoinApi from './bitcoin/bitcoin-api-factory';
|
||||
|
||||
@@ -742,25 +741,8 @@ class WebsocketHandler {
|
||||
|
||||
const isAccelerated = config.MEMPOOL_SERVICES.ACCELERATIONS && accelerationApi.isAcceleratedBlock(block, Object.values(mempool.getAccelerations()));
|
||||
|
||||
|
||||
if (isAccelerated) {
|
||||
const blockTxs: { [txid: string]: MempoolTransactionExtended } = {};
|
||||
for (const tx of transactions) {
|
||||
blockTxs[tx.txid] = tx;
|
||||
}
|
||||
const accelerations = Object.values(mempool.getAccelerations());
|
||||
const boostRate = accelerationCosts.calculateBoostRate(
|
||||
accelerations.map(acc => ({ txid: acc.txid, max_bid: acc.feeDelta })),
|
||||
transactions
|
||||
);
|
||||
for (const acc of accelerations) {
|
||||
if (blockTxs[acc.txid]) {
|
||||
const tx = blockTxs[acc.txid];
|
||||
const accelerationInfo = accelerationCosts.getAccelerationInfo(tx, boostRate, transactions);
|
||||
accelerationRepository.$saveAcceleration(accelerationInfo, block, block.extras.pool.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
const accelerations = Object.values(mempool.getAccelerations());
|
||||
await accelerationRepository.$indexAccelerationsForBlock(block, accelerations, transactions);
|
||||
|
||||
const rbfTransactions = Common.findMinedRbfTransactions(transactions, memPool.getSpendMap());
|
||||
memPool.handleMinedRbfTransactions(rbfTransactions);
|
||||
|
||||
Reference in New Issue
Block a user