Limit GBT: fix on-demand CPFP calculation
This commit is contained in:
		
							parent
							
								
									07c76d084e
								
							
						
					
					
						commit
						8f2e1de578
					
				| @ -1,4 +1,5 @@ | ||||
| import { CpfpInfo, MempoolTransactionExtended } from '../mempool.interfaces'; | ||||
| import memPool from './mempool'; | ||||
| 
 | ||||
| const CPFP_UPDATE_INTERVAL = 60_000; // update CPFP info at most once per 60s per transaction
 | ||||
| const MAX_GRAPH_SIZE = 50; // the maximum number of in-mempool relatives to consider
 | ||||
| @ -77,8 +78,8 @@ export function calculateCpfp(tx: MempoolTransactionExtended, mempool: { [txid: | ||||
| function mempoolToGraphTx(tx: MempoolTransactionExtended): GraphTx { | ||||
|   return { | ||||
|     ...tx, | ||||
|     depends: [], | ||||
|     spentby: [], | ||||
|     depends: tx.vin.map(v => v.txid), | ||||
|     spentby: tx.vout.map((v, i) => memPool.getFromSpendMap(tx.txid, i)).map(tx => tx?.txid).filter(txid => txid != null) as string[], | ||||
|     ancestorMap: new Map(), | ||||
|     fees: { | ||||
|       base: tx.fee, | ||||
| @ -176,7 +177,7 @@ function calculateCpfpCluster(txid: string, graph: Map<string, GraphTx>): Map<st | ||||
|   let bestCluster = new Map<string, GraphTx>(best?.ancestorMap?.entries() || []); | ||||
|   while (sortedRelatives.length && best && (best.txid !== tx.txid && !best.ancestorMap.has(tx.txid)) && maxIterations > 0) { | ||||
|     maxIterations--; | ||||
|     if (bestCluster && bestCluster.has(tx.txid)) { | ||||
|     if ((best && best.txid === tx.txid) || (bestCluster && bestCluster.has(tx.txid))) { | ||||
|       break; | ||||
|     } else { | ||||
|       // Remove this cluster (it doesn't include our target tx)
 | ||||
| @ -195,6 +196,8 @@ function calculateCpfpCluster(txid: string, graph: Map<string, GraphTx>): Map<st | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   bestCluster.set(tx.txid, tx); | ||||
| 
 | ||||
|   return bestCluster; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -420,16 +420,6 @@ class MempoolBlocks { | ||||
|             block: blockIndex, | ||||
|             vsize: totalVsize + (mempoolTx.vsize / 2), | ||||
|           }; | ||||
|           if (!mempoolTx.cpfpChecked) { | ||||
|             if (mempoolTx.ancestors?.length) { | ||||
|               mempoolTx.ancestors = []; | ||||
|             } | ||||
|             if (mempoolTx.descendants?.length) { | ||||
|               mempoolTx.descendants = []; | ||||
|             } | ||||
|             mempoolTx.bestDescendant = null; | ||||
|             mempoolTx.cpfpChecked = true; | ||||
|           } | ||||
| 
 | ||||
|           const acceleration = accelerations[txid]; | ||||
|           if (isAccelerated[txid] || (acceleration && (!accelerationPool || acceleration.pools.includes(accelerationPool)))) { | ||||
|  | ||||
| @ -91,6 +91,10 @@ class Mempool { | ||||
|     return this.spendMap; | ||||
|   } | ||||
| 
 | ||||
|   public getFromSpendMap(txid, index): MempoolTransactionExtended | void { | ||||
|     return this.spendMap.get(`${txid}:${index}`); | ||||
|   } | ||||
| 
 | ||||
|   public async $setMempool(mempoolData: { [txId: string]: MempoolTransactionExtended }) { | ||||
|     this.mempoolCache = mempoolData; | ||||
|     let count = 0; | ||||
| @ -113,6 +117,9 @@ class Mempool { | ||||
|         await redisCache.$addTransaction(this.mempoolCache[txid]); | ||||
|       } | ||||
|       this.mempoolCache[txid].flags = Common.getTransactionFlags(this.mempoolCache[txid]); | ||||
|       this.mempoolCache[txid].cpfpChecked = false; | ||||
|       this.mempoolCache[txid].cpfpDirty = true; | ||||
|       this.mempoolCache[txid].cpfpUpdated = undefined; | ||||
|     } | ||||
|     if (config.MEMPOOL.CACHE_ENABLED && config.REDIS.ENABLED) { | ||||
|       await redisCache.$flushTransactions(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user