@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.86469d5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +1 -3
- package/dest/client/p2p_client.d.ts +2 -4
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +2 -6
- package/dest/config.d.ts +3 -9
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -3
- package/dest/services/index.d.ts +1 -2
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +0 -1
- package/dest/services/libp2p/libp2p_service.d.ts +4 -4
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +8 -4
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -4
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +8 -8
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +5 -6
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +11 -16
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +10 -15
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +11 -12
- package/dest/services/tx_collection/config.d.ts +3 -3
- package/dest/services/tx_collection/config.js +3 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts +5 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +14 -10
- package/dest/services/tx_collection/index.d.ts +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +12 -12
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/package.json +14 -14
- package/src/client/factory.ts +0 -4
- package/src/client/p2p_client.ts +0 -5
- package/src/config.ts +1 -8
- package/src/services/index.ts +0 -1
- package/src/services/libp2p/libp2p_service.ts +8 -12
- package/src/services/reqresp/batch-tx-requester/README.md +7 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +11 -11
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +14 -22
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +15 -21
- package/src/services/tx_collection/config.ts +6 -6
- package/src/services/tx_collection/fast_tx_collection.ts +24 -14
- package/src/services/tx_collection/index.ts +1 -1
- package/src/services/tx_collection/proposal_tx_collector.ts +14 -12
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +0 -2
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/archive/index.js +0 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +0 -43
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +0 -103
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +0 -47
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +0 -119
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +0 -90
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +0 -89
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +0 -10
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +0 -11
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +0 -131
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +0 -17
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +0 -63
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +0 -91
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +0 -70
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +0 -20
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +0 -63
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +0 -19
- package/dest/mem_pools/tx_pool_v2/index.d.ts +0 -5
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/index.js +0 -4
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +0 -197
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +0 -6
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +0 -71
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +0 -95
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +0 -26
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +0 -70
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +0 -99
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +0 -332
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +0 -55
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +0 -156
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +0 -69
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +0 -748
- package/dest/services/tx_file_store/config.d.ts +0 -18
- package/dest/services/tx_file_store/config.d.ts.map +0 -1
- package/dest/services/tx_file_store/config.js +0 -26
- package/dest/services/tx_file_store/index.d.ts +0 -4
- package/dest/services/tx_file_store/index.d.ts.map +0 -1
- package/dest/services/tx_file_store/index.js +0 -3
- package/dest/services/tx_file_store/instrumentation.d.ts +0 -15
- package/dest/services/tx_file_store/instrumentation.d.ts.map +0 -1
- package/dest/services/tx_file_store/instrumentation.js +0 -29
- package/dest/services/tx_file_store/tx_file_store.d.ts +0 -47
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +0 -1
- package/dest/services/tx_file_store/tx_file_store.js +0 -149
- package/src/mem_pools/tx_pool_v2/README.md +0 -209
- package/src/mem_pools/tx_pool_v2/archive/index.ts +0 -1
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +0 -120
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +0 -147
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +0 -118
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +0 -111
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +0 -23
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +0 -164
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +0 -74
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +0 -101
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +0 -86
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +0 -72
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +0 -31
- package/src/mem_pools/tx_pool_v2/index.ts +0 -11
- package/src/mem_pools/tx_pool_v2/interfaces.ts +0 -227
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +0 -161
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +0 -77
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +0 -417
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +0 -212
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +0 -882
- package/src/services/tx_file_store/config.ts +0 -43
- package/src/services/tx_file_store/index.ts +0 -3
- package/src/services/tx_file_store/instrumentation.ts +0 -36
- package/src/services/tx_file_store/tx_file_store.ts +0 -173
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
4
|
-
|
|
5
|
-
import type { TxMetaData } from '../tx_metadata.js';
|
|
6
|
-
import {
|
|
7
|
-
type EvictionConfig,
|
|
8
|
-
type EvictionContext,
|
|
9
|
-
EvictionEvent,
|
|
10
|
-
type EvictionRule,
|
|
11
|
-
type PoolOperations,
|
|
12
|
-
type PreAddPoolAccess,
|
|
13
|
-
type PreAddResult,
|
|
14
|
-
type PreAddRule,
|
|
15
|
-
} from './interfaces.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Manages eviction rules for the transaction pool.
|
|
19
|
-
* Coordinates pre-add rules (run during addPendingTxs) and post-event rules (run after events).
|
|
20
|
-
*/
|
|
21
|
-
export class EvictionManager {
|
|
22
|
-
private preAddRules: PreAddRule[] = [];
|
|
23
|
-
private postEventRules: EvictionRule[] = [];
|
|
24
|
-
|
|
25
|
-
constructor(
|
|
26
|
-
private pool: PoolOperations,
|
|
27
|
-
private log: Logger,
|
|
28
|
-
) {}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Registers a pre-add rule that runs during transaction addition.
|
|
32
|
-
*/
|
|
33
|
-
registerPreAddRule(rule: PreAddRule): void {
|
|
34
|
-
this.preAddRules.push(rule);
|
|
35
|
-
this.log.debug(`Registered pre-add rule: ${rule.name}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Registers a post-event eviction rule that runs after events.
|
|
40
|
-
*/
|
|
41
|
-
registerRule(rule: EvictionRule): void {
|
|
42
|
-
this.postEventRules.push(rule);
|
|
43
|
-
this.log.debug(`Registered eviction rule: ${rule.name}`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Runs all pre-add rules for an incoming transaction.
|
|
48
|
-
* Returns combined result of all rules.
|
|
49
|
-
*/
|
|
50
|
-
async runPreAddRules(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
|
|
51
|
-
const allTxHashesToEvict: string[] = [];
|
|
52
|
-
|
|
53
|
-
for (const rule of this.preAddRules) {
|
|
54
|
-
try {
|
|
55
|
-
const result = await rule.check(incomingMeta, poolAccess);
|
|
56
|
-
|
|
57
|
-
if (result.shouldIgnore) {
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Collect txs to evict from all rules
|
|
62
|
-
for (const txHash of result.txHashesToEvict) {
|
|
63
|
-
if (!allTxHashesToEvict.includes(txHash)) {
|
|
64
|
-
allTxHashesToEvict.push(txHash);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} catch (err) {
|
|
68
|
-
this.log.error(`Error running pre-add rule ${rule.name}`, { err, txHash: incomingMeta.txHash });
|
|
69
|
-
// On error, ignore the transaction to be safe
|
|
70
|
-
return {
|
|
71
|
-
shouldIgnore: true,
|
|
72
|
-
txHashesToEvict: [],
|
|
73
|
-
reason: `pre-add rule ${rule.name} error: ${err}`,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
shouldIgnore: false,
|
|
80
|
-
txHashesToEvict: allTxHashesToEvict,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Runs post-event eviction after new transactions are added.
|
|
86
|
-
*/
|
|
87
|
-
async evictAfterNewTxs(newTxHashes: string[], feePayers: string[]): Promise<void> {
|
|
88
|
-
const context: EvictionContext = {
|
|
89
|
-
event: EvictionEvent.TXS_ADDED,
|
|
90
|
-
newTxHashes,
|
|
91
|
-
feePayers,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
await this.runPostEventRules(context);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Runs post-event eviction after a block is mined.
|
|
99
|
-
*/
|
|
100
|
-
async evictAfterNewBlock(block: BlockHeader, newNullifiers: string[], feePayers: string[]): Promise<void> {
|
|
101
|
-
const context: EvictionContext = {
|
|
102
|
-
event: EvictionEvent.BLOCK_MINED,
|
|
103
|
-
block,
|
|
104
|
-
newNullifiers,
|
|
105
|
-
feePayers,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
await this.runPostEventRules(context);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Runs post-event eviction after a chain prune (reorg).
|
|
113
|
-
*/
|
|
114
|
-
async evictAfterChainPrune(blockNumber: BlockNumber): Promise<void> {
|
|
115
|
-
const context: EvictionContext = {
|
|
116
|
-
event: EvictionEvent.CHAIN_PRUNED,
|
|
117
|
-
blockNumber,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
await this.runPostEventRules(context);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Updates configuration for all rules.
|
|
125
|
-
*/
|
|
126
|
-
updateConfig(config: EvictionConfig): void {
|
|
127
|
-
for (const rule of this.preAddRules) {
|
|
128
|
-
rule.updateConfig?.(config);
|
|
129
|
-
}
|
|
130
|
-
for (const rule of this.postEventRules) {
|
|
131
|
-
rule.updateConfig?.(config);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private async runPostEventRules(context: EvictionContext): Promise<void> {
|
|
136
|
-
for (const rule of this.postEventRules) {
|
|
137
|
-
try {
|
|
138
|
-
const result = await rule.evict(context, this.pool);
|
|
139
|
-
if (!result.success) {
|
|
140
|
-
this.log.warn(`Eviction rule ${rule.name} failed`, { error: result.error });
|
|
141
|
-
}
|
|
142
|
-
} catch (err) {
|
|
143
|
-
this.log.error(`Error running eviction rule ${rule.name}`, { err });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
6
|
-
import { DatabasePublicStateSource, type MerkleTreeReadOperations } from '@aztec/stdlib/trees';
|
|
7
|
-
|
|
8
|
-
import { type TxMetaData, comparePriority } from '../tx_metadata.js';
|
|
9
|
-
import type { EvictionContext, EvictionResult, EvictionRule, PoolOperations } from './interfaces.js';
|
|
10
|
-
import { EvictionEvent } from './interfaces.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Eviction rule that removes transactions when fee payers have insufficient balance.
|
|
14
|
-
* Triggers on TXS_ADDED, BLOCK_MINED, and CHAIN_PRUNED events.
|
|
15
|
-
*/
|
|
16
|
-
export class FeePayerBalanceEvictionRule implements EvictionRule {
|
|
17
|
-
public readonly name = 'FeePayerBalanceEviction';
|
|
18
|
-
public readonly reason = 'fee_payer_balance';
|
|
19
|
-
|
|
20
|
-
private log = createLogger('p2p:tx_pool_v2:fee_payer_balance_eviction_rule');
|
|
21
|
-
|
|
22
|
-
constructor(private worldState: WorldStateSynchronizer) {}
|
|
23
|
-
|
|
24
|
-
async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
|
|
25
|
-
try {
|
|
26
|
-
if (context.event === EvictionEvent.TXS_ADDED) {
|
|
27
|
-
return await this.evictForFeePayers(context.feePayers, this.worldState.getCommitted(), pool);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (context.event === EvictionEvent.BLOCK_MINED) {
|
|
31
|
-
const blockNumber = context.block.getBlockNumber();
|
|
32
|
-
await this.worldState.syncImmediate(blockNumber);
|
|
33
|
-
return await this.evictForFeePayers(context.feePayers, this.worldState.getSnapshot(blockNumber), pool);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (context.event === EvictionEvent.CHAIN_PRUNED) {
|
|
37
|
-
await this.worldState.syncImmediate(context.blockNumber);
|
|
38
|
-
const feePayers = pool.getPendingFeePayers();
|
|
39
|
-
return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), pool);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
reason: this.reason,
|
|
44
|
-
success: true,
|
|
45
|
-
txsEvicted: [],
|
|
46
|
-
};
|
|
47
|
-
} catch (err) {
|
|
48
|
-
this.log.error('Failed to evict txs due to fee payer balance', { err });
|
|
49
|
-
return {
|
|
50
|
-
reason: this.reason,
|
|
51
|
-
success: false,
|
|
52
|
-
txsEvicted: [],
|
|
53
|
-
error: new Error('Failed to evict txs due to fee payer balance', { cause: err }),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private async evictForFeePayers(
|
|
59
|
-
feePayers: string[],
|
|
60
|
-
db: MerkleTreeReadOperations,
|
|
61
|
-
pool: PoolOperations,
|
|
62
|
-
): Promise<EvictionResult> {
|
|
63
|
-
const publicStateSource = new DatabasePublicStateSource(db);
|
|
64
|
-
|
|
65
|
-
const txsToEvict = (
|
|
66
|
-
await Promise.all(feePayers.map(feePayer => this.getEvictionsForFeePayer(feePayer, publicStateSource, pool)))
|
|
67
|
-
).flat();
|
|
68
|
-
|
|
69
|
-
if (txsToEvict.length > 0) {
|
|
70
|
-
await pool.deleteTxs(txsToEvict);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
reason: this.reason,
|
|
75
|
-
success: true,
|
|
76
|
-
txsEvicted: txsToEvict,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private async getEvictionsForFeePayer(
|
|
81
|
-
feePayerStr: string,
|
|
82
|
-
publicStateSource: DatabasePublicStateSource,
|
|
83
|
-
pool: PoolOperations,
|
|
84
|
-
): Promise<string[]> {
|
|
85
|
-
const feePayer = AztecAddress.fromString(feePayerStr);
|
|
86
|
-
const initialBalance = (
|
|
87
|
-
await publicStateSource.storageRead(
|
|
88
|
-
ProtocolContractAddress.FeeJuice,
|
|
89
|
-
await computeFeePayerBalanceStorageSlot(feePayer),
|
|
90
|
-
)
|
|
91
|
-
).toBigInt();
|
|
92
|
-
|
|
93
|
-
const txs: TxMetaData[] = pool.getFeePayerPendingTxs(feePayerStr);
|
|
94
|
-
|
|
95
|
-
if (txs.length === 0) {
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const txsToEvict: string[] = [];
|
|
100
|
-
let balance = initialBalance;
|
|
101
|
-
|
|
102
|
-
// Sort by priority descending (highest first), with hash as tiebreaker
|
|
103
|
-
txs.sort((a, b) => comparePriority(b, a));
|
|
104
|
-
|
|
105
|
-
for (const tx of txs) {
|
|
106
|
-
const available = balance + tx.claimAmount;
|
|
107
|
-
if (available >= tx.feeLimit) {
|
|
108
|
-
balance = available - tx.feeLimit;
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// This tx cannot be covered - mark for eviction
|
|
113
|
-
txsToEvict.push(tx.txHash);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return txsToEvict;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
|
|
3
|
-
import { type TxMetaData, comparePriority } from '../tx_metadata.js';
|
|
4
|
-
import type { PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Pre-add rule that checks if a fee payer has sufficient balance to cover the incoming transaction.
|
|
8
|
-
*
|
|
9
|
-
* When an incoming tx is added:
|
|
10
|
-
* - Get the fee payer's on-chain balance
|
|
11
|
-
* - Get all existing pending txs for this fee payer
|
|
12
|
-
* - Insert incoming tx in priority order
|
|
13
|
-
* - Walk through in priority order, tracking running balance
|
|
14
|
-
* - If incoming tx can be covered: accept, mark lower-priority txs for eviction if needed
|
|
15
|
-
* - If incoming tx cannot be covered: ignore it
|
|
16
|
-
*/
|
|
17
|
-
export class FeePayerBalancePreAddRule implements PreAddRule {
|
|
18
|
-
public readonly name = 'FeePayerBalancePreAdd';
|
|
19
|
-
|
|
20
|
-
private log = createLogger('p2p:tx_pool_v2:fee_payer_balance_pre_add_rule');
|
|
21
|
-
|
|
22
|
-
async check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
|
|
23
|
-
// Get fee payer's on-chain balance
|
|
24
|
-
const initialBalance = await poolAccess.getFeePayerBalance(incomingMeta.feePayer);
|
|
25
|
-
|
|
26
|
-
// Get existing pending txs for this fee payer
|
|
27
|
-
const existingTxs = poolAccess.getFeePayerPendingTxs(incomingMeta.feePayer);
|
|
28
|
-
|
|
29
|
-
// Create combined list with incoming tx
|
|
30
|
-
const allTxs: Array<{
|
|
31
|
-
txHash: string;
|
|
32
|
-
priorityFee: bigint;
|
|
33
|
-
feeLimit: bigint;
|
|
34
|
-
claimAmount: bigint;
|
|
35
|
-
isIncoming: boolean;
|
|
36
|
-
}> = [
|
|
37
|
-
...existingTxs.map(t => ({
|
|
38
|
-
txHash: t.txHash,
|
|
39
|
-
priorityFee: t.priorityFee,
|
|
40
|
-
feeLimit: t.feeLimit,
|
|
41
|
-
claimAmount: t.claimAmount,
|
|
42
|
-
isIncoming: false,
|
|
43
|
-
})),
|
|
44
|
-
{
|
|
45
|
-
txHash: incomingMeta.txHash,
|
|
46
|
-
priorityFee: incomingMeta.priorityFee,
|
|
47
|
-
feeLimit: incomingMeta.feeLimit,
|
|
48
|
-
claimAmount: incomingMeta.claimAmount,
|
|
49
|
-
isIncoming: true,
|
|
50
|
-
},
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
// Sort by priority descending (highest first), with hash as tiebreaker
|
|
54
|
-
allTxs.sort((a, b) => comparePriority(b, a));
|
|
55
|
-
|
|
56
|
-
// Walk through in priority order, tracking balance
|
|
57
|
-
let balance = initialBalance;
|
|
58
|
-
let incomingTxCovered = false;
|
|
59
|
-
const txsToEvict: string[] = [];
|
|
60
|
-
|
|
61
|
-
for (const txInfo of allTxs) {
|
|
62
|
-
const available = balance + txInfo.claimAmount;
|
|
63
|
-
|
|
64
|
-
if (available >= txInfo.feeLimit) {
|
|
65
|
-
// This tx can be covered
|
|
66
|
-
balance = available - txInfo.feeLimit;
|
|
67
|
-
if (txInfo.isIncoming) {
|
|
68
|
-
incomingTxCovered = true;
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
// This tx cannot be covered
|
|
72
|
-
if (txInfo.isIncoming) {
|
|
73
|
-
// Incoming tx cannot be covered - ignore it
|
|
74
|
-
this.log.debug(
|
|
75
|
-
`Ignoring tx ${incomingMeta.txHash}: fee payer ${incomingMeta.feePayer} has insufficient balance`,
|
|
76
|
-
{ balance: initialBalance, feeLimit: incomingMeta.feeLimit, claimAmount: incomingMeta.claimAmount },
|
|
77
|
-
);
|
|
78
|
-
return {
|
|
79
|
-
shouldIgnore: true,
|
|
80
|
-
txHashesToEvict: [],
|
|
81
|
-
reason: `fee payer ${incomingMeta.feePayer} has insufficient balance`,
|
|
82
|
-
};
|
|
83
|
-
} else {
|
|
84
|
-
// Existing tx cannot be covered after adding incoming - mark for eviction
|
|
85
|
-
txsToEvict.push(txInfo.txHash);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!incomingTxCovered) {
|
|
91
|
-
// This shouldn't happen if the logic above is correct, but just in case
|
|
92
|
-
this.log.warn(`Incoming tx ${incomingMeta.txHash} was not covered but also not ignored - this is a bug`);
|
|
93
|
-
return {
|
|
94
|
-
shouldIgnore: true,
|
|
95
|
-
txHashesToEvict: [],
|
|
96
|
-
reason: 'internal error: tx coverage not determined',
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (txsToEvict.length > 0) {
|
|
101
|
-
this.log.debug(
|
|
102
|
-
`Accepting tx ${incomingMeta.txHash}, evicting ${txsToEvict.length} lower-priority txs due to fee payer balance`,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
shouldIgnore: false,
|
|
108
|
-
txHashesToEvict: txsToEvict,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export { EvictionManager } from './eviction_manager.js';
|
|
2
|
-
export {
|
|
3
|
-
type EvictionConfig,
|
|
4
|
-
type EvictionContext,
|
|
5
|
-
EvictionEvent,
|
|
6
|
-
type EvictionResult,
|
|
7
|
-
type EvictionRule,
|
|
8
|
-
type PoolOperations,
|
|
9
|
-
type PreAddPoolAccess,
|
|
10
|
-
type PreAddResult,
|
|
11
|
-
type PreAddRule,
|
|
12
|
-
} from './interfaces.js';
|
|
13
|
-
|
|
14
|
-
// Pre-add rules
|
|
15
|
-
export { NullifierConflictRule } from './nullifier_conflict_rule.js';
|
|
16
|
-
export { FeePayerBalancePreAddRule } from './fee_payer_balance_pre_add_rule.js';
|
|
17
|
-
export { LowPriorityPreAddRule } from './low_priority_pre_add_rule.js';
|
|
18
|
-
|
|
19
|
-
// Post-event eviction rules
|
|
20
|
-
export { InvalidTxsAfterMiningRule } from './invalid_txs_after_mining_rule.js';
|
|
21
|
-
export { InvalidTxsAfterReorgRule } from './invalid_txs_after_reorg_rule.js';
|
|
22
|
-
export { FeePayerBalanceEvictionRule } from './fee_payer_balance_eviction_rule.js';
|
|
23
|
-
export { LowPriorityEvictionRule } from './low_priority_eviction_rule.js';
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
3
|
-
|
|
4
|
-
import type { TxMetaData } from '../tx_metadata.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Events that trigger eviction checks.
|
|
8
|
-
*/
|
|
9
|
-
export const EvictionEvent = {
|
|
10
|
-
TXS_ADDED: 'txs_added',
|
|
11
|
-
BLOCK_MINED: 'block_mined',
|
|
12
|
-
CHAIN_PRUNED: 'chain_pruned',
|
|
13
|
-
} as const;
|
|
14
|
-
|
|
15
|
-
export type EvictionEventType = (typeof EvictionEvent)[keyof typeof EvictionEvent];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Context passed to eviction rules based on the triggering event.
|
|
19
|
-
*/
|
|
20
|
-
export type EvictionContext =
|
|
21
|
-
| {
|
|
22
|
-
event: typeof EvictionEvent.TXS_ADDED;
|
|
23
|
-
newTxHashes: string[];
|
|
24
|
-
feePayers: string[];
|
|
25
|
-
}
|
|
26
|
-
| {
|
|
27
|
-
event: typeof EvictionEvent.CHAIN_PRUNED;
|
|
28
|
-
blockNumber: BlockNumber;
|
|
29
|
-
}
|
|
30
|
-
| {
|
|
31
|
-
event: typeof EvictionEvent.BLOCK_MINED;
|
|
32
|
-
block: BlockHeader;
|
|
33
|
-
newNullifiers: string[];
|
|
34
|
-
feePayers: string[];
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Result of an eviction operation.
|
|
39
|
-
*/
|
|
40
|
-
export interface EvictionResult {
|
|
41
|
-
readonly txsEvicted: string[];
|
|
42
|
-
readonly reason: string;
|
|
43
|
-
readonly success: boolean;
|
|
44
|
-
readonly error?: Error;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Read-only access to pool state for pre-add checks.
|
|
49
|
-
*/
|
|
50
|
-
export interface PreAddPoolAccess {
|
|
51
|
-
/** Get metadata for a pending tx by its hash string */
|
|
52
|
-
getMetadata(txHashStr: string): TxMetaData | undefined;
|
|
53
|
-
|
|
54
|
-
/** Get the pending tx hash that uses a specific nullifier (as string) */
|
|
55
|
-
getTxHashByNullifier(nullifier: string): string | undefined;
|
|
56
|
-
|
|
57
|
-
/** Get on-chain balance for a fee payer address */
|
|
58
|
-
getFeePayerBalance(feePayer: string): Promise<bigint>;
|
|
59
|
-
|
|
60
|
-
/** Get metadata for all pending txs from a specific fee payer */
|
|
61
|
-
getFeePayerPendingTxs(feePayer: string): TxMetaData[];
|
|
62
|
-
|
|
63
|
-
/** Get current count of pending transactions */
|
|
64
|
-
getPendingTxCount(): number;
|
|
65
|
-
|
|
66
|
-
/** Get the lowest priority pending tx metadata */
|
|
67
|
-
getLowestPriorityPendingTx(): TxMetaData | undefined;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Result of a pre-add check for a single transaction.
|
|
72
|
-
*/
|
|
73
|
-
export interface PreAddResult {
|
|
74
|
-
/** Whether the incoming tx should be ignored (valid but not desired) */
|
|
75
|
-
readonly shouldIgnore: boolean;
|
|
76
|
-
/** Tx hashes (as strings) that should be evicted if this tx is added */
|
|
77
|
-
readonly txHashesToEvict: string[];
|
|
78
|
-
/** Optional reason for ignoring */
|
|
79
|
-
readonly reason?: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Pre-add rule interface. Rules check incoming txs before they're added to the pool.
|
|
84
|
-
* All methods work with TxMetaData for efficiency.
|
|
85
|
-
*/
|
|
86
|
-
export interface PreAddRule {
|
|
87
|
-
readonly name: string;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Check if incoming tx should be added and which existing txs to evict.
|
|
91
|
-
* @param incomingMeta - Metadata for the incoming transaction
|
|
92
|
-
* @param poolAccess - Read-only access to current pool state
|
|
93
|
-
* @returns Result indicating whether to ignore and what to evict
|
|
94
|
-
*/
|
|
95
|
-
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult>;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Updates the configuration for this rule.
|
|
99
|
-
*/
|
|
100
|
-
updateConfig?(config: EvictionConfig): void;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Operations that post-event eviction rules can perform on the pool.
|
|
105
|
-
* All methods work with metadata and strings for efficiency.
|
|
106
|
-
*/
|
|
107
|
-
export interface PoolOperations {
|
|
108
|
-
/** Get all pending tx metadata */
|
|
109
|
-
getPendingTxs(): TxMetaData[];
|
|
110
|
-
|
|
111
|
-
/** Get unique fee payers from pending transactions */
|
|
112
|
-
getPendingFeePayers(): string[];
|
|
113
|
-
|
|
114
|
-
/** Get metadata for all pending txs from a specific fee payer */
|
|
115
|
-
getFeePayerPendingTxs(feePayer: string): TxMetaData[];
|
|
116
|
-
|
|
117
|
-
/** Get current count of pending transactions */
|
|
118
|
-
getPendingTxCount(): number;
|
|
119
|
-
|
|
120
|
-
/** Get the N lowest priority pending tx hashes */
|
|
121
|
-
getLowestPriorityPending(limit: number): string[];
|
|
122
|
-
|
|
123
|
-
/** Delete transactions by hash */
|
|
124
|
-
deleteTxs(txHashes: string[]): Promise<void>;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Post-event eviction rule interface. Rules run after events to clean up the pool.
|
|
129
|
-
*/
|
|
130
|
-
export interface EvictionRule {
|
|
131
|
-
readonly name: string;
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Performs the eviction logic after an event.
|
|
135
|
-
*/
|
|
136
|
-
evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult>;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Updates the configuration for this rule.
|
|
140
|
-
*/
|
|
141
|
-
updateConfig?(config: EvictionConfig): void;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Configuration options for eviction rules.
|
|
146
|
-
*/
|
|
147
|
-
export interface EvictionConfig {
|
|
148
|
-
/** Maximum number of pending transactions (0 = unlimited) */
|
|
149
|
-
maxPendingTxCount?: number;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Converts a TxHash to its string representation for use in eviction results.
|
|
154
|
-
*/
|
|
155
|
-
export function txHashToString(txHash: TxHash): string {
|
|
156
|
-
return txHash.toString();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Converts an array of TxHash to string array.
|
|
161
|
-
*/
|
|
162
|
-
export function txHashesToStrings(txHashes: TxHash[]): string[] {
|
|
163
|
-
return txHashes.map(h => h.toString());
|
|
164
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
|
|
3
|
-
import type { EvictionContext, EvictionResult, EvictionRule, PoolOperations } from './interfaces.js';
|
|
4
|
-
import { EvictionEvent } from './interfaces.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Eviction rule that removes invalid transactions after a block is mined.
|
|
8
|
-
* Only triggers on BLOCK_MINED events.
|
|
9
|
-
*
|
|
10
|
-
* Eviction criteria includes:
|
|
11
|
-
* - Transactions with nullifiers that are already included in the mined block
|
|
12
|
-
* - Transactions with an expiration timestamp less than or equal to the mined block timestamp
|
|
13
|
-
*/
|
|
14
|
-
export class InvalidTxsAfterMiningRule implements EvictionRule {
|
|
15
|
-
public readonly name = 'InvalidTxsAfterMining';
|
|
16
|
-
|
|
17
|
-
private log = createLogger('p2p:tx_pool_v2:invalid_txs_after_mining_rule');
|
|
18
|
-
|
|
19
|
-
async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
|
|
20
|
-
if (context.event !== EvictionEvent.BLOCK_MINED) {
|
|
21
|
-
return {
|
|
22
|
-
reason: 'block_mined_invalid_txs',
|
|
23
|
-
success: true,
|
|
24
|
-
txsEvicted: [],
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const { timestamp } = context.block.globalVariables;
|
|
30
|
-
const minedNullifiers = new Set(context.newNullifiers);
|
|
31
|
-
|
|
32
|
-
const txsToEvict: string[] = [];
|
|
33
|
-
const pendingTxs = pool.getPendingTxs();
|
|
34
|
-
|
|
35
|
-
for (const meta of pendingTxs) {
|
|
36
|
-
// Evict pending txs that share nullifiers with mined txs
|
|
37
|
-
if (meta.nullifiers.some(nullifier => minedNullifiers.has(nullifier))) {
|
|
38
|
-
this.log.verbose(`Evicting tx ${meta.txHash} from pool due to a duplicate nullifier with a mined tx`);
|
|
39
|
-
txsToEvict.push(meta.txHash);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
|
|
44
|
-
if (meta.includeByTimestamp <= timestamp) {
|
|
45
|
-
this.log.verbose(
|
|
46
|
-
`Evicting tx ${meta.txHash} from pool due to the tx being expired (includeByTimestamp: ${meta.includeByTimestamp}, mined block timestamp: ${timestamp})`,
|
|
47
|
-
);
|
|
48
|
-
txsToEvict.push(meta.txHash);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (txsToEvict.length > 0) {
|
|
54
|
-
await pool.deleteTxs(txsToEvict);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.log.debug(`Evicted ${txsToEvict.length} invalid txs after block mined`);
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
reason: 'block_mined_invalid_txs',
|
|
61
|
-
success: true,
|
|
62
|
-
txsEvicted: txsToEvict,
|
|
63
|
-
};
|
|
64
|
-
} catch (err) {
|
|
65
|
-
this.log.error('Failed to evict invalid transactions after mining', { err });
|
|
66
|
-
return {
|
|
67
|
-
reason: 'block_mined_invalid_txs',
|
|
68
|
-
success: false,
|
|
69
|
-
txsEvicted: [],
|
|
70
|
-
error: new Error('Failed to evict invalid txs after mining', { cause: err }),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|