@aztec/p2p 0.0.1-commit.7cf39cb55 → 0.0.1-commit.808bf7f90
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 +3 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +5 -3
- package/dest/client/interface.d.ts +7 -9
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +4 -7
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +38 -14
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +5 -5
- package/dest/config.d.ts +4 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +0 -5
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +10 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -5
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +12 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +12 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +7 -5
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +29 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +12 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +5 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +10 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +240 -124
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +3 -3
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/dummy_service.d.ts +3 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +2 -1
- package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +32 -10
- package/dest/services/libp2p/libp2p_service.d.ts +2 -1
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +7 -3
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
- 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 +5 -9
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
- package/dest/services/service.d.ts +4 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +39 -33
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
- package/dest/services/tx_collection/file_store_tx_source.d.ts +15 -6
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +47 -16
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
- 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/dest/services/tx_collection/slow_tx_collection.d.ts +2 -2
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +10 -8
- package/dest/services/tx_collection/tx_collection.d.ts +5 -4
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +13 -22
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/tx_file_store.js +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +3 -2
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +6 -0
- package/dest/test-helpers/testbench-utils.d.ts +5 -2
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +1 -1
- package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +8 -8
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +6 -2
- package/src/client/interface.ts +14 -9
- package/src/client/p2p_client.ts +44 -17
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +18 -8
- package/src/config.ts +2 -10
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/tx_pool/README.md +1 -1
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/README.md +1 -1
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +15 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +4 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +12 -9
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +11 -2
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +40 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +14 -3
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +11 -6
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +262 -117
- package/src/msg_validators/tx_validator/gas_validator.ts +11 -3
- package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
- package/src/services/dummy_service.ts +5 -1
- package/src/services/encoding.ts +2 -1
- package/src/services/gossipsub/README.md +29 -14
- package/src/services/gossipsub/topic_score_params.ts +49 -13
- package/src/services/libp2p/libp2p_service.ts +7 -2
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +6 -6
- package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
- package/src/services/service.ts +10 -1
- package/src/services/tx_collection/fast_tx_collection.ts +51 -30
- package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
- package/src/services/tx_collection/file_store_tx_source.ts +61 -17
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
- package/src/services/tx_collection/slow_tx_collection.ts +8 -9
- package/src/services/tx_collection/tx_collection.ts +4 -3
- package/src/services/tx_collection/tx_collection_sink.ts +15 -29
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/tx_file_store.ts +1 -1
- package/src/test-helpers/mock-pubsub.ts +10 -0
- package/src/test-helpers/testbench-utils.ts +2 -2
- package/src/testbench/p2p_client_testbench_worker.ts +20 -13
- package/src/util.ts +7 -1
|
@@ -4,6 +4,7 @@ import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
|
|
|
4
4
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import type { BlockHeader, Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
|
+
import type { TxPoolRejectionError } from './eviction/interfaces.js';
|
|
7
8
|
import type { TxMetaData, TxState } from './tx_metadata.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -17,6 +18,8 @@ export type AddTxsResult = {
|
|
|
17
18
|
ignored: TxHash[];
|
|
18
19
|
/** Transactions rejected because they failed validation (e.g., invalid proof, expired timestamp) */
|
|
19
20
|
rejected: TxHash[];
|
|
21
|
+
/** Optional rejection errors, only present when there are rejections with structured errors. */
|
|
22
|
+
errors?: Map<string, TxPoolRejectionError>;
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
/**
|
|
@@ -39,6 +42,10 @@ export type TxPoolV2Config = {
|
|
|
39
42
|
archivedTxLimit: number;
|
|
40
43
|
/** Minimum age (ms) a transaction must have been in the pool before it's eligible for block building */
|
|
41
44
|
minTxPoolAgeMs: number;
|
|
45
|
+
/** Maximum number of evicted tx hashes to remember for metrics tracking */
|
|
46
|
+
evictedTxCacheSize: number;
|
|
47
|
+
/** The probability (0-1) that a transaction is discarded. 0 disables dropping. For testing purposes only. */
|
|
48
|
+
dropTransactionsProbability: number;
|
|
42
49
|
};
|
|
43
50
|
|
|
44
51
|
/**
|
|
@@ -48,6 +55,8 @@ export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
|
|
|
48
55
|
maxPendingTxCount: 0, // 0 = disabled
|
|
49
56
|
archivedTxLimit: 0, // 0 = disabled
|
|
50
57
|
minTxPoolAgeMs: 2_000,
|
|
58
|
+
evictedTxCacheSize: 10_000,
|
|
59
|
+
dropTransactionsProbability: 0,
|
|
51
60
|
};
|
|
52
61
|
|
|
53
62
|
/**
|
|
@@ -98,7 +107,7 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
98
107
|
* @param opts - Optional metadata (e.g., source for logging)
|
|
99
108
|
* @returns Result categorizing each transaction as accepted, rejected, or ignored
|
|
100
109
|
*/
|
|
101
|
-
addPendingTxs(txs: Tx[], opts?: { source?: string }): Promise<AddTxsResult>;
|
|
110
|
+
addPendingTxs(txs: Tx[], opts?: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult>;
|
|
102
111
|
|
|
103
112
|
/**
|
|
104
113
|
* Checks if a transaction can be added without modifying the pool.
|
|
@@ -159,7 +168,7 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
159
168
|
* and validates them before returning to pending.
|
|
160
169
|
* @param latestBlock - The latest valid block ID after the prune
|
|
161
170
|
*/
|
|
162
|
-
handlePrunedBlocks(latestBlock: L2BlockId): Promise<void>;
|
|
171
|
+
handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void>;
|
|
163
172
|
|
|
164
173
|
/**
|
|
165
174
|
* Handles failed transaction execution.
|
|
@@ -6,12 +6,12 @@ import type { Tx } from '@aztec/stdlib/tx';
|
|
|
6
6
|
|
|
7
7
|
import { getFeePayerBalanceDelta } from '../../msg_validators/tx_validator/fee_payer_balance.js';
|
|
8
8
|
import { getTxPriorityFee } from '../tx_pool/priority.js';
|
|
9
|
-
import type
|
|
9
|
+
import { type PreAddResult, TxPoolRejectionCode } from './eviction/interfaces.js';
|
|
10
10
|
|
|
11
11
|
/** Validator-compatible data interface, mirroring the subset of PrivateKernelTailCircuitPublicInputs used by validators. */
|
|
12
12
|
export type TxMetaValidationData = {
|
|
13
13
|
getNonEmptyNullifiers(): Fr[];
|
|
14
|
-
|
|
14
|
+
expirationTimestamp: bigint;
|
|
15
15
|
constants: {
|
|
16
16
|
anchorBlockHeader: {
|
|
17
17
|
hash(): Promise<BlockHash>;
|
|
@@ -56,13 +56,16 @@ export type TxMetaData = {
|
|
|
56
56
|
readonly nullifiers: readonly string[];
|
|
57
57
|
|
|
58
58
|
/** Timestamp by which the transaction must be included (for expiration checks) */
|
|
59
|
-
readonly
|
|
59
|
+
readonly expirationTimestamp: bigint;
|
|
60
60
|
|
|
61
61
|
/** Validator-compatible data, providing the same access patterns as Tx.data */
|
|
62
62
|
readonly data: TxMetaValidationData;
|
|
63
63
|
|
|
64
64
|
/** Timestamp (ms) when the tx was received into the pool. 0 for hydrated txs (always eligible). */
|
|
65
65
|
receivedAt: number;
|
|
66
|
+
|
|
67
|
+
/** Estimated memory footprint of this metadata object in bytes */
|
|
68
|
+
readonly estimatedSizeBytes: number;
|
|
66
69
|
};
|
|
67
70
|
|
|
68
71
|
/** Transaction state derived from TxMetaData fields and pool protection status */
|
|
@@ -79,13 +82,15 @@ export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
|
|
|
79
82
|
const nullifiers = nullifierFrs.map(n => n.toString());
|
|
80
83
|
const anchorBlockHeaderHashFr = await tx.data.constants.anchorBlockHeader.hash();
|
|
81
84
|
const anchorBlockHeaderHash = anchorBlockHeaderHashFr.toString();
|
|
82
|
-
const
|
|
85
|
+
const expirationTimestamp = tx.data.expirationTimestamp;
|
|
83
86
|
const anchorBlockNumber = tx.data.constants.anchorBlockHeader.globalVariables.blockNumber;
|
|
84
87
|
const priorityFee = getTxPriorityFee(tx);
|
|
85
88
|
const feePayer = tx.data.feePayer.toString();
|
|
86
89
|
|
|
87
90
|
const { feeLimit, claimAmount } = await getFeePayerBalanceDelta(tx, ProtocolContractAddress.FeeJuice);
|
|
88
91
|
|
|
92
|
+
const estimatedSizeBytes = estimateTxMetaDataSize(nullifiers.length);
|
|
93
|
+
|
|
89
94
|
return {
|
|
90
95
|
txHash,
|
|
91
96
|
anchorBlockHeaderHash,
|
|
@@ -94,11 +99,12 @@ export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
|
|
|
94
99
|
claimAmount,
|
|
95
100
|
feeLimit,
|
|
96
101
|
nullifiers,
|
|
97
|
-
|
|
102
|
+
expirationTimestamp,
|
|
98
103
|
receivedAt: 0,
|
|
104
|
+
estimatedSizeBytes,
|
|
99
105
|
data: {
|
|
100
106
|
getNonEmptyNullifiers: () => nullifierFrs,
|
|
101
|
-
|
|
107
|
+
expirationTimestamp,
|
|
102
108
|
constants: {
|
|
103
109
|
anchorBlockHeader: {
|
|
104
110
|
hash: () => Promise.resolve(anchorBlockHeaderHashFr),
|
|
@@ -109,6 +115,27 @@ export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
|
|
|
109
115
|
};
|
|
110
116
|
}
|
|
111
117
|
|
|
118
|
+
// V8 JS object overhead (~64 bytes for a plain object with hidden class).
|
|
119
|
+
// String overhead: ~32 bytes header + 1 byte per ASCII char (V8 one-byte strings).
|
|
120
|
+
// Hex string (0x + 64 hex chars = 66 chars): ~98 bytes per string.
|
|
121
|
+
// bigint: ~32 bytes. number: 8 bytes. Fr: ~80 bytes (32 data + object overhead).
|
|
122
|
+
const OBJECT_OVERHEAD = 64;
|
|
123
|
+
const HEX_STRING_BYTES = 98;
|
|
124
|
+
const BIGINT_BYTES = 32;
|
|
125
|
+
const FR_BYTES = 80;
|
|
126
|
+
// Fixed cost: object shell + txHash + anchorBlockHeaderHash + feePayer (3 hex strings)
|
|
127
|
+
// + priorityFee + claimAmount + feeLimit + includeByTimestamp (4 bigints)
|
|
128
|
+
// + receivedAt (number, 8 bytes) + estimatedSizeBytes (number, 8 bytes)
|
|
129
|
+
// + data closure object (~OBJECT_OVERHEAD + anchorBlockHeaderHashFr Fr + anchorBlockNumber number)
|
|
130
|
+
const FIXED_METADATA_BYTES =
|
|
131
|
+
OBJECT_OVERHEAD + 3 * HEX_STRING_BYTES + 4 * BIGINT_BYTES + 8 + 8 + OBJECT_OVERHEAD + FR_BYTES + 8;
|
|
132
|
+
|
|
133
|
+
/** Estimates the in-memory size of a TxMetaData object based on the number of nullifiers. */
|
|
134
|
+
function estimateTxMetaDataSize(nullifierCount: number): number {
|
|
135
|
+
// Per nullifier: one hex string in nullifiers[] + one Fr in the captured nullifierFrs[]
|
|
136
|
+
return FIXED_METADATA_BYTES + nullifierCount * (HEX_STRING_BYTES + FR_BYTES);
|
|
137
|
+
}
|
|
138
|
+
|
|
112
139
|
/** Minimal fields required for priority comparison. */
|
|
113
140
|
type PriorityComparable = Pick<TxMetaData, 'txHash' | 'priorityFee'>;
|
|
114
141
|
|
|
@@ -188,7 +215,11 @@ export function checkNullifierConflict(
|
|
|
188
215
|
return {
|
|
189
216
|
shouldIgnore: true,
|
|
190
217
|
txHashesToEvict: [],
|
|
191
|
-
reason:
|
|
218
|
+
reason: {
|
|
219
|
+
code: TxPoolRejectionCode.NULLIFIER_CONFLICT,
|
|
220
|
+
message: `Nullifier conflict with existing tx ${conflictingHashStr}`,
|
|
221
|
+
conflictingTxHash: conflictingHashStr,
|
|
222
|
+
},
|
|
192
223
|
};
|
|
193
224
|
}
|
|
194
225
|
}
|
|
@@ -197,10 +228,10 @@ export function checkNullifierConflict(
|
|
|
197
228
|
}
|
|
198
229
|
|
|
199
230
|
/** Creates a stub TxMetaValidationData for tests that don't exercise validators. */
|
|
200
|
-
export function stubTxMetaValidationData(overrides: {
|
|
231
|
+
export function stubTxMetaValidationData(overrides: { expirationTimestamp?: bigint } = {}): TxMetaValidationData {
|
|
201
232
|
return {
|
|
202
233
|
getNonEmptyNullifiers: () => [],
|
|
203
|
-
|
|
234
|
+
expirationTimestamp: overrides.expirationTimestamp ?? 0n,
|
|
204
235
|
constants: {
|
|
205
236
|
anchorBlockHeader: {
|
|
206
237
|
hash: () => Promise.resolve(new BlockHash(Fr.ZERO)),
|
|
@@ -348,13 +348,15 @@ export class TxPoolIndices {
|
|
|
348
348
|
// METRICS
|
|
349
349
|
// ============================================================================
|
|
350
350
|
|
|
351
|
-
/** Counts transactions by state */
|
|
352
|
-
countTxs(): { pending: number; protected: number; mined: number } {
|
|
351
|
+
/** Counts transactions by state and estimates total metadata memory usage */
|
|
352
|
+
countTxs(): { pending: number; protected: number; mined: number; totalMetadataBytes: number } {
|
|
353
353
|
let pending = 0;
|
|
354
354
|
let protected_ = 0;
|
|
355
355
|
let mined = 0;
|
|
356
|
+
let totalMetadataBytes = 0;
|
|
356
357
|
|
|
357
358
|
for (const meta of this.#metadata.values()) {
|
|
359
|
+
totalMetadataBytes += meta.estimatedSizeBytes;
|
|
358
360
|
const state = this.getTxState(meta);
|
|
359
361
|
if (state === 'pending') {
|
|
360
362
|
pending++;
|
|
@@ -365,7 +367,16 @@ export class TxPoolIndices {
|
|
|
365
367
|
}
|
|
366
368
|
}
|
|
367
369
|
|
|
368
|
-
return { pending, protected: protected_, mined };
|
|
370
|
+
return { pending, protected: protected_, mined, totalMetadataBytes };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** Returns the estimated total memory consumed by all metadata objects */
|
|
374
|
+
getTotalMetadataBytes(): number {
|
|
375
|
+
let total = 0;
|
|
376
|
+
for (const meta of this.#metadata.values()) {
|
|
377
|
+
total += meta.estimatedSizeBytes;
|
|
378
|
+
}
|
|
379
|
+
return total;
|
|
369
380
|
}
|
|
370
381
|
|
|
371
382
|
/** Gets all mined transactions with their block IDs */
|
|
@@ -61,7 +61,7 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
// Create the implementation
|
|
64
|
-
this.#impl = new TxPoolV2Impl(store, archiveStore, deps, callbacks, config, dateProvider, log);
|
|
64
|
+
this.#impl = new TxPoolV2Impl(store, archiveStore, deps, callbacks, telemetry, config, dateProvider, log);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// ============================================================================
|
|
@@ -70,7 +70,7 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
|
|
|
70
70
|
|
|
71
71
|
// === Core Operations ===
|
|
72
72
|
|
|
73
|
-
addPendingTxs(txs: Tx[], opts: { source?: string } = {}): Promise<AddTxsResult> {
|
|
73
|
+
addPendingTxs(txs: Tx[], opts: { source?: string; feeComparisonOnly?: boolean } = {}): Promise<AddTxsResult> {
|
|
74
74
|
return this.#queue.put(() => this.#impl.addPendingTxs(txs, opts));
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -83,7 +83,7 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
protectTxs(txHashes: TxHash[], block: BlockHeader): Promise<TxHash[]> {
|
|
86
|
-
return this.#queue.put(() =>
|
|
86
|
+
return this.#queue.put(() => this.#impl.protectTxs(txHashes, block));
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
addMinedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string } = {}): Promise<void> {
|
|
@@ -100,8 +100,8 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
|
|
|
100
100
|
return this.#queue.put(() => this.#impl.prepareForSlot(slotNumber));
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
handlePrunedBlocks(latestBlock: L2BlockId): Promise<void> {
|
|
104
|
-
return this.#queue.put(() => this.#impl.handlePrunedBlocks(latestBlock));
|
|
103
|
+
handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void> {
|
|
104
|
+
return this.#queue.put(() => this.#impl.handlePrunedBlocks(latestBlock, options));
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
@@ -195,7 +195,12 @@ export class AztecKVTxPoolV2 extends (EventEmitter as new () => TypedEventEmitte
|
|
|
195
195
|
this.#queue.put(() => {
|
|
196
196
|
const counts = this.#impl.countTxs();
|
|
197
197
|
return Promise.resolve({
|
|
198
|
-
itemCount: {
|
|
198
|
+
itemCount: {
|
|
199
|
+
pending: counts.pending,
|
|
200
|
+
protected: counts.protected,
|
|
201
|
+
mined: counts.mined,
|
|
202
|
+
softDeleted: counts.softDeleted,
|
|
203
|
+
},
|
|
199
204
|
});
|
|
200
205
|
}),
|
|
201
206
|
() => this.#store.estimateSize(),
|