Merge pull request #2778 from mempool/mononaut/advanced-gbt-fixes

Fix bugs related to advanced GBT transaction selection
This commit is contained in:
softsimon 2022-12-07 16:13:16 +04:00 committed by GitHub
commit c59ab2a129
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 28 deletions

View File

@ -106,44 +106,44 @@ function makeBlockTemplates({ mempool, blockLimit, weightLimit, condenseRest }:
if (nextTx && !nextTx?.used) { if (nextTx && !nextTx?.used) {
// Check if the package fits into this block // Check if the package fits into this block
if (blockWeight + nextTx.ancestorWeight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) { if (blockWeight + nextTx.ancestorWeight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) {
blockWeight += nextTx.ancestorWeight;
const ancestors: AuditTransaction[] = Array.from(nextTx.ancestorMap.values()); const ancestors: AuditTransaction[] = Array.from(nextTx.ancestorMap.values());
const descendants: AuditTransaction[] = []; 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);
const used: AuditTransaction[] = [];
while (sortedTxSet.length) { while (sortedTxSet.length) {
const ancestor = sortedTxSet.pop(); const ancestor = sortedTxSet.pop();
const mempoolTx = mempool[ancestor.txid]; const mempoolTx = mempool[ancestor.txid];
if (ancestor && !ancestor?.used) { ancestor.used = true;
ancestor.used = true; ancestor.usedBy = nextTx.txid;
// 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 = sortedTxSet.map((a) => { mempoolTx.ancestors = sortedTxSet.map((a) => {
return { return {
txid: a.txid, txid: a.txid,
fee: a.fee, fee: a.fee,
weight: a.weight, weight: a.weight,
}; };
}).reverse(); }).reverse();
mempoolTx.descendants = descendants.map((a) => { 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); descendants.push(ancestor);
mempoolTx.cpfpChecked = true; mempoolTx.cpfpChecked = true;
transactions.push(ancestor); transactions.push(ancestor);
blockSize += ancestor.size; blockSize += ancestor.size;
} blockWeight += ancestor.weight;
used.push(ancestor);
} }
// 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 (used.length) {
sortedTxSet.forEach(tx => { used.forEach(tx => {
updateDescendants(tx, auditPool, modified); updateDescendants(tx, auditPool, modified);
}); });
} }

View File

@ -468,7 +468,7 @@ class WebsocketHandler {
} }
if (config.MEMPOOL.ADVANCED_GBT_MEMPOOL) { if (config.MEMPOOL.ADVANCED_GBT_MEMPOOL) {
await mempoolBlocks.makeBlockTemplates(_memPool, 2); await mempoolBlocks.makeBlockTemplates(_memPool, 8, null, true);
} else { } else {
mempoolBlocks.updateMempoolBlocks(_memPool); mempoolBlocks.updateMempoolBlocks(_memPool);
} }