Add expected total fees audit
This commit is contained in:
		
							parent
							
								
									6076eeed46
								
							
						
					
					
						commit
						3c0bb11208
					
				@ -7,7 +7,7 @@ import cpfpRepository from '../repositories/CpfpRepository';
 | 
			
		||||
import { RowDataPacket } from 'mysql2';
 | 
			
		||||
 | 
			
		||||
class DatabaseMigration {
 | 
			
		||||
  private static currentVersion = 60;
 | 
			
		||||
  private static currentVersion = 61;
 | 
			
		||||
  private queryTimeout = 3600_000;
 | 
			
		||||
  private statisticsAddedIndexed = false;
 | 
			
		||||
  private uniqueLogs: string[] = [];
 | 
			
		||||
@ -521,6 +521,11 @@ class DatabaseMigration {
 | 
			
		||||
      await this.$executeQuery('ALTER TABLE `blocks_audits` ADD sigop_txs JSON DEFAULT "[]"');
 | 
			
		||||
      await this.updateToSchemaVersion(60);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (databaseSchemaVersion < 61 && isBitcoin === true) {
 | 
			
		||||
      await this.$executeQuery('ALTER TABLE `blocks_audits` ADD expected_fees BIGINT UNSIGNED NOT NULL DEFAULT "0"');
 | 
			
		||||
      await this.updateToSchemaVersion(61);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
 | 
			
		||||
@ -559,6 +559,8 @@ class WebsocketHandler {
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (Common.indexingEnabled() && memPool.isInSync()) {
 | 
			
		||||
        logger.debug(`Auditing block ${block.height} (${block.id})`);
 | 
			
		||||
 | 
			
		||||
        const { censored, added, fresh, sigop, score, similarity } = Audit.auditBlock(transactions, projectedBlocks, auditMempool);
 | 
			
		||||
        const matchRate = Math.round(score * 100 * 100) / 100;
 | 
			
		||||
 | 
			
		||||
@ -571,11 +573,14 @@ class WebsocketHandler {
 | 
			
		||||
          };
 | 
			
		||||
        }) : [];
 | 
			
		||||
 | 
			
		||||
        const totalFees = stripped.reduce((total, transaction) => total + transaction.fee, 0);
 | 
			
		||||
        logger.debug(`Projected block fees: ${totalFees} sats`);
 | 
			
		||||
 | 
			
		||||
        BlocksSummariesRepository.$saveTemplate({
 | 
			
		||||
          height: block.height,
 | 
			
		||||
          template: {
 | 
			
		||||
            id: block.id,
 | 
			
		||||
            transactions: stripped
 | 
			
		||||
            transactions: stripped,
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
@ -588,6 +593,7 @@ class WebsocketHandler {
 | 
			
		||||
          freshTxs: fresh,
 | 
			
		||||
          sigopTxs: sigop,
 | 
			
		||||
          matchRate: matchRate,
 | 
			
		||||
          expectedFees: totalFees
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        if (block.extras) {
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,7 @@ export interface BlockAudit {
 | 
			
		||||
  sigopTxs: string[],
 | 
			
		||||
  addedTxs: string[],
 | 
			
		||||
  matchRate: number,
 | 
			
		||||
  expectedFees: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface AuditScore {
 | 
			
		||||
 | 
			
		||||
@ -6,9 +6,9 @@ import { BlockAudit, AuditScore } from '../mempool.interfaces';
 | 
			
		||||
class BlocksAuditRepositories {
 | 
			
		||||
  public async $saveAudit(audit: BlockAudit): Promise<void> {
 | 
			
		||||
    try {
 | 
			
		||||
      await DB.query(`INSERT INTO blocks_audits(time, height, hash, missing_txs, added_txs, fresh_txs, sigop_txs, match_rate)
 | 
			
		||||
        VALUE (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?)`, [audit.time, audit.height, audit.hash, JSON.stringify(audit.missingTxs),
 | 
			
		||||
          JSON.stringify(audit.addedTxs), JSON.stringify(audit.freshTxs), JSON.stringify(audit.sigopTxs), audit.matchRate]);
 | 
			
		||||
      await DB.query(`INSERT INTO blocks_audits(time, height, hash, missing_txs, added_txs, fresh_txs, sigop_txs, match_rate, expected_fees)
 | 
			
		||||
        VALUE (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?, ?)`, [audit.time, audit.height, audit.hash, JSON.stringify(audit.missingTxs),
 | 
			
		||||
          JSON.stringify(audit.addedTxs), JSON.stringify(audit.freshTxs), JSON.stringify(audit.sigopTxs), audit.matchRate, audit.expectedFees]);
 | 
			
		||||
    } catch (e: any) {
 | 
			
		||||
      if (e.errno === 1062) { // ER_DUP_ENTRY - This scenario is possible upon node backend restart
 | 
			
		||||
        logger.debug(`Cannot save block audit for block ${audit.hash} because it has already been indexed, ignoring`);
 | 
			
		||||
@ -52,7 +52,7 @@ class BlocksAuditRepositories {
 | 
			
		||||
      const [rows]: any[] = await DB.query(
 | 
			
		||||
        `SELECT blocks.height, blocks.hash as id, UNIX_TIMESTAMP(blocks.blockTimestamp) as timestamp, blocks.size,
 | 
			
		||||
        blocks.weight, blocks.tx_count,
 | 
			
		||||
        transactions, template, missing_txs as missingTxs, added_txs as addedTxs, fresh_txs as freshTxs, sigop_txs as sigopTxs, match_rate as matchRate
 | 
			
		||||
        transactions, template, missing_txs as missingTxs, added_txs as addedTxs, fresh_txs as freshTxs, sigop_txs as sigopTxs, match_rate as matchRate, expected_fees as expectedFees
 | 
			
		||||
        FROM blocks_audits
 | 
			
		||||
        JOIN blocks ON blocks.hash = blocks_audits.hash
 | 
			
		||||
        JOIN blocks_summaries ON blocks_summaries.id = blocks_audits.hash
 | 
			
		||||
 | 
			
		||||
@ -72,6 +72,15 @@
 | 
			
		||||
                  </ng-template>
 | 
			
		||||
                </td>
 | 
			
		||||
              </tr>
 | 
			
		||||
              <tr *ngIf="auditAvailable">
 | 
			
		||||
                <td i18n="latest-blocks.expected_fees">Expected total fees</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                  <app-amount [satoshis]="blockAudit?.expectedFees" digitsInfo="1.2-3" [noFiat]="true"></app-amount>
 | 
			
		||||
                  <span class="fiat">
 | 
			
		||||
                    <app-fiat [blockConversion]="blockConversion" [value]="blockAudit?.expectedFees" digitsInfo="1.0-0"></app-fiat>
 | 
			
		||||
                  </span>
 | 
			
		||||
                </td>
 | 
			
		||||
              </tr>
 | 
			
		||||
            </ng-container>
 | 
			
		||||
            <ng-template #skeletonRows>
 | 
			
		||||
              <tr>
 | 
			
		||||
 | 
			
		||||
@ -149,6 +149,7 @@ export interface BlockAudit extends BlockExtended {
 | 
			
		||||
  missingTxs: string[],
 | 
			
		||||
  addedTxs: string[],
 | 
			
		||||
  matchRate: number,
 | 
			
		||||
  expectedFees: number,
 | 
			
		||||
  template: TransactionStripped[],
 | 
			
		||||
  transactions: TransactionStripped[],
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user