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 { 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 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
|
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 {
|
function mempoolToGraphTx(tx: MempoolTransactionExtended): GraphTx {
|
||||||
return {
|
return {
|
||||||
...tx,
|
...tx,
|
||||||
depends: [],
|
depends: tx.vin.map(v => v.txid),
|
||||||
spentby: [],
|
spentby: tx.vout.map((v, i) => memPool.getFromSpendMap(tx.txid, i)).map(tx => tx?.txid).filter(txid => txid != null) as string[],
|
||||||
ancestorMap: new Map(),
|
ancestorMap: new Map(),
|
||||||
fees: {
|
fees: {
|
||||||
base: tx.fee,
|
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() || []);
|
let bestCluster = new Map<string, GraphTx>(best?.ancestorMap?.entries() || []);
|
||||||
while (sortedRelatives.length && best && (best.txid !== tx.txid && !best.ancestorMap.has(tx.txid)) && maxIterations > 0) {
|
while (sortedRelatives.length && best && (best.txid !== tx.txid && !best.ancestorMap.has(tx.txid)) && maxIterations > 0) {
|
||||||
maxIterations--;
|
maxIterations--;
|
||||||
if (bestCluster && bestCluster.has(tx.txid)) {
|
if ((best && best.txid === tx.txid) || (bestCluster && bestCluster.has(tx.txid))) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
// Remove this cluster (it doesn't include our target tx)
|
// 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;
|
return bestCluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,16 +420,6 @@ class MempoolBlocks {
|
|||||||
block: blockIndex,
|
block: blockIndex,
|
||||||
vsize: totalVsize + (mempoolTx.vsize / 2),
|
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];
|
const acceleration = accelerations[txid];
|
||||||
if (isAccelerated[txid] || (acceleration && (!accelerationPool || acceleration.pools.includes(accelerationPool)))) {
|
if (isAccelerated[txid] || (acceleration && (!accelerationPool || acceleration.pools.includes(accelerationPool)))) {
|
||||||
|
@ -91,6 +91,10 @@ class Mempool {
|
|||||||
return this.spendMap;
|
return this.spendMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getFromSpendMap(txid, index): MempoolTransactionExtended | void {
|
||||||
|
return this.spendMap.get(`${txid}:${index}`);
|
||||||
|
}
|
||||||
|
|
||||||
public async $setMempool(mempoolData: { [txId: string]: MempoolTransactionExtended }) {
|
public async $setMempool(mempoolData: { [txId: string]: MempoolTransactionExtended }) {
|
||||||
this.mempoolCache = mempoolData;
|
this.mempoolCache = mempoolData;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
@ -113,6 +117,9 @@ class Mempool {
|
|||||||
await redisCache.$addTransaction(this.mempoolCache[txid]);
|
await redisCache.$addTransaction(this.mempoolCache[txid]);
|
||||||
}
|
}
|
||||||
this.mempoolCache[txid].flags = Common.getTransactionFlags(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) {
|
if (config.MEMPOOL.CACHE_ENABLED && config.REDIS.ENABLED) {
|
||||||
await redisCache.$flushTransactions();
|
await redisCache.$flushTransactions();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user