disable block audits unless indexing is enabled
This commit is contained in:
		
							parent
							
								
									968d7b827b
								
							
						
					
					
						commit
						6d28259515
					
				@ -4,9 +4,12 @@ import { BlockExtended, TransactionExtended, MempoolBlockWithTransactions } from
 | 
			
		||||
const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first seen after which it is assumed to have propagated to all miners
 | 
			
		||||
 | 
			
		||||
class Audit {
 | 
			
		||||
  auditBlock(block: BlockExtended, txIds: string[], transactions: TransactionExtended[],
 | 
			
		||||
    projectedBlocks: MempoolBlockWithTransactions[], mempool: { [txId: string]: TransactionExtended },
 | 
			
		||||
  ): { censored: string[], added: string[], score: number } {
 | 
			
		||||
  auditBlock(transactions: TransactionExtended[], projectedBlocks: MempoolBlockWithTransactions[], mempool: { [txId: string]: TransactionExtended })
 | 
			
		||||
   : { censored: string[], added: string[], score: number } {
 | 
			
		||||
    if (!projectedBlocks?.[0]?.transactionIds || !mempool) {
 | 
			
		||||
      return { censored: [], added: [], score: 0 };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const matches: string[] = []; // present in both mined block and template
 | 
			
		||||
    const added: string[] = []; // present in mined block, not in template
 | 
			
		||||
    const fresh: string[] = []; // missing, but firstSeen within PROPAGATION_MARGIN
 | 
			
		||||
 | 
			
		||||
@ -250,8 +250,6 @@ class WebsocketHandler {
 | 
			
		||||
      throw new Error('WebSocket.Server is not set');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    logger.debug("mempool changed!");
 | 
			
		||||
 | 
			
		||||
    mempoolBlocks.updateMempoolBlocks(newMempool);
 | 
			
		||||
    const mBlocks = mempoolBlocks.getMempoolBlocks();
 | 
			
		||||
    const mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
 | 
			
		||||
@ -417,55 +415,54 @@ class WebsocketHandler {
 | 
			
		||||
    let mBlockDeltas: undefined | MempoolBlockDelta[];
 | 
			
		||||
    let matchRate = 0;
 | 
			
		||||
    const _memPool = memPool.getMempool();
 | 
			
		||||
    const mempoolCopy = cloneMempool(_memPool);
 | 
			
		||||
 | 
			
		||||
    const projectedBlocks = mempoolBlocks.makeBlockTemplates(mempoolCopy, 2);
 | 
			
		||||
    if (Common.indexingEnabled()) {
 | 
			
		||||
      const mempoolCopy = cloneMempool(_memPool);
 | 
			
		||||
      const projectedBlocks = mempoolBlocks.makeBlockTemplates(mempoolCopy, 2);
 | 
			
		||||
 | 
			
		||||
    if (projectedBlocks[0]) {
 | 
			
		||||
      const { censored, added, score } = Audit.auditBlock(block, txIds, transactions, projectedBlocks, mempoolCopy);
 | 
			
		||||
      const { censored, added, score } = Audit.auditBlock(transactions, projectedBlocks, mempoolCopy);
 | 
			
		||||
      matchRate = Math.round(score * 100 * 100) / 100;
 | 
			
		||||
 | 
			
		||||
      // Update mempool to remove transactions included in the new block
 | 
			
		||||
      for (const txId of txIds) {
 | 
			
		||||
        delete _memPool[txId];
 | 
			
		||||
      }
 | 
			
		||||
      const stripped = projectedBlocks[0]?.transactions ? projectedBlocks[0].transactions.map((tx) => {
 | 
			
		||||
        return {
 | 
			
		||||
          txid: tx.txid,
 | 
			
		||||
          vsize: tx.vsize,
 | 
			
		||||
          fee: tx.fee ? Math.round(tx.fee) : 0,
 | 
			
		||||
          value: tx.value,
 | 
			
		||||
        };
 | 
			
		||||
      }) : [];
 | 
			
		||||
 | 
			
		||||
      mempoolBlocks.updateMempoolBlocks(_memPool);
 | 
			
		||||
      mBlocks = mempoolBlocks.getMempoolBlocks();
 | 
			
		||||
      mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
 | 
			
		||||
      BlocksSummariesRepository.$saveSummary({
 | 
			
		||||
        height: block.height,
 | 
			
		||||
        template: {
 | 
			
		||||
          id: block.id,
 | 
			
		||||
          transactions: stripped
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      if (Common.indexingEnabled()) {
 | 
			
		||||
        const stripped = projectedBlocks[0].transactions.map((tx) => {
 | 
			
		||||
          return {
 | 
			
		||||
            txid: tx.txid,
 | 
			
		||||
            vsize: tx.vsize,
 | 
			
		||||
            fee: tx.fee ? Math.round(tx.fee) : 0,
 | 
			
		||||
            value: tx.value,
 | 
			
		||||
          };
 | 
			
		||||
        });
 | 
			
		||||
        BlocksSummariesRepository.$saveSummary({
 | 
			
		||||
          height: block.height,
 | 
			
		||||
          template: {
 | 
			
		||||
            id: block.id,
 | 
			
		||||
            transactions: stripped
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
      BlocksAuditsRepository.$saveAudit({
 | 
			
		||||
        time: block.timestamp,
 | 
			
		||||
        height: block.height,
 | 
			
		||||
        hash: block.id,
 | 
			
		||||
        addedTxs: added,
 | 
			
		||||
        missingTxs: censored,
 | 
			
		||||
        matchRate: matchRate,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
        BlocksAuditsRepository.$saveAudit({
 | 
			
		||||
          time: block.timestamp,
 | 
			
		||||
          height: block.height,
 | 
			
		||||
          hash: block.id,
 | 
			
		||||
          addedTxs: added,
 | 
			
		||||
          missingTxs: censored,
 | 
			
		||||
          matchRate: matchRate,
 | 
			
		||||
        });
 | 
			
		||||
      if (block.extras) {
 | 
			
		||||
        block.extras.matchRate = matchRate;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (block.extras) {
 | 
			
		||||
      block.extras.matchRate = matchRate;
 | 
			
		||||
    // Update mempool to remove transactions included in the new block
 | 
			
		||||
    for (const txId of txIds) {
 | 
			
		||||
      delete _memPool[txId];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mempoolBlocks.updateMempoolBlocks(_memPool);
 | 
			
		||||
    mBlocks = mempoolBlocks.getMempoolBlocks();
 | 
			
		||||
    mBlockDeltas = mempoolBlocks.getMempoolBlockDeltas();
 | 
			
		||||
 | 
			
		||||
    const da = difficultyAdjustment.getDifficultyAdjustment();
 | 
			
		||||
    const fees = feeApi.getRecommendedFee();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user