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