Skip to content

Commit ee0f9d0

Browse files
committed
Review changes
1 parent 6d3ff9f commit ee0f9d0

File tree

8 files changed

+520
-202
lines changed

8 files changed

+520
-202
lines changed

yarn-project/p2p/src/mem_pools/tx_pool/eviction/archive_filter.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

yarn-project/p2p/src/mem_pools/tx_pool/eviction/eviction_manager.ts

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import {
1313
type PreAddEvictionResult,
1414
type PreAddEvictionRule,
1515
type PreAddPoolAccess,
16-
type PrePendingFilter,
17-
type PrePendingFilterContext,
18-
type PrePendingFilterResult,
1916
type TxPoolOperations,
20-
type TxValidationFields,
2117
} from './eviction_strategy.js';
2218

2319
export class EvictionManager {
@@ -26,9 +22,6 @@ export class EvictionManager {
2622
/** Pre-add eviction rules (run inside addTxs transaction) */
2723
private preAddRules: PreAddEvictionRule[] = [];
2824

29-
/** Pre-pending filters (run before restoring txs to pending after reorg/unprotect) */
30-
private prePendingFilters: PrePendingFilter[] = [];
31-
3225
constructor(
3326
private txPool: TxPoolOperations,
3427
private log = createLogger('p2p:mempool:tx_pool:eviction_manager'),
@@ -114,68 +107,6 @@ export class EvictionManager {
114107
this.preAddRules.push(rule);
115108
}
116109

117-
public registerPrePendingFilter(filter: PrePendingFilter) {
118-
this.prePendingFilters.push(filter);
119-
}
120-
121-
/**
122-
* Filters transactions before they are restored to pending state.
123-
* Used during reorgs (un-mining) and slot transitions (unprotecting) to avoid
124-
* adding transactions to pending indices only to immediately remove them.
125-
*
126-
* @param txs - Transaction metadata to validate
127-
* @param ctx - Context about why we're filtering
128-
* @returns Result with valid and invalid tx hashes
129-
*/
130-
public async filterValidForPending(
131-
txs: TxValidationFields[],
132-
ctx: PrePendingFilterContext,
133-
): Promise<PrePendingFilterResult> {
134-
if (txs.length === 0) {
135-
return { valid: [], invalid: [] };
136-
}
137-
138-
// Collect all invalid tx hashes from all filters
139-
const allInvalid = new Set<string>();
140-
141-
for (const filter of this.prePendingFilters) {
142-
try {
143-
const invalidFromFilter = await filter.filterInvalid(txs, ctx);
144-
for (const txHash of invalidFromFilter) {
145-
allInvalid.add(txHash);
146-
}
147-
} catch (err) {
148-
this.log.warn(`Pre-pending filter ${filter.name} unexpected error: ${String(err)}`, {
149-
err,
150-
filterName: filter.name,
151-
event: ctx.event,
152-
});
153-
// On error, don't filter out any txs - let them go to pending and be evicted later if needed
154-
}
155-
}
156-
157-
// Partition into valid and invalid
158-
const valid: string[] = [];
159-
const invalid: string[] = [];
160-
for (const tx of txs) {
161-
if (allInvalid.has(tx.txHash)) {
162-
invalid.push(tx.txHash);
163-
} else {
164-
valid.push(tx.txHash);
165-
}
166-
}
167-
168-
if (invalid.length > 0) {
169-
this.log.verbose(`Pre-pending filter: ${invalid.length} invalid, ${valid.length} valid`, {
170-
event: ctx.event,
171-
invalidCount: invalid.length,
172-
validCount: valid.length,
173-
});
174-
}
175-
176-
return { valid, invalid };
177-
}
178-
179110
public updateConfig(config: TxPoolOptions): void {
180111
for (const rule of this.rules) {
181112
rule.updateConfig(config);

yarn-project/p2p/src/mem_pools/tx_pool/eviction/eviction_strategy.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -148,62 +148,6 @@ export class FeePayerTxInfo {
148148
}
149149
}
150150

151-
/**
152-
* Metadata about a transaction for pre-pending validation.
153-
* Contains the essential fields needed to validate without loading the full Tx.
154-
*/
155-
export interface TxValidationFields {
156-
/** Transaction hash as string */
157-
txHash: string;
158-
/** Hash of the anchor block header */
159-
anchorBlockHeaderHash: string;
160-
/** Fee payer address as string */
161-
feePayer: string;
162-
/** Maximum fee the tx is willing to pay */
163-
feeLimit: bigint;
164-
}
165-
166-
/**
167-
* Context for pre-pending filter operations.
168-
*/
169-
export type PrePendingFilterContext =
170-
| {
171-
event: 'CHAIN_PRUNED';
172-
/** The latest valid block number after the prune */
173-
blockNumber: BlockNumber;
174-
}
175-
| {
176-
event: 'UNPROTECT';
177-
};
178-
179-
/**
180-
* Result of a pre-pending filter operation.
181-
*/
182-
export interface PrePendingFilterResult {
183-
/** Transaction hashes that are valid and can be added to pending */
184-
valid: string[];
185-
/** Transaction hashes that are invalid and should be deleted */
186-
invalid: string[];
187-
}
188-
189-
/**
190-
* Strategy interface for filtering transactions before they enter the pending pool.
191-
* Used during reorgs (un-mining) and slot transitions (unprotecting) to avoid
192-
* adding transactions to pending indices only to immediately remove them.
193-
*/
194-
export interface PrePendingFilter {
195-
readonly name: string;
196-
197-
/**
198-
* Filters transactions, returning which are invalid and should not be added to pending.
199-
*
200-
* @param txs - Transaction metadata to validate
201-
* @param ctx - Context about why we're filtering (reorg vs unprotect)
202-
* @returns Set of tx hashes that are INVALID (should not be added to pending)
203-
*/
204-
filterInvalid(txs: TxValidationFields[], ctx: PrePendingFilterContext): Promise<Set<string>>;
205-
}
206-
207151
/**
208152
* Read-only access to pool state for pre-add eviction checks.
209153
* Passed to pre-add rules during the addTxs transaction.

0 commit comments

Comments
 (0)