Fix effective fee rates for non-cpfp dependents

This commit is contained in:
Mononaut 2023-05-18 13:35:02 -04:00
parent 126a75ed45
commit 70fa78b987
No known key found for this signature in database
GPG key ID: A3F058E41374C04E
5 changed files with 19 additions and 12 deletions

View file

@ -127,7 +127,7 @@ function makeBlockTemplates(mempool: Map<number, CompactThreadTransaction>)
cpfpClusters.set(nextTx.uid, sortedTxSet.map(tx => tx.uid)); cpfpClusters.set(nextTx.uid, sortedTxSet.map(tx => tx.uid));
isCluster = true; isCluster = true;
} }
const effectiveFeeRate = nextTx.ancestorFee / (nextTx.ancestorWeight / 4); const effectiveFeeRate = Math.min(nextTx.dependencyRate || Infinity, nextTx.ancestorFee / (nextTx.ancestorWeight / 4));
const used: AuditTransaction[] = []; const used: AuditTransaction[] = [];
while (sortedTxSet.length) { while (sortedTxSet.length) {
const ancestor = sortedTxSet.pop(); const ancestor = sortedTxSet.pop();
@ -155,7 +155,7 @@ function makeBlockTemplates(mempool: Map<number, CompactThreadTransaction>)
// 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 (used.length) { if (used.length) {
used.forEach(tx => { used.forEach(tx => {
updateDescendants(tx, auditPool, modified); updateDescendants(tx, auditPool, modified, effectiveFeeRate);
}); });
} }
@ -251,6 +251,7 @@ function updateDescendants(
rootTx: AuditTransaction, rootTx: AuditTransaction,
mempool: Map<number, AuditTransaction>, mempool: Map<number, AuditTransaction>,
modified: PairingHeap<AuditTransaction>, modified: PairingHeap<AuditTransaction>,
clusterRate: number,
): void { ): void {
const descendantSet: Set<AuditTransaction> = new Set(); const descendantSet: Set<AuditTransaction> = new Set();
// stack of nodes left to visit // stack of nodes left to visit
@ -272,6 +273,7 @@ function updateDescendants(
descendantTx.ancestorWeight -= rootTx.weight; descendantTx.ancestorWeight -= rootTx.weight;
tmpScore = descendantTx.score; tmpScore = descendantTx.score;
descendantTx.score = descendantTx.ancestorFee / (descendantTx.ancestorWeight / 4); descendantTx.score = descendantTx.ancestorFee / (descendantTx.ancestorWeight / 4);
descendantTx.dependencyRate = descendantTx.dependencyRate ? Math.min(descendantTx.dependencyRate, clusterRate) : clusterRate;
if (!descendantTx.modifiedNode) { if (!descendantTx.modifiedNode) {
descendantTx.modified = true; descendantTx.modified = true;

View file

@ -104,6 +104,7 @@ export interface AuditTransaction {
used: boolean; used: boolean;
modified: boolean; modified: boolean;
modifiedNode: HeapNode<AuditTransaction>; modifiedNode: HeapNode<AuditTransaction>;
dependencyRate?: number;
} }
export interface CompactThreadTransaction { export interface CompactThreadTransaction {

View file

@ -481,7 +481,7 @@
</ng-template> </ng-template>
</td> </td>
</tr> </tr>
<tr *ngIf="cpfpInfo && (cpfpInfo?.bestDescendant || cpfpInfo?.descendants?.length || cpfpInfo?.ancestors?.length)"> <tr *ngIf="cpfpInfo && (cpfpInfo.effectiveFeePerVsize || cpfpInfo.bestDescendant || cpfpInfo.descendants?.length || cpfpInfo.ancestors?.length)">
<td i18n="transaction.effective-fee-rate|Effective transaction fee rate">Effective fee rate</td> <td i18n="transaction.effective-fee-rate|Effective transaction fee rate">Effective fee rate</td>
<td> <td>
<div class="effective-fee-container"> <div class="effective-fee-container">
@ -490,7 +490,7 @@
<app-tx-fee-rating class="ml-2 mr-2" *ngIf="tx.fee || tx.effectiveFeePerVsize" [tx]="tx"></app-tx-fee-rating> <app-tx-fee-rating class="ml-2 mr-2" *ngIf="tx.fee || tx.effectiveFeePerVsize" [tx]="tx"></app-tx-fee-rating>
</ng-template> </ng-template>
</div> </div>
<button type="button" class="btn btn-outline-info btn-sm btn-small-height float-right" (click)="showCpfpDetails = !showCpfpDetails">CPFP <fa-icon [icon]="['fas', 'info-circle']" [fixedWidth]="true"></fa-icon></button> <button *ngIf="cpfpInfo.bestDescendant || cpfpInfo.descendants?.length || cpfpInfo.ancestors?.length" type="button" class="btn btn-outline-info btn-sm btn-small-height float-right" (click)="showCpfpDetails = !showCpfpDetails">CPFP <fa-icon [icon]="['fas', 'info-circle']" [fixedWidth]="true"></fa-icon></button>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -164,14 +164,17 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
if (cpfpInfo.bestDescendant && !cpfpInfo.descendants?.length) { if (cpfpInfo.bestDescendant && !cpfpInfo.descendants?.length) {
relatives.push(cpfpInfo.bestDescendant); relatives.push(cpfpInfo.bestDescendant);
} }
let totalWeight = if (!cpfpInfo.effectiveFeePerVsize) {
this.tx.weight + let totalWeight =
relatives.reduce((prev, val) => prev + val.weight, 0); this.tx.weight +
let totalFees = relatives.reduce((prev, val) => prev + val.weight, 0);
this.tx.fee + let totalFees =
relatives.reduce((prev, val) => prev + val.fee, 0); this.tx.fee +
relatives.reduce((prev, val) => prev + val.fee, 0);
this.tx.effectiveFeePerVsize = totalFees / (totalWeight / 4); this.tx.effectiveFeePerVsize = totalFees / (totalWeight / 4);
} else {
this.tx.effectiveFeePerVsize = cpfpInfo.effectiveFeePerVsize;
}
this.cpfpInfo = cpfpInfo; this.cpfpInfo = cpfpInfo;
}); });

View file

@ -24,6 +24,7 @@ export interface CpfpInfo {
ancestors: Ancestor[]; ancestors: Ancestor[];
descendants?: Ancestor[]; descendants?: Ancestor[];
bestDescendant?: BestDescendant | null; bestDescendant?: BestDescendant | null;
effectiveFeePerVsize?: number;
} }
export interface RbfInfo { export interface RbfInfo {