Fix errors in block audit tx selection algorithm
This commit is contained in:
parent
702ff2796a
commit
39afa4cda1
@ -207,10 +207,10 @@ class MempoolBlocks {
|
|||||||
if (nextTxSet && blockWeight + nextTxSet.weight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) {
|
if (nextTxSet && blockWeight + nextTxSet.weight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) {
|
||||||
blockWeight += nextTxSet.weight;
|
blockWeight += nextTxSet.weight;
|
||||||
// sort txSet by dependency graph (equivalent to sorting by ascending ancestor count)
|
// sort txSet by dependency graph (equivalent to sorting by ascending ancestor count)
|
||||||
const sortedTxSet = nextTx.ancestors.sort((a, b) => {
|
const sortedTxSet = [...nextTx.ancestors.sort((a, b) => {
|
||||||
return (mempool[a.txid]?.ancestors?.length || 0) - (mempool[b.txid]?.ancestors?.length || 0);
|
return (mempool[a.txid]?.ancestors?.length || 0) - (mempool[b.txid]?.ancestors?.length || 0);
|
||||||
});
|
}), nextTx];
|
||||||
[...sortedTxSet, nextTx].forEach((ancestor, i, arr) => {
|
sortedTxSet.forEach((ancestor, i, arr) => {
|
||||||
const tx = mempool[ancestor.txid];
|
const tx = mempool[ancestor.txid];
|
||||||
const txSet = txSets[ancestor.txid];
|
const txSet = txSets[ancestor.txid];
|
||||||
if (txSet.available) {
|
if (txSet.available) {
|
||||||
@ -340,7 +340,7 @@ class MempoolBlocks {
|
|||||||
if (txSet.children) {
|
if (txSet.children) {
|
||||||
txSet.children.forEach(childId => {
|
txSet.children.forEach(childId => {
|
||||||
const child = mempool[childId];
|
const child = mempool[childId];
|
||||||
if (child && child.ancestors && txSets[childId]?.available) {
|
if (child && child.ancestors) {
|
||||||
const ancestorIndex = child.ancestors.findIndex(a => a.txid === root.txid);
|
const ancestorIndex = child.ancestors.findIndex(a => a.txid === root.txid);
|
||||||
if (ancestorIndex > -1) {
|
if (ancestorIndex > -1) {
|
||||||
// remove tx as ancestor
|
// remove tx as ancestor
|
||||||
@ -355,11 +355,12 @@ class MempoolBlocks {
|
|||||||
childTxSet.modified = true;
|
childTxSet.modified = true;
|
||||||
modified.push(child);
|
modified.push(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursively update grandchildren
|
|
||||||
anyModified = this.updateDescendants(root, child, mempool, txSets, modified) || anyModified;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// recursively update grandchildren
|
||||||
|
if (child) {
|
||||||
|
anyModified = this.updateDescendants(root, child, mempool, txSets, modified) || anyModified;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return anyModified;
|
return anyModified;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user