From 3f49944c05f898a91721823f9ffaf3fd8f5ae582 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 3 May 2023 10:02:03 -0600 Subject: [PATCH 1/3] Fix transaction ETA calculation --- .../src/app/components/transaction/transaction.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 5f23633bf..4c2dbccb0 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -416,13 +416,15 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { const txFeePerVSize = this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4); + let found = false; for (const block of mempoolBlocks) { - for (let i = 0; i < block.feeRange.length - 1; i++) { + for (let i = 0; i < block.feeRange.length - 1 && !found; i++) { if ( txFeePerVSize <= block.feeRange[i + 1] && txFeePerVSize >= block.feeRange[i] ) { this.txInBlockIndex = mempoolBlocks.indexOf(block); + found = true; } } } From e3f1fced9995d5c76aa3a5d9f6adb3ff2fafe6ae Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 3 May 2023 13:55:26 -0600 Subject: [PATCH 2/3] keep ETA relative time basis updated --- .../src/app/components/transaction/transaction.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 4c2dbccb0..3fe194cb5 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -59,7 +59,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { fetchRbfHistory$ = new Subject(); fetchCachedTx$ = new Subject(); isCached: boolean = false; - now = new Date().getTime(); + now = Date.now(); timeAvg$: Observable; liquidUnblinding = new LiquidUnblinding(); inputIndex: number; @@ -413,6 +413,8 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { return; } + this.now = Date.now(); + const txFeePerVSize = this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4); From 9bd968f6c316ed9db256599a0f8f3de7e491463a Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 3 May 2023 13:58:08 -0600 Subject: [PATCH 3/3] fix tx page mempool blocks subscription leak --- .../transaction/transaction.component.ts | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 3fe194cb5..a5ae52d60 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -49,6 +49,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { blocksSubscription: Subscription; queryParamsSubscription: Subscription; urlFragmentSubscription: Subscription; + mempoolBlocksSubscription: Subscription; fragmentParams: URLSearchParams; rbfTransaction: undefined | Transaction; replaced: boolean = false; @@ -308,7 +309,6 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { this.isLoadingTx = false; this.error = undefined; this.waitingForTransaction = false; - this.setMempoolBlocksSubscription(); this.websocketService.startTrackTransaction(tx.txid); this.graphExpanded = false; this.setupGraph(); @@ -391,6 +391,34 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { this.setFlowEnabled(); this.setGraphSize(); }); + + this.mempoolBlocksSubscription = this.stateService.mempoolBlocks$.subscribe((mempoolBlocks) => { + if (!this.tx) { + return; + } + + this.now = Date.now(); + + const txFeePerVSize = + this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4); + + let found = false; + this.txInBlockIndex = 0; + for (const block of mempoolBlocks) { + for (let i = 0; i < block.feeRange.length - 1 && !found; i++) { + if ( + txFeePerVSize <= block.feeRange[i + 1] && + txFeePerVSize >= block.feeRange[i] + ) { + this.txInBlockIndex = mempoolBlocks.indexOf(block); + found = true; + } + } + } + if (!found && txFeePerVSize < mempoolBlocks[mempoolBlocks.length - 1].feeRange[0]) { + this.txInBlockIndex = 7; + } + }); } ngAfterViewInit(): void { @@ -407,32 +435,6 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { return of(false); } - setMempoolBlocksSubscription() { - this.stateService.mempoolBlocks$.subscribe((mempoolBlocks) => { - if (!this.tx) { - return; - } - - this.now = Date.now(); - - const txFeePerVSize = - this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4); - - let found = false; - for (const block of mempoolBlocks) { - for (let i = 0; i < block.feeRange.length - 1 && !found; i++) { - if ( - txFeePerVSize <= block.feeRange[i + 1] && - txFeePerVSize >= block.feeRange[i] - ) { - this.txInBlockIndex = mempoolBlocks.indexOf(block); - found = true; - } - } - } - }); - } - getTransactionTime() { this.apiService .getTransactionTimes$([this.tx.txid]) @@ -540,6 +542,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { this.queryParamsSubscription.unsubscribe(); this.flowPrefSubscription.unsubscribe(); this.urlFragmentSubscription.unsubscribe(); + this.mempoolBlocksSubscription.unsubscribe(); this.leaveTransaction(); } }