From c7d61a3be41d236f7cef4fcb458d0668ba90f184 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 1 Dec 2022 11:34:11 +0900 Subject: [PATCH 1/2] only retry fetch CPFP for unconfirmed txs --- .../transaction/transaction.component.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 3e04b0ad9..575c00637 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -7,10 +7,11 @@ import { catchError, retryWhen, delay, - map + map, + mergeMap } from 'rxjs/operators'; import { Transaction } from '../../interfaces/electrs.interface'; -import { of, merge, Subscription, Observable, Subject, timer, combineLatest, from } from 'rxjs'; +import { of, merge, Subscription, Observable, Subject, timer, combineLatest, from, throwError } from 'rxjs'; import { StateService } from '../../services/state.service'; import { WebsocketService } from '../../services/websocket.service'; import { AudioService } from '../../services/audio.service'; @@ -110,11 +111,24 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { switchMap((txId) => this.apiService .getCpfpinfo$(txId) - .pipe(retryWhen((errors) => errors.pipe(delay(2000)))) - ) + .pipe(retryWhen((errors) => errors.pipe( + mergeMap((error) => { + if (!this.tx?.status || this.tx.status.confirmed) { + return throwError(error); + } else { + return of(null); + } + }), + delay(2000) + ))) + ), + catchError(() => { + return of(null); + }) ) .subscribe((cpfpInfo) => { - if (!this.tx) { + if (!cpfpInfo || !this.tx) { + this.cpfpInfo = null; return; } if (cpfpInfo.effectiveFeePerVsize) { From 38c890626be82090569a9455777c9d41dae03e59 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 1 Dec 2022 11:34:44 +0900 Subject: [PATCH 2/2] fix CPFP handling in transaction preview --- .../transaction-preview.component.ts | 36 +++---------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/frontend/src/app/components/transaction/transaction-preview.component.ts b/frontend/src/app/components/transaction/transaction-preview.component.ts index bd4260244..9d2d502b4 100644 --- a/frontend/src/app/components/transaction/transaction-preview.component.ts +++ b/frontend/src/app/components/transaction/transaction-preview.component.ts @@ -63,40 +63,14 @@ export class TransactionPreviewComponent implements OnInit, OnDestroy { this.fetchCpfpSubscription = this.fetchCpfp$ .pipe( switchMap((txId) => - this.apiService - .getCpfpinfo$(txId) - .pipe(retryWhen((errors) => errors.pipe(delay(2000)))) + this.apiService.getCpfpinfo$(txId).pipe( + catchError((err) => { + return of(null); + }) + ) ) ) .subscribe((cpfpInfo) => { - if (!this.tx) { - return; - } - if (cpfpInfo.effectiveFeePerVsize) { - this.tx.effectiveFeePerVsize = cpfpInfo.effectiveFeePerVsize; - } else { - const lowerFeeParents = cpfpInfo.ancestors.filter( - (parent) => parent.fee / (parent.weight / 4) < this.tx.feePerVsize - ); - let totalWeight = - this.tx.weight + - lowerFeeParents.reduce((prev, val) => prev + val.weight, 0); - let totalFees = - this.tx.fee + - lowerFeeParents.reduce((prev, val) => prev + val.fee, 0); - - if (cpfpInfo?.bestDescendant) { - totalWeight += cpfpInfo?.bestDescendant.weight; - totalFees += cpfpInfo?.bestDescendant.fee; - } - - this.tx.effectiveFeePerVsize = totalFees / (totalWeight / 4); - } - if (!this.tx.status.confirmed) { - this.stateService.markBlock$.next({ - txFeePerVSize: this.tx.effectiveFeePerVsize, - }); - } this.cpfpInfo = cpfpInfo; this.openGraphService.waitOver('cpfp-data-' + this.txId); });