mirror of
https://github.com/mempool/mempool.git
synced 2025-03-12 19:04: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 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[] {
|
||||
return this.mempoolBlocks.map((block) => {
|
||||
|
@ -503,33 +504,38 @@ class MempoolBlocks {
|
|||
|
||||
private resetUids(): void {
|
||||
this.uidMap.clear();
|
||||
this.txidMap.clear();
|
||||
this.nextUid = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
this.nextUid++;
|
||||
this.uidMap.set(uid, tx.txid);
|
||||
this.txidMap.set(tx.txid, uid);
|
||||
tx.uid = uid;
|
||||
return uid;
|
||||
} else {
|
||||
tx.uid = this.txidMap.get(tx.txid) as number;
|
||||
return tx.uid;
|
||||
}
|
||||
}
|
||||
|
||||
private getUid(tx: MempoolTransactionExtended): number | void {
|
||||
if (tx?.uid !== null && tx?.uid !== undefined && this.uidMap.has(tx.uid)) {
|
||||
return tx.uid;
|
||||
if (tx) {
|
||||
return this.txidMap.get(tx.txid);
|
||||
}
|
||||
}
|
||||
|
||||
private removeUids(txs: MempoolTransactionExtended[]): void {
|
||||
for (const tx of txs) {
|
||||
if (tx.uid != null) {
|
||||
this.uidMap.delete(tx.uid);
|
||||
tx.uid = undefined;
|
||||
const uid = this.txidMap.get(tx.txid);
|
||||
if (uid != null) {
|
||||
this.uidMap.delete(uid);
|
||||
this.txidMap.delete(tx.txid);
|
||||
}
|
||||
tx.uid = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -457,6 +457,12 @@ class Mempool {
|
|||
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 added: MempoolTransactionExtended[] = [];
|
||||
// don't prematurely remove txs included in a new block
|
||||
|
|
Loading…
Add table
Reference in a new issue