clearer uint32 uid overflow check

This commit is contained in:
Mononaut 2023-06-25 23:42:33 -04:00
parent 5d48ae1eec
commit 4a15cd7abe
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E

View File

@ -6,6 +6,8 @@ import config from '../config';
import { Worker } from 'worker_threads'; import { Worker } from 'worker_threads';
import path from 'path'; import path from 'path';
const MAX_UINT32 = Math.pow(2, 32) - 1;
class MempoolBlocks { class MempoolBlocks {
private mempoolBlocks: MempoolBlockWithTransactions[] = []; private mempoolBlocks: MempoolBlockWithTransactions[] = [];
private mempoolBlockDeltas: MempoolBlockDelta[] = []; private mempoolBlockDeltas: MempoolBlockDelta[] = [];
@ -375,7 +377,7 @@ class MempoolBlocks {
public async $rustUpdateBlockTemplates(newMempool: { [txid: string]: MempoolTransactionExtended }, added: MempoolTransactionExtended[], removed: MempoolTransactionExtended[]): Promise<void> { public async $rustUpdateBlockTemplates(newMempool: { [txid: string]: MempoolTransactionExtended }, added: MempoolTransactionExtended[], removed: MempoolTransactionExtended[]): Promise<void> {
// sanity check to avoid approaching uint32 uid overflow // sanity check to avoid approaching uint32 uid overflow
if (this.nextUid > 4_000_000_000) { if (this.nextUid + added.length > MAX_UINT32) {
this.resetRustGbt(); this.resetRustGbt();
} }
if (!this.rustInitialized) { if (!this.rustInitialized) {