mirror of
https://github.com/mempool/mempool.git
synced 2025-03-13 11:36:07 +01:00
Limit GBT: handle accelerations beneath the purge rate
This commit is contained in:
parent
5411eb491f
commit
07c76d084e
2 changed files with 18 additions and 6 deletions
|
@ -18,6 +18,7 @@ class MempoolBlocks {
|
||||||
|
|
||||||
private nextUid: number = 1;
|
private nextUid: number = 1;
|
||||||
private uidMap: Map<number, string> = new Map(); // map short numerical uids to full txids
|
private uidMap: Map<number, string> = new Map(); // map short numerical uids to full txids
|
||||||
|
private txidMap: Map<string, number> = new Map(); // map full txids back to short numerical uids
|
||||||
|
|
||||||
public getMempoolBlocks(): MempoolBlock[] {
|
public getMempoolBlocks(): MempoolBlock[] {
|
||||||
return this.mempoolBlocks.map((block) => {
|
return this.mempoolBlocks.map((block) => {
|
||||||
|
@ -503,33 +504,38 @@ class MempoolBlocks {
|
||||||
|
|
||||||
private resetUids(): void {
|
private resetUids(): void {
|
||||||
this.uidMap.clear();
|
this.uidMap.clear();
|
||||||
|
this.txidMap.clear();
|
||||||
this.nextUid = 1;
|
this.nextUid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private setUid(tx: MempoolTransactionExtended, skipSet = false): number {
|
private setUid(tx: MempoolTransactionExtended, skipSet = false): number {
|
||||||
if (tx.uid === null || tx.uid === undefined || !skipSet) {
|
if (!this.txidMap.has(tx.txid) || !skipSet) {
|
||||||
const uid = this.nextUid;
|
const uid = this.nextUid;
|
||||||
this.nextUid++;
|
this.nextUid++;
|
||||||
this.uidMap.set(uid, tx.txid);
|
this.uidMap.set(uid, tx.txid);
|
||||||
|
this.txidMap.set(tx.txid, uid);
|
||||||
tx.uid = uid;
|
tx.uid = uid;
|
||||||
return uid;
|
return uid;
|
||||||
} else {
|
} else {
|
||||||
|
tx.uid = this.txidMap.get(tx.txid) as number;
|
||||||
return tx.uid;
|
return tx.uid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getUid(tx: MempoolTransactionExtended): number | void {
|
private getUid(tx: MempoolTransactionExtended): number | void {
|
||||||
if (tx?.uid !== null && tx?.uid !== undefined && this.uidMap.has(tx.uid)) {
|
if (tx) {
|
||||||
return tx.uid;
|
return this.txidMap.get(tx.txid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeUids(txs: MempoolTransactionExtended[]): void {
|
private removeUids(txs: MempoolTransactionExtended[]): void {
|
||||||
for (const tx of txs) {
|
for (const tx of txs) {
|
||||||
if (tx.uid != null) {
|
const uid = this.txidMap.get(tx.txid);
|
||||||
this.uidMap.delete(tx.uid);
|
if (uid != null) {
|
||||||
tx.uid = undefined;
|
this.uidMap.delete(uid);
|
||||||
|
this.txidMap.delete(tx.txid);
|
||||||
}
|
}
|
||||||
|
tx.uid = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -457,6 +457,12 @@ class Mempool {
|
||||||
newCandidateTxMap[txid] = true;
|
newCandidateTxMap[txid] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const accelerations = this.getAccelerations();
|
||||||
|
for (const txid of Object.keys(accelerations)) {
|
||||||
|
if (this.mempoolCache[txid]) {
|
||||||
|
newCandidateTxMap[txid] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
const removed: MempoolTransactionExtended[] = [];
|
const removed: MempoolTransactionExtended[] = [];
|
||||||
const added: MempoolTransactionExtended[] = [];
|
const added: MempoolTransactionExtended[] = [];
|
||||||
// don't prematurely remove txs included in a new block
|
// don't prematurely remove txs included in a new block
|
||||||
|
|
Loading…
Add table
Reference in a new issue