From 70fa78b987083bd70425a81ba799695fa8096e87 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 18 May 2023 13:35:02 -0400 Subject: [PATCH] Fix effective fee rates for non-cpfp dependents --- backend/src/api/tx-selection-worker.ts | 6 ++++-- backend/src/mempool.interfaces.ts | 1 + .../transaction/transaction.component.html | 4 ++-- .../transaction/transaction.component.ts | 19 +++++++++++-------- .../src/app/interfaces/node-api.interface.ts | 1 + 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/src/api/tx-selection-worker.ts b/backend/src/api/tx-selection-worker.ts index b22f42823..5bca59958 100644 --- a/backend/src/api/tx-selection-worker.ts +++ b/backend/src/api/tx-selection-worker.ts @@ -127,7 +127,7 @@ function makeBlockTemplates(mempool: Map) cpfpClusters.set(nextTx.uid, sortedTxSet.map(tx => tx.uid)); isCluster = true; } - const effectiveFeeRate = nextTx.ancestorFee / (nextTx.ancestorWeight / 4); + const effectiveFeeRate = Math.min(nextTx.dependencyRate || Infinity, nextTx.ancestorFee / (nextTx.ancestorWeight / 4)); const used: AuditTransaction[] = []; while (sortedTxSet.length) { const ancestor = sortedTxSet.pop(); @@ -155,7 +155,7 @@ function makeBlockTemplates(mempool: Map) // remove these as valid package ancestors for any descendants remaining in the mempool if (used.length) { used.forEach(tx => { - updateDescendants(tx, auditPool, modified); + updateDescendants(tx, auditPool, modified, effectiveFeeRate); }); } @@ -251,6 +251,7 @@ function updateDescendants( rootTx: AuditTransaction, mempool: Map, modified: PairingHeap, + clusterRate: number, ): void { const descendantSet: Set = new Set(); // stack of nodes left to visit @@ -272,6 +273,7 @@ function updateDescendants( descendantTx.ancestorWeight -= rootTx.weight; tmpScore = descendantTx.score; descendantTx.score = descendantTx.ancestorFee / (descendantTx.ancestorWeight / 4); + descendantTx.dependencyRate = descendantTx.dependencyRate ? Math.min(descendantTx.dependencyRate, clusterRate) : clusterRate; if (!descendantTx.modifiedNode) { descendantTx.modified = true; diff --git a/backend/src/mempool.interfaces.ts b/backend/src/mempool.interfaces.ts index 63f33d222..14114fa2c 100644 --- a/backend/src/mempool.interfaces.ts +++ b/backend/src/mempool.interfaces.ts @@ -104,6 +104,7 @@ export interface AuditTransaction { used: boolean; modified: boolean; modifiedNode: HeapNode; + dependencyRate?: number; } export interface CompactThreadTransaction { diff --git a/frontend/src/app/components/transaction/transaction.component.html b/frontend/src/app/components/transaction/transaction.component.html index 4bae3e792..30d74e24d 100644 --- a/frontend/src/app/components/transaction/transaction.component.html +++ b/frontend/src/app/components/transaction/transaction.component.html @@ -481,7 +481,7 @@ - + Effective fee rate
@@ -490,7 +490,7 @@
- + diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 3bfc8400a..e548fdc46 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -164,14 +164,17 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { if (cpfpInfo.bestDescendant && !cpfpInfo.descendants?.length) { relatives.push(cpfpInfo.bestDescendant); } - let totalWeight = - this.tx.weight + - relatives.reduce((prev, val) => prev + val.weight, 0); - let totalFees = - this.tx.fee + - relatives.reduce((prev, val) => prev + val.fee, 0); - - this.tx.effectiveFeePerVsize = totalFees / (totalWeight / 4); + if (!cpfpInfo.effectiveFeePerVsize) { + let totalWeight = + this.tx.weight + + relatives.reduce((prev, val) => prev + val.weight, 0); + let totalFees = + this.tx.fee + + relatives.reduce((prev, val) => prev + val.fee, 0); + this.tx.effectiveFeePerVsize = totalFees / (totalWeight / 4); + } else { + this.tx.effectiveFeePerVsize = cpfpInfo.effectiveFeePerVsize; + } this.cpfpInfo = cpfpInfo; }); diff --git a/frontend/src/app/interfaces/node-api.interface.ts b/frontend/src/app/interfaces/node-api.interface.ts index 321ee5841..106b875d2 100644 --- a/frontend/src/app/interfaces/node-api.interface.ts +++ b/frontend/src/app/interfaces/node-api.interface.ts @@ -24,6 +24,7 @@ export interface CpfpInfo { ancestors: Ancestor[]; descendants?: Ancestor[]; bestDescendant?: BestDescendant | null; + effectiveFeePerVsize?: number; } export interface RbfInfo {