diff --git a/backend/src/api/mempool-blocks.ts b/backend/src/api/mempool-blocks.ts index 51f07fac6..9b5da8b3b 100644 --- a/backend/src/api/mempool-blocks.ts +++ b/backend/src/api/mempool-blocks.ts @@ -223,6 +223,7 @@ class MempoolBlocks { uid: entry.uid, fee: entry.fee, weight: (entry.adjustedVsize * 4), + sigops: entry.sigops, feePerVsize: entry.adjustedFeePerVsize || entry.feePerVsize, effectiveFeePerVsize: entry.effectiveFeePerVsize || entry.adjustedFeePerVsize || entry.feePerVsize, inputs: entry.vin.map(v => this.getUid(newMempool[v.txid])).filter(uid => uid != null) as number[], @@ -288,6 +289,7 @@ class MempoolBlocks { uid: entry.uid || 0, fee: entry.fee, weight: (entry.adjustedVsize * 4), + sigops: entry.sigops, feePerVsize: entry.adjustedFeePerVsize || entry.feePerVsize, effectiveFeePerVsize: entry.effectiveFeePerVsize || entry.adjustedFeePerVsize || entry.feePerVsize, inputs: entry.vin.map(v => this.getUid(newMempool[v.txid])).filter(uid => uid != null) as number[], diff --git a/backend/src/api/tx-selection-worker.ts b/backend/src/api/tx-selection-worker.ts index 5bca59958..0acc2f65e 100644 --- a/backend/src/api/tx-selection-worker.ts +++ b/backend/src/api/tx-selection-worker.ts @@ -48,12 +48,14 @@ function makeBlockTemplates(mempool: Map) weight: tx.weight, feePerVsize: tx.feePerVsize, effectiveFeePerVsize: tx.feePerVsize, + sigops: tx.sigops, inputs: tx.inputs || [], relativesSet: false, ancestorMap: new Map(), children: new Set(), ancestorFee: 0, ancestorWeight: 0, + ancestorSigops: 0, score: 0, used: false, modified: false, @@ -83,6 +85,7 @@ function makeBlockTemplates(mempool: Map) // (i.e. the package rooted in the transaction with the best ancestor score) const blocks: number[][] = []; let blockWeight = 4000; + let blockSigops = 0; let transactions: AuditTransaction[] = []; const modified: PairingHeap = new PairingHeap((a, b): boolean => { if (a.score === b.score) { @@ -118,7 +121,7 @@ function makeBlockTemplates(mempool: Map) if (nextTx && !nextTx?.used) { // Check if the package fits into this block - if (blocks.length >= 7 || (blockWeight + nextTx.ancestorWeight < config.MEMPOOL.BLOCK_WEIGHT_UNITS)) { + if (blocks.length >= 7 || ((blockWeight + nextTx.ancestorWeight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) && (blockSigops + nextTx.ancestorSigops <= 80000))) { const ancestors: AuditTransaction[] = Array.from(nextTx.ancestorMap.values()); // 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]; @@ -237,9 +240,11 @@ function setRelatives( }; tx.ancestorFee = tx.fee || 0; tx.ancestorWeight = tx.weight || 0; + tx.ancestorSigops = tx.sigops || 0; tx.ancestorMap.forEach((ancestor) => { tx.ancestorFee += ancestor.fee; tx.ancestorWeight += ancestor.weight; + tx.ancestorSigops += ancestor.sigops; }); tx.score = tx.ancestorFee / ((tx.ancestorWeight / 4) || 1); tx.relativesSet = true; @@ -271,6 +276,7 @@ function updateDescendants( descendantTx.ancestorMap.delete(rootTx.uid); descendantTx.ancestorFee -= rootTx.fee; descendantTx.ancestorWeight -= rootTx.weight; + descendantTx.ancestorSigops -= rootTx.sigops; tmpScore = descendantTx.score; descendantTx.score = descendantTx.ancestorFee / (descendantTx.ancestorWeight / 4); descendantTx.dependencyRate = descendantTx.dependencyRate ? Math.min(descendantTx.dependencyRate, clusterRate) : clusterRate; diff --git a/backend/src/mempool.interfaces.ts b/backend/src/mempool.interfaces.ts index e7fba439d..c3e0d02ba 100644 --- a/backend/src/mempool.interfaces.ts +++ b/backend/src/mempool.interfaces.ts @@ -100,12 +100,14 @@ export interface AuditTransaction { weight: number; feePerVsize: number; effectiveFeePerVsize: number; + sigops: number; inputs: number[]; relativesSet: boolean; ancestorMap: Map; children: Set; ancestorFee: number; ancestorWeight: number; + ancestorSigops: number; score: number; used: boolean; modified: boolean; @@ -117,6 +119,7 @@ export interface CompactThreadTransaction { uid: number; fee: number; weight: number; + sigops: number; feePerVsize: number; effectiveFeePerVsize?: number; inputs: number[];