return more complete cpfp data for mempool transactions
This commit is contained in:
parent
3e7270d1c5
commit
205d832d31
@ -201,6 +201,8 @@ class BitcoinRoutes {
|
|||||||
res.json({
|
res.json({
|
||||||
ancestors: tx.ancestors,
|
ancestors: tx.ancestors,
|
||||||
bestDescendant: tx.bestDescendant || null,
|
bestDescendant: tx.bestDescendant || null,
|
||||||
|
descendants: tx.descendants || null,
|
||||||
|
effectiveFeePerVsize: tx.effectiveFeePerVsize || null,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,7 @@ class MempoolBlocks {
|
|||||||
if (newMempool[txid] && mempool[txid]) {
|
if (newMempool[txid] && mempool[txid]) {
|
||||||
newMempool[txid].effectiveFeePerVsize = mempool[txid].effectiveFeePerVsize;
|
newMempool[txid].effectiveFeePerVsize = mempool[txid].effectiveFeePerVsize;
|
||||||
newMempool[txid].ancestors = mempool[txid].ancestors;
|
newMempool[txid].ancestors = mempool[txid].ancestors;
|
||||||
|
newMempool[txid].descendants = mempool[txid].descendants;
|
||||||
newMempool[txid].bestDescendant = mempool[txid].bestDescendant;
|
newMempool[txid].bestDescendant = mempool[txid].bestDescendant;
|
||||||
newMempool[txid].cpfpChecked = mempool[txid].cpfpChecked;
|
newMempool[txid].cpfpChecked = mempool[txid].cpfpChecked;
|
||||||
}
|
}
|
||||||
|
@ -108,36 +108,38 @@ function makeBlockTemplates({ mempool, blockLimit, weightLimit, condenseRest }:
|
|||||||
if (blockWeight + nextTx.ancestorWeight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) {
|
if (blockWeight + nextTx.ancestorWeight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) {
|
||||||
blockWeight += nextTx.ancestorWeight;
|
blockWeight += nextTx.ancestorWeight;
|
||||||
const ancestors: AuditTransaction[] = Array.from(nextTx.ancestorMap.values());
|
const ancestors: AuditTransaction[] = Array.from(nextTx.ancestorMap.values());
|
||||||
|
const descendants: AuditTransaction[] = [];
|
||||||
// sort ancestors by dependency graph (equivalent to sorting by ascending ancestor count)
|
// sort ancestors by dependency graph (equivalent to sorting by ascending ancestor count)
|
||||||
const sortedTxSet = [...ancestors.sort((a, b) => { return (a.ancestorMap.size || 0) - (b.ancestorMap.size || 0); }), nextTx];
|
const sortedTxSet = [...ancestors.sort((a, b) => { return (a.ancestorMap.size || 0) - (b.ancestorMap.size || 0); }), nextTx];
|
||||||
const effectiveFeeRate = nextTx.ancestorFee / (nextTx.ancestorWeight / 4);
|
const effectiveFeeRate = nextTx.ancestorFee / (nextTx.ancestorWeight / 4);
|
||||||
sortedTxSet.forEach((ancestor, i, arr) => {
|
|
||||||
|
while (sortedTxSet.length) {
|
||||||
|
const ancestor = sortedTxSet.pop();
|
||||||
const mempoolTx = mempool[ancestor.txid];
|
const mempoolTx = mempool[ancestor.txid];
|
||||||
if (ancestor && !ancestor?.used) {
|
if (ancestor && !ancestor?.used) {
|
||||||
ancestor.used = true;
|
ancestor.used = true;
|
||||||
// update original copy of this tx with effective fee rate & relatives data
|
// update original copy of this tx with effective fee rate & relatives data
|
||||||
mempoolTx.effectiveFeePerVsize = effectiveFeeRate;
|
mempoolTx.effectiveFeePerVsize = effectiveFeeRate;
|
||||||
mempoolTx.ancestors = (Array.from(ancestor.ancestorMap?.values()) as AuditTransaction[]).map((a) => {
|
mempoolTx.ancestors = sortedTxSet.map((a) => {
|
||||||
|
return {
|
||||||
|
txid: a.txid,
|
||||||
|
fee: a.fee,
|
||||||
|
weight: a.weight,
|
||||||
|
};
|
||||||
|
}).reverse();
|
||||||
|
mempoolTx.descendants = descendants.map((a) => {
|
||||||
return {
|
return {
|
||||||
txid: a.txid,
|
txid: a.txid,
|
||||||
fee: a.fee,
|
fee: a.fee,
|
||||||
weight: a.weight,
|
weight: a.weight,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
descendants.push(ancestor);
|
||||||
mempoolTx.cpfpChecked = true;
|
mempoolTx.cpfpChecked = true;
|
||||||
if (i < arr.length - 1) {
|
|
||||||
mempoolTx.bestDescendant = {
|
|
||||||
txid: arr[arr.length - 1].txid,
|
|
||||||
fee: arr[arr.length - 1].fee,
|
|
||||||
weight: arr[arr.length - 1].weight,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
mempoolTx.bestDescendant = null;
|
|
||||||
}
|
|
||||||
transactions.push(ancestor);
|
transactions.push(ancestor);
|
||||||
blockSize += ancestor.size;
|
blockSize += ancestor.size;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// remove these as valid package ancestors for any descendants remaining in the mempool
|
// remove these as valid package ancestors for any descendants remaining in the mempool
|
||||||
if (sortedTxSet.length) {
|
if (sortedTxSet.length) {
|
||||||
|
@ -72,6 +72,7 @@ export interface TransactionExtended extends IEsploraApi.Transaction {
|
|||||||
firstSeen?: number;
|
firstSeen?: number;
|
||||||
effectiveFeePerVsize: number;
|
effectiveFeePerVsize: number;
|
||||||
ancestors?: Ancestor[];
|
ancestors?: Ancestor[];
|
||||||
|
descendants?: Ancestor[];
|
||||||
bestDescendant?: BestDescendant | null;
|
bestDescendant?: BestDescendant | null;
|
||||||
cpfpChecked?: boolean;
|
cpfpChecked?: boolean;
|
||||||
deleteAfter?: number;
|
deleteAfter?: number;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user