Fix & reenable cpfp indexer optimized path
This commit is contained in:
		
							parent
							
								
									07987ff4b6
								
							
						
					
					
						commit
						fb137e6247
					
				@ -742,7 +742,7 @@ class Blocks {
 | 
			
		||||
 | 
			
		||||
  public async $indexCPFP(hash: string, height: number): Promise<void> {
 | 
			
		||||
    let transactions;
 | 
			
		||||
    if (false/*Common.blocksSummariesIndexingEnabled()*/) {
 | 
			
		||||
    if (Common.blocksSummariesIndexingEnabled()) {
 | 
			
		||||
      transactions = await this.$getStrippedBlockTransactions(hash);
 | 
			
		||||
      const rawBlock = await bitcoinApi.$getRawBlock(hash);
 | 
			
		||||
      const block = Block.fromBuffer(rawBlock);
 | 
			
		||||
@ -751,10 +751,11 @@ class Blocks {
 | 
			
		||||
        txMap[tx.getId()] = tx;
 | 
			
		||||
      }
 | 
			
		||||
      for (const tx of transactions) {
 | 
			
		||||
        // convert from bitcoinjs to esplora vin format
 | 
			
		||||
        if (txMap[tx.txid]?.ins) {
 | 
			
		||||
          tx.vin = txMap[tx.txid].ins.map(vin => {
 | 
			
		||||
            return {
 | 
			
		||||
              txid: vin.hash
 | 
			
		||||
              txid: vin.hash.slice().reverse().toString('hex')
 | 
			
		||||
            };
 | 
			
		||||
          });
 | 
			
		||||
        }
 | 
			
		||||
@ -763,6 +764,7 @@ class Blocks {
 | 
			
		||||
      const block = await bitcoinClient.getBlock(hash, 2);
 | 
			
		||||
      transactions = block.tx.map(tx => {
 | 
			
		||||
        tx.vsize = tx.weight / 4;
 | 
			
		||||
        tx.fee *= 100_000_000;
 | 
			
		||||
        return tx;
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
@ -778,9 +780,9 @@ class Blocks {
 | 
			
		||||
          totalFee += tx?.fee || 0;
 | 
			
		||||
          totalVSize += tx.vsize;
 | 
			
		||||
        });
 | 
			
		||||
        const effectiveFeePerVsize = (totalFee * 100_000_000) / totalVSize;
 | 
			
		||||
        const effectiveFeePerVsize = totalFee / totalVSize;
 | 
			
		||||
        if (cluster.length > 1) {
 | 
			
		||||
          await cpfpRepository.$saveCluster(height, cluster.map(tx => { return { txid: tx.txid, weight: tx.vsize * 4, fee: (tx.fee || 0) * 100_000_000 }; }), effectiveFeePerVsize);
 | 
			
		||||
          await cpfpRepository.$saveCluster(height, cluster.map(tx => { return { txid: tx.txid, weight: tx.vsize * 4, fee: tx.fee || 0 }; }), effectiveFeePerVsize);
 | 
			
		||||
          for (const tx of cluster) {
 | 
			
		||||
            await transactionRepository.$setCluster(tx.txid, cluster[0].txid);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@ -44,8 +44,10 @@ class TransactionRepository {
 | 
			
		||||
      const [rows]: any = await DB.query(query, [txid]);
 | 
			
		||||
      if (rows.length) {
 | 
			
		||||
        rows[0].txs = JSON.parse(rows[0].txs) as Ancestor[];
 | 
			
		||||
        if (rows[0]?.txs?.length) {
 | 
			
		||||
          return this.convertCpfp(rows[0]);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      logger.err('Cannot get transaction cpfp info from db. Reason: ' + (e instanceof Error ? e.message : e));
 | 
			
		||||
      throw e;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user