don't reset blockchain position on every mempool update

This commit is contained in:
Mononaut 2023-06-19 15:19:34 -04:00
parent 9d606d0006
commit 58b8052530
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
3 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import { Component, ElementRef, HostListener, OnInit, OnDestroy, ViewChild, Input } from '@angular/core'; import { Component, ElementRef, HostListener, OnInit, OnDestroy, ViewChild, Input } from '@angular/core';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { StateService } from '../../services/state.service'; import { MarkBlockState, StateService } from '../../services/state.service';
import { specialBlocks } from '../../app.constants'; import { specialBlocks } from '../../app.constants';
@Component({ @Component({
@ -24,6 +24,7 @@ export class StartComponent implements OnInit, OnDestroy {
chainTipSubscription: Subscription; chainTipSubscription: Subscription;
chainTip: number = -1; chainTip: number = -1;
tipIsSet: boolean = false; tipIsSet: boolean = false;
lastMark: MarkBlockState;
markBlockSubscription: Subscription; markBlockSubscription: Subscription;
blockCounterSubscription: Subscription; blockCounterSubscription: Subscription;
@ViewChild('blockchainContainer') blockchainContainer: ElementRef; @ViewChild('blockchainContainer') blockchainContainer: ElementRef;
@ -75,20 +76,31 @@ export class StartComponent implements OnInit, OnDestroy {
}); });
this.markBlockSubscription = this.stateService.markBlock$.subscribe((mark) => { this.markBlockSubscription = this.stateService.markBlock$.subscribe((mark) => {
let blockHeight; let blockHeight;
let newMark = true;
if (mark?.blockHeight != null) { if (mark?.blockHeight != null) {
if (this.lastMark?.blockHeight === mark.blockHeight) {
newMark = false;
}
blockHeight = mark.blockHeight; blockHeight = mark.blockHeight;
} else if (mark?.mempoolBlockIndex != null) { } else if (mark?.mempoolBlockIndex != null) {
if (this.lastMark?.mempoolBlockIndex === mark.mempoolBlockIndex || (mark.txid && this.lastMark?.txid === mark.txid)) {
newMark = false;
}
blockHeight = -1 - mark.mempoolBlockIndex; blockHeight = -1 - mark.mempoolBlockIndex;
} else if (mark?.mempoolPosition?.block != null) { } else if (mark?.mempoolPosition?.block != null) {
if (this.lastMark?.txid === mark.txid) {
newMark = false;
}
blockHeight = -1 - mark.mempoolPosition.block; blockHeight = -1 - mark.mempoolPosition.block;
} }
this.lastMark = mark;
if (blockHeight != null) { if (blockHeight != null) {
if (this.tipIsSet) { if (this.tipIsSet) {
let scrollToHeight = blockHeight; let scrollToHeight = blockHeight;
if (blockHeight < 0) { if (blockHeight < 0) {
scrollToHeight = this.chainTip - blockHeight; scrollToHeight = this.chainTip - blockHeight;
} }
if (!this.blockInViewport(scrollToHeight)) { if (newMark && !this.blockInViewport(scrollToHeight)) {
this.scrollToBlock(scrollToHeight); this.scrollToBlock(scrollToHeight);
} }
} }

View File

@ -240,6 +240,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
this.mempoolPosition = txPosition.position; this.mempoolPosition = txPosition.position;
if (this.tx && !this.tx.status.confirmed) { if (this.tx && !this.tx.status.confirmed) {
this.stateService.markBlock$.next({ this.stateService.markBlock$.next({
txid: txPosition.txid,
mempoolPosition: this.mempoolPosition mempoolPosition: this.mempoolPosition
}); });
this.txInBlockIndex = this.mempoolPosition.block; this.txInBlockIndex = this.mempoolPosition.block;
@ -359,6 +360,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
} else { } else {
if (tx.cpfpChecked) { if (tx.cpfpChecked) {
this.stateService.markBlock$.next({ this.stateService.markBlock$.next({
txid: tx.txid,
txFeePerVSize: tx.effectiveFeePerVsize, txFeePerVSize: tx.effectiveFeePerVsize,
mempoolPosition: this.mempoolPosition, mempoolPosition: this.mempoolPosition,
}); });

View File

@ -8,8 +8,9 @@ import { isPlatformBrowser } from '@angular/common';
import { map, shareReplay } from 'rxjs/operators'; import { map, shareReplay } from 'rxjs/operators';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
interface MarkBlockState { export interface MarkBlockState {
blockHeight?: number; blockHeight?: number;
txid?: string;
mempoolBlockIndex?: number; mempoolBlockIndex?: number;
txFeePerVSize?: number; txFeePerVSize?: number;
mempoolPosition?: MempoolPosition; mempoolPosition?: MempoolPosition;