bound stale block total weight for sanity

This commit is contained in:
Mononaut 2025-10-13 09:04:43 +00:00
parent f6d0fd01c0
commit 87c94020fc
No known key found for this signature in database
GPG key ID: A3F058E41374C04E

View file

@ -22,6 +22,7 @@ import { identifyPrioritizedTransactions } from '@app/shared/transaction.utils';
interface ComparisonStats {
totalFees: number;
totalWeight: number;
totalVsize: number;
txCount: number;
feeDelta: number;
weightDelta: number;
@ -622,6 +623,7 @@ export class BlockComponent implements OnInit, OnDestroy {
this.staleStats = {
totalFees: 0,
totalWeight: 0,
totalVsize: 0,
txCount: 0,
feeDelta: 0,
weightDelta: 0,
@ -630,6 +632,7 @@ export class BlockComponent implements OnInit, OnDestroy {
this.canonicalStats = {
totalFees: 0,
totalWeight: 0,
totalVsize: 0,
txCount: 0,
feeDelta: 0,
weightDelta: 0,
@ -645,12 +648,14 @@ export class BlockComponent implements OnInit, OnDestroy {
inStale[tx.txid] = tx;
this.staleStats.totalFees += tx.fee;
this.staleStats.totalWeight += tx.vsize * 4;
this.staleStats.totalVsize += tx.vsize;
this.staleStats.txCount++;
}
for (const tx of canonicalTransactions) {
inCanonical[tx.txid] = tx;
this.canonicalStats.totalFees += tx.fee;
this.canonicalStats.totalWeight += tx.vsize * 4;
this.canonicalStats.totalVsize += tx.vsize;
this.canonicalStats.txCount++;
}
@ -680,6 +685,10 @@ export class BlockComponent implements OnInit, OnDestroy {
}
}
// if vsize was rounded, the total weight we calculated isn't exact and can exceed the 4MB limit
this.staleStats.totalWeight = Math.min(this.staleStats.totalWeight, 4_000_000);
this.canonicalStats.totalWeight = Math.min(this.canonicalStats.totalWeight, 4_000_000);
this.staleStats.feeDelta = this.staleStats.totalFees > 0 ? (this.staleStats.totalFees - this.canonicalStats.totalFees) / this.staleStats.totalFees : 0;
this.staleStats.weightDelta = this.staleStats.totalWeight > 0 ? (this.staleStats.totalWeight - this.canonicalStats.totalWeight) / this.staleStats.totalWeight : 0;
this.staleStats.txDelta = this.staleStats.txCount > 0 ? (this.staleStats.txCount - this.canonicalStats.txCount) / this.staleStats.txCount : 0;