From a4cd6450e3829cc57ab039b1cac53fd3886ece27 Mon Sep 17 00:00:00 2001 From: softsimon Date: Fri, 21 May 2021 17:06:53 +0400 Subject: [PATCH] Fix for race condition causing cpfp fetching not working. (#533) fixes #505 --- .../transaction/transaction.component.ts | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 65a8acc86..74d181a50 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -47,6 +47,32 @@ export class TransactionComponent implements OnInit, OnDestroy { this.websocketService.want(['blocks', 'mempool-blocks']); this.stateService.networkChanged$.subscribe((network) => this.network = network); + this.fetchCpfpSubscription = this.fetchCpfp$ + .pipe( + switchMap((txId) => this.apiService.getCpfpinfo$(txId) + .pipe( + retryWhen((errors) => errors.pipe(delay(2000))) + ) + ), + ) + .subscribe((cpfpInfo) => { + if (!this.tx) { + return; + } + 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); + this.stateService.markBlock$.next({ txFeePerVSize: this.tx.effectiveFeePerVsize }); + this.cpfpInfo = cpfpInfo; + }); + this.subscription = this.route.paramMap.pipe( switchMap((params: ParamMap) => { this.txId = params.get('id') || ''; @@ -117,32 +143,6 @@ export class TransactionComponent implements OnInit, OnDestroy { this.isLoadingTx = false; }); - this.fetchCpfpSubscription = this.fetchCpfp$ - .pipe( - switchMap((txId) => this.apiService.getCpfpinfo$(txId) - .pipe( - retryWhen((errors) => errors.pipe(delay(2000))) - ) - ), - ) - .subscribe((cpfpInfo) => { - if (!this.tx) { - return; - } - 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); - this.stateService.markBlock$.next({ txFeePerVSize: this.tx.effectiveFeePerVsize }); - this.cpfpInfo = cpfpInfo; - }); - this.stateService.blocks$ .subscribe(([block, txConfirmed]) => { this.latestBlock = block;