Merge pull request #3846 from mempool/mononaut/audit-details
Add expected vs actual audit details comparison table
This commit is contained in:
@@ -282,10 +282,14 @@ class Blocks {
|
||||
}
|
||||
|
||||
extras.matchRate = null;
|
||||
extras.expectedFees = null;
|
||||
extras.expectedWeight = null;
|
||||
if (config.MEMPOOL.AUDIT) {
|
||||
const auditScore = await BlocksAuditsRepository.$getBlockAuditScore(block.id);
|
||||
if (auditScore != null) {
|
||||
extras.matchRate = auditScore.matchRate;
|
||||
extras.expectedFees = auditScore.expectedFees;
|
||||
extras.expectedWeight = auditScore.expectedWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -455,6 +459,46 @@ class Blocks {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [INDEXING] Index expected fees & weight for all audited blocks
|
||||
*/
|
||||
public async $generateAuditStats(): Promise<void> {
|
||||
const blockIds = await BlocksAuditsRepository.$getBlocksWithoutSummaries();
|
||||
if (!blockIds?.length) {
|
||||
return;
|
||||
}
|
||||
let timer = Date.now();
|
||||
let indexedThisRun = 0;
|
||||
let indexedTotal = 0;
|
||||
logger.debug(`Indexing ${blockIds.length} block audit details`);
|
||||
for (const hash of blockIds) {
|
||||
const summary = await BlocksSummariesRepository.$getTemplate(hash);
|
||||
let totalFees = 0;
|
||||
let totalWeight = 0;
|
||||
for (const tx of summary?.transactions || []) {
|
||||
totalFees += tx.fee;
|
||||
totalWeight += (tx.vsize * 4);
|
||||
}
|
||||
await BlocksAuditsRepository.$setSummary(hash, totalFees, totalWeight);
|
||||
const cachedBlock = this.blocks.find(block => block.id === hash);
|
||||
if (cachedBlock) {
|
||||
cachedBlock.extras.expectedFees = totalFees;
|
||||
cachedBlock.extras.expectedWeight = totalWeight;
|
||||
}
|
||||
|
||||
indexedThisRun++;
|
||||
indexedTotal++;
|
||||
const elapsedSeconds = (Date.now() - timer) / 1000;
|
||||
if (elapsedSeconds > 5) {
|
||||
const blockPerSeconds = indexedThisRun / elapsedSeconds;
|
||||
logger.debug(`Indexed ${indexedTotal} / ${blockIds.length} block audit details (${blockPerSeconds.toFixed(1)}/s)`);
|
||||
timer = Date.now();
|
||||
indexedThisRun = 0;
|
||||
}
|
||||
}
|
||||
logger.debug(`Indexing block audit details completed`);
|
||||
}
|
||||
|
||||
/**
|
||||
* [INDEXING] Index all blocks metadata for the mining dashboard
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ import cpfpRepository from '../repositories/CpfpRepository';
|
||||
import { RowDataPacket } from 'mysql2';
|
||||
|
||||
class DatabaseMigration {
|
||||
private static currentVersion = 61;
|
||||
private static currentVersion = 62;
|
||||
private queryTimeout = 3600_000;
|
||||
private statisticsAddedIndexed = false;
|
||||
private uniqueLogs: string[] = [];
|
||||
@@ -533,6 +533,12 @@ class DatabaseMigration {
|
||||
await this.updateToSchemaVersion(61);
|
||||
}
|
||||
|
||||
if (databaseSchemaVersion < 62 && isBitcoin === true) {
|
||||
await this.$executeQuery('ALTER TABLE `blocks_audits` ADD expected_fees BIGINT UNSIGNED DEFAULT NULL');
|
||||
await this.$executeQuery('ALTER TABLE `blocks_audits` ADD expected_weight BIGINT UNSIGNED DEFAULT NULL');
|
||||
await this.updateToSchemaVersion(62);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -571,11 +571,18 @@ class WebsocketHandler {
|
||||
};
|
||||
}) : [];
|
||||
|
||||
let totalFees = 0;
|
||||
let totalWeight = 0;
|
||||
for (const tx of stripped) {
|
||||
totalFees += tx.fee;
|
||||
totalWeight += (tx.vsize * 4);
|
||||
}
|
||||
|
||||
BlocksSummariesRepository.$saveTemplate({
|
||||
height: block.height,
|
||||
template: {
|
||||
id: block.id,
|
||||
transactions: stripped
|
||||
transactions: stripped,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -588,10 +595,14 @@ class WebsocketHandler {
|
||||
freshTxs: fresh,
|
||||
sigopTxs: sigop,
|
||||
matchRate: matchRate,
|
||||
expectedFees: totalFees,
|
||||
expectedWeight: totalWeight,
|
||||
});
|
||||
|
||||
if (block.extras) {
|
||||
block.extras.matchRate = matchRate;
|
||||
block.extras.expectedFees = totalFees;
|
||||
block.extras.expectedWeight = totalWeight;
|
||||
block.extras.similarity = similarity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user