@aztec/p2p 0.0.1-commit.9ef841308 → 0.0.1-commit.a89ec08
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 +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +1 -2
- package/dest/client/p2p_client.d.ts +1 -1
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +4 -6
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -17
- package/dest/config.d.ts +6 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +6 -6
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +4 -8
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +2 -1
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +2 -4
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +14 -16
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +125 -0
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +596 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +123 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +3 -0
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/index.js +2 -0
- package/dest/mem_pools/tx_pool/priority.d.ts +12 -0
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/priority.js +15 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +127 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/tx_pool.js +3 -0
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +7 -0
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +402 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +5 -7
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +0 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +6 -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 +1 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- 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 +43 -26
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +1 -1
- 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 +0 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -2
- 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 +1 -18
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +4 -5
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +3 -4
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +5 -5
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/services/discv5/discV5_service.d.ts +1 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +2 -4
- package/dest/services/libp2p/libp2p_service.d.ts +9 -7
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +59 -137
- package/dest/services/peer-manager/metrics.d.ts +1 -3
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +0 -6
- package/dest/services/peer-manager/peer_manager.d.ts +2 -6
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +9 -24
- package/dest/services/peer-manager/peer_scoring.d.ts +2 -5
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +10 -28
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +8 -11
- 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 +101 -82
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -3
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +4 -5
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +7 -13
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +11 -19
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +15 -52
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +3 -4
- package/dest/services/service.d.ts +1 -7
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +73 -57
- 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 +4 -4
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +6 -3
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +1 -6
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +1 -9
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +2 -20
- package/dest/testbench/p2p_client_testbench_worker.js +15 -44
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +2 -2
- package/dest/util.d.ts +4 -9
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +9 -2
- package/package.json +14 -14
- package/src/client/factory.ts +2 -3
- package/src/client/p2p_client.ts +4 -6
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +9 -19
- package/src/config.ts +10 -10
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +7 -8
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +3 -0
- package/src/mem_pools/instrumentation.ts +13 -17
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +746 -0
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +163 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +2 -0
- package/src/mem_pools/tx_pool/priority.ts +20 -0
- package/src/mem_pools/tx_pool/tx_pool.ts +141 -0
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +321 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +4 -7
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +5 -11
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -29
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +0 -3
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1 -19
- package/src/msg_validators/attestation_validator/README.md +1 -1
- package/src/msg_validators/attestation_validator/attestation_validator.ts +4 -5
- package/src/msg_validators/clock_tolerance.ts +3 -4
- package/src/msg_validators/proposal_validator/README.md +4 -4
- package/src/msg_validators/proposal_validator/proposal_validator.ts +5 -6
- package/src/msg_validators/tx_validator/metadata_validator.ts +4 -12
- package/src/services/discv5/discV5_service.ts +2 -4
- package/src/services/libp2p/libp2p_service.ts +71 -135
- package/src/services/peer-manager/metrics.ts +0 -7
- package/src/services/peer-manager/peer_manager.ts +9 -28
- package/src/services/peer-manager/peer_scoring.ts +5 -21
- package/src/services/reqresp/batch-tx-requester/README.md +7 -46
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +111 -78
- package/src/services/reqresp/batch-tx-requester/interface.ts +1 -2
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +6 -13
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +24 -68
- package/src/services/reqresp/reqresp.ts +3 -5
- package/src/services/service.ts +0 -7
- package/src/services/tx_collection/fast_tx_collection.ts +83 -57
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +13 -8
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +5 -3
- package/src/test-helpers/make-test-p2p-clients.ts +1 -1
- package/src/test-helpers/mock-pubsub.ts +0 -9
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/test-helpers/testbench-utils.ts +3 -28
- package/src/testbench/p2p_client_testbench_worker.ts +15 -44
- package/src/testbench/worker_client_manager.ts +2 -2
- package/src/util.ts +13 -9
- package/dest/services/tx_collection/request_tracker.d.ts +0 -53
- package/dest/services/tx_collection/request_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/request_tracker.js +0 -84
- package/src/services/tx_collection/request_tracker.ts +0 -127
package/src/config.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
secretStringConfigHelper,
|
|
12
12
|
} from '@aztec/foundation/config';
|
|
13
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
|
+
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
14
15
|
import { FunctionSelector } from '@aztec/stdlib/abi/function-selector';
|
|
15
16
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
17
|
import {
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
chainConfigMappings,
|
|
21
22
|
sharedSequencerConfigMappings,
|
|
22
23
|
} from '@aztec/stdlib/config';
|
|
23
|
-
import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
24
24
|
|
|
25
25
|
import {
|
|
26
26
|
type BatchTxRequesterConfig,
|
|
@@ -70,9 +70,6 @@ export interface P2PConfig
|
|
|
70
70
|
/** The frequency in which to check for new peers. */
|
|
71
71
|
peerCheckIntervalMS: number;
|
|
72
72
|
|
|
73
|
-
/** How long to ban a peer after it fails MAX_DIAL_ATTEMPTS dials. */
|
|
74
|
-
peerFailedBanTimeMs: number;
|
|
75
|
-
|
|
76
73
|
/** Size of queue of L2 blocks to store. */
|
|
77
74
|
l2QueueSize: number;
|
|
78
75
|
|
|
@@ -189,7 +186,10 @@ export interface P2PConfig
|
|
|
189
186
|
/** Whether transactions are disabled for this node. This means transactions will be rejected at the RPC and P2P layers. */
|
|
190
187
|
disableTransactions: boolean;
|
|
191
188
|
|
|
192
|
-
/**
|
|
189
|
+
/** True to simulate discarding transactions. - For testing purposes only*/
|
|
190
|
+
dropTransactions: boolean;
|
|
191
|
+
|
|
192
|
+
/** The probability that a transaction is discarded. - For testing purposes only */
|
|
193
193
|
dropTransactionsProbability: number;
|
|
194
194
|
|
|
195
195
|
/** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
|
|
@@ -266,11 +266,6 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
266
266
|
description: 'The frequency in which to check for new peers.',
|
|
267
267
|
...numberConfigHelper(30_000),
|
|
268
268
|
},
|
|
269
|
-
peerFailedBanTimeMs: {
|
|
270
|
-
env: 'P2P_PEER_FAILED_BAN_TIME_MS',
|
|
271
|
-
description: 'How long to ban a peer after it fails maximum dial attempts.',
|
|
272
|
-
...numberConfigHelper(5 * 60 * 1000),
|
|
273
|
-
},
|
|
274
269
|
l2QueueSize: {
|
|
275
270
|
env: 'P2P_L2_QUEUE_SIZE',
|
|
276
271
|
description: 'Size of queue of L2 blocks to store.',
|
|
@@ -474,6 +469,11 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
474
469
|
description: 'Number of auth attempts to allow before peer is banned. Number is inclusive',
|
|
475
470
|
...numberConfigHelper(3),
|
|
476
471
|
},
|
|
472
|
+
dropTransactions: {
|
|
473
|
+
env: 'P2P_DROP_TX',
|
|
474
|
+
description: 'True to simulate discarding transactions. - For testing purposes only',
|
|
475
|
+
...booleanConfigHelper(false),
|
|
476
|
+
},
|
|
477
477
|
dropTransactionsProbability: {
|
|
478
478
|
env: 'P2P_DROP_TX_CHANCE',
|
|
479
479
|
description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './client/index.js';
|
|
|
6
6
|
export * from './enr/index.js';
|
|
7
7
|
export * from './config.js';
|
|
8
8
|
export * from './mem_pools/attestation_pool/index.js';
|
|
9
|
+
export * from './mem_pools/tx_pool/index.js';
|
|
9
10
|
export * from './mem_pools/tx_pool_v2/index.js';
|
|
10
11
|
export * from './msg_validators/index.js';
|
|
11
12
|
export * from './services/index.js';
|
|
@@ -26,10 +26,10 @@ export type TryAddResult = {
|
|
|
26
26
|
count: number;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT =
|
|
30
|
-
export const MAX_BLOCK_PROPOSALS_PER_POSITION =
|
|
29
|
+
export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT = 5;
|
|
30
|
+
export const MAX_BLOCK_PROPOSALS_PER_POSITION = 3;
|
|
31
31
|
/** Maximum attestations a single signer can make per slot before being rejected. */
|
|
32
|
-
export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER =
|
|
32
|
+
export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER = 3;
|
|
33
33
|
|
|
34
34
|
/** Public API interface for attestation pools. Used for typing mocks and test implementations. */
|
|
35
35
|
export type AttestationPoolApi = Pick<
|
|
@@ -359,10 +359,11 @@ export class AttestationPool {
|
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
const address = sender.toString();
|
|
362
|
-
const ownKey = this.getAttestationKey(slotNumber, proposalId, address);
|
|
363
362
|
|
|
364
|
-
await this.checkpointAttestations.set(
|
|
365
|
-
|
|
363
|
+
await this.checkpointAttestations.set(
|
|
364
|
+
this.getAttestationKey(slotNumber, proposalId, address),
|
|
365
|
+
attestation.toBuffer(),
|
|
366
|
+
);
|
|
366
367
|
|
|
367
368
|
this.log.debug(`Added own checkpoint attestation for slot ${slotNumber} from ${address}`, {
|
|
368
369
|
signature: attestation.signature.toString(),
|
|
@@ -428,7 +429,6 @@ export class AttestationPool {
|
|
|
428
429
|
const attestationEndKey = new Fr(oldestSlot).toString();
|
|
429
430
|
for await (const key of this.checkpointAttestations.keysAsync({ end: attestationEndKey })) {
|
|
430
431
|
await this.checkpointAttestations.delete(key);
|
|
431
|
-
this.metrics.trackMempoolItemRemoved(key);
|
|
432
432
|
numberOfAttestations++;
|
|
433
433
|
}
|
|
434
434
|
|
|
@@ -526,7 +526,6 @@ export class AttestationPool {
|
|
|
526
526
|
|
|
527
527
|
// Add the attestation
|
|
528
528
|
await this.checkpointAttestations.set(key, attestation.toBuffer());
|
|
529
|
-
this.metrics.trackMempoolItemAdded(key);
|
|
530
529
|
|
|
531
530
|
// Track this attestation in the per-signer-per-slot index for duplicate detection
|
|
532
531
|
const slotSignerKey = this.getSlotSignerKey(slotNumber, signerAddress);
|
|
@@ -446,12 +446,12 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
|
|
|
446
446
|
const result2 = await ap.tryAddBlockProposal(proposal2);
|
|
447
447
|
expect(result2.count).toBe(2);
|
|
448
448
|
|
|
449
|
-
//
|
|
449
|
+
// Add a third proposal for same position
|
|
450
450
|
const proposal3 = await mockBlockProposalWithIndex(signers[2], slotNumber, indexWithinCheckpoint);
|
|
451
451
|
const result3 = await ap.tryAddBlockProposal(proposal3);
|
|
452
452
|
|
|
453
|
-
expect(result3.added).toBe(
|
|
454
|
-
expect(result3.count).toBe(
|
|
453
|
+
expect(result3.added).toBe(true);
|
|
454
|
+
expect(result3.count).toBe(3);
|
|
455
455
|
});
|
|
456
456
|
|
|
457
457
|
it('should return added=false when exceeding capacity', async () => {
|
|
@@ -666,12 +666,12 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
|
|
|
666
666
|
const result2 = await ap.tryAddCheckpointProposal(proposal2);
|
|
667
667
|
expect(result2.count).toBe(2);
|
|
668
668
|
|
|
669
|
-
//
|
|
669
|
+
// Add a third proposal for same slot
|
|
670
670
|
const proposal3 = await mockCheckpointProposalCoreForPool(signers[2], slotNumber);
|
|
671
671
|
const result3 = await ap.tryAddCheckpointProposal(proposal3);
|
|
672
672
|
|
|
673
|
-
expect(result3.added).toBe(
|
|
674
|
-
expect(result3.count).toBe(
|
|
673
|
+
expect(result3.added).toBe(true);
|
|
674
|
+
expect(result3.count).toBe(3);
|
|
675
675
|
});
|
|
676
676
|
|
|
677
677
|
it('should not count attestations as proposals for duplicate detection', async () => {
|
package/src/mem_pools/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { AttestationPool, type AttestationPoolApi } from './attestation_pool/attestation_pool.js';
|
|
2
2
|
export { type MemPools } from './interface.js';
|
|
3
|
+
// Old TxPool exports - kept temporarily for external consumers
|
|
4
|
+
export { type TxPool } from './tx_pool/tx_pool.js';
|
|
5
|
+
// New TxPoolV2 exports
|
|
3
6
|
export { type TxPoolV2, type TxPoolV2Config, type TxPoolV2Events, type AddTxsResult } from './tx_pool_v2/index.js';
|
|
@@ -73,7 +73,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
73
73
|
private defaultAttributes;
|
|
74
74
|
private meter: Meter;
|
|
75
75
|
|
|
76
|
-
private
|
|
76
|
+
private txAddedTimestamp: Map<bigint, number> = new Map<bigint, number>();
|
|
77
77
|
|
|
78
78
|
constructor(
|
|
79
79
|
telemetry: TelemetryClient,
|
|
@@ -114,26 +114,22 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
public transactionsAdded(transactions: Tx[]) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
|
|
121
|
-
for (const hash of hashes) {
|
|
122
|
-
this.trackMempoolItemRemoved(BigInt(hash));
|
|
117
|
+
const timestamp = Date.now();
|
|
118
|
+
for (const transaction of transactions) {
|
|
119
|
+
this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
122
|
|
|
126
|
-
public
|
|
127
|
-
this.mempoolItemAddedTimestamp.set(key, Date.now());
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public trackMempoolItemRemoved(key: bigint | string): void {
|
|
123
|
+
public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
|
|
131
124
|
const timestamp = Date.now();
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
this.
|
|
135
|
-
if (addedAt
|
|
136
|
-
this.
|
|
125
|
+
for (const hash of hashes) {
|
|
126
|
+
const key = BigInt(hash);
|
|
127
|
+
const addedAt = this.txAddedTimestamp.get(key);
|
|
128
|
+
if (addedAt !== undefined) {
|
|
129
|
+
this.txAddedTimestamp.delete(key);
|
|
130
|
+
if (addedAt < timestamp) {
|
|
131
|
+
this.minedDelay.record(timestamp - addedAt);
|
|
132
|
+
}
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
135
|
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Transaction Pool (Mempool)
|
|
2
|
+
|
|
3
|
+
This module implements the transaction pool (mempool) for the Aztec P2P network. The mempool holds unconfirmed transactions awaiting inclusion in a block.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The transaction pool serves as a staging area for transactions before they are included in blocks. It manages the lifecycle of transactions from initial submission through mining, handling duplicates, priority ordering, and eviction of invalid or low-priority transactions.
|
|
8
|
+
|
|
9
|
+
## Interface: `TxPool`
|
|
10
|
+
|
|
11
|
+
The [`TxPool`](tx_pool.ts) interface defines the contract that all transaction pool implementations must fulfill:
|
|
12
|
+
|
|
13
|
+
### Transaction Lifecycle
|
|
14
|
+
|
|
15
|
+
The lifecycle of transactions in the pool is summarised in the following table:
|
|
16
|
+
|
|
17
|
+
| State | Meaning | Possible Future States |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| Pending | Available to be added to a block, can be evicted | Protected, Mined, Soft Deleted |
|
|
20
|
+
| Protected | Added to a proposal, must not be evicted | Mined, Pending |
|
|
21
|
+
| Mined | Confirmed as added to a block | Soft Deleted, Pending |
|
|
22
|
+
| Soft Deleted | Awaiting full deletion once state has been finalised on L1 | Pending, Deleted |
|
|
23
|
+
| Deleted | Removed from the pool | N/A |
|
|
24
|
+
|
|
25
|
+
**Note on why Soft Delete:**
|
|
26
|
+
Mined transactions are soft-deleted rather than permanently removed to support:
|
|
27
|
+
1. Reorg handling — If a chain reorganization occurs, soft-deleted transactions are still available in the mempool
|
|
28
|
+
2. Slash condition detection — The epoch prune watcher needs access to transactions from pruned epochs to correctly identify data withholding slash conditions. Without soft-delete, transactions invalidated by reorgs (e.g., built on removed blocks) would be lost, causing false positives for data withholding violations.
|
|
29
|
+
|
|
30
|
+
Mined transactions are permanently deleted via `cleanupDeletedMinedTxs()` once their original block is finalized on L1, ensuring theyremain available during the uncertainty window.
|
|
31
|
+
Alternatively, mined transactions can be permanently deleted immediately by passing the `permanent: true` option to `deleteTxs()`.
|
|
32
|
+
|
|
33
|
+
#### Transaction Lifecycle Methods
|
|
34
|
+
|
|
35
|
+
| Method | Description |
|
|
36
|
+
|--------|-------------|
|
|
37
|
+
| `addTxs(txs, opts?)` | Adds transactions to the pool. Duplicates and nullifier conflicts are handled. Returns count of newly added txs. |
|
|
38
|
+
| `deleteTxs(txHashes, opts?)` | Removes transactions from the pool. Supports soft-delete for mined txs. |
|
|
39
|
+
| `markAsMined(txHashes, blockHeader)` | Marks transactions as included in a block. |
|
|
40
|
+
| `markMinedAsPending(txHashes, blockNumber)` | Reverts mined transactions to pending (used during reorgs). |
|
|
41
|
+
| `getArchivedTxByHash(txHash)` | Retrieves archived (historical) transactions. |
|
|
42
|
+
| `getTxStatus(txHash)` | Returns status: `'pending'`, `'mined'`, `'deleted'`, or `undefined`. |
|
|
43
|
+
|
|
44
|
+
### Transaction Fetching
|
|
45
|
+
|
|
46
|
+
| Method | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `hasTx(txHash)` / `hasTxs(txHashes)` | Checks if transaction(s) exist in the pool. |
|
|
49
|
+
| `getTxByHash(txHash)` | Retrieves a transaction by its hash. |
|
|
50
|
+
| `getTxsByHash(txHashes)` | Batch retrieval of transactions by hash. |
|
|
51
|
+
| `getAllTxs()` / `getAllTxHashes()` | Returns all transactions or their hashes. |
|
|
52
|
+
| `getPendingTxHashes()` | Returns pending tx hashes **sorted by priority** (highest first). |
|
|
53
|
+
| `getPendingTxCount()` | Returns count of pending transactions. |
|
|
54
|
+
| `getMinedTxHashes()` | Returns mined tx hashes with their block numbers. |
|
|
55
|
+
|
|
56
|
+
### Pool Management
|
|
57
|
+
|
|
58
|
+
| Method | Description |
|
|
59
|
+
|--------|-------------|
|
|
60
|
+
| `updateConfig(config)` | Updates pool configuration (max size, archive limit). |
|
|
61
|
+
| `markTxsAsNonEvictable(txHashes)` | Protects transactions from eviction. |
|
|
62
|
+
| `clearNonEvictableTxs()` | Clears non-evictable flag from all transactions. |
|
|
63
|
+
| `cleanupDeletedMinedTxs(blockNumber)` | Permanently removes soft-deleted txs from blocks ≤ blockNumber. |
|
|
64
|
+
| `isEmpty()` | Checks if the pool has no transactions. |
|
|
65
|
+
|
|
66
|
+
### Events
|
|
67
|
+
|
|
68
|
+
The pool emits a `txs-added` event when new transactions are successfully added, allowing subscribers to react to pool changes.
|
|
69
|
+
|
|
70
|
+
## `AztecKVTxPool`
|
|
71
|
+
|
|
72
|
+
The [`AztecKVTxPool`](aztec_kv_tx_pool.ts) is the production-grade implementation backed by a persistent key-value store. It provides:
|
|
73
|
+
|
|
74
|
+
- **Persistent storage** via `AztecAsyncKVStore`
|
|
75
|
+
- **Multiple indexes** for efficient queries
|
|
76
|
+
- **Automatic eviction** of invalid and low-priority transactions
|
|
77
|
+
- **Transaction archival** for historical lookups
|
|
78
|
+
- **Soft-delete semantics** for mined transactions
|
|
79
|
+
|
|
80
|
+
#### Storage Structure
|
|
81
|
+
|
|
82
|
+
The pool maintains several KV maps and indexes:
|
|
83
|
+
|
|
84
|
+
| Store | Purpose |
|
|
85
|
+
|-------|---------|
|
|
86
|
+
| `#txs` | Primary storage: tx hash → serialized tx buffer |
|
|
87
|
+
| `#minedTxHashToBlock` | Index of mined txs: tx hash → block number |
|
|
88
|
+
| `#pendingTxPriorityToHash` | Priority-ordered index of pending txs |
|
|
89
|
+
| `#deletedMinedTxHashes` | Soft-deleted mined txs: tx hash → original block number |
|
|
90
|
+
| `#blockToDeletedMinedTxHash` | Reverse index for cleanup: block → deleted tx hashes |
|
|
91
|
+
| `#txHashToHistoricalBlockHeaderHash` | Anchor block reference for each tx |
|
|
92
|
+
| `#historicalHeaderToTxHash` | Index from historical block → tx hashes |
|
|
93
|
+
| `#feePayerToTxHash` | Index from fee payer address → tx hashes |
|
|
94
|
+
| `#pendingNullifierToTxHash` | Index from nullifier → tx hash |
|
|
95
|
+
| `#archivedTxs` | Archived transactions for historical lookup |
|
|
96
|
+
|
|
97
|
+
#### In-Memory Caches
|
|
98
|
+
|
|
99
|
+
| Cache | Purpose |
|
|
100
|
+
|-------|---------|
|
|
101
|
+
| `#pendingTxs` | Hydrated pending transactions for fast access |
|
|
102
|
+
| `#nonEvictableTxs` | Set of tx hashes protected from eviction |
|
|
103
|
+
|
|
104
|
+
## Transaction Priority
|
|
105
|
+
|
|
106
|
+
Transactions are prioritized based on their **total priority fees** (see [`priority.ts`](priority.ts)):
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
priorityFee = maxPriorityFeesPerGas.feePerDaGas + maxPriorityFeesPerGas.feePerL2Gas
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The priority is stored as a hex string derived from a 32-byte buffer representation of the fee amount, enabling lexicographic ordering in the KV store. Pending transactions are returned in **descending priority order** (highest fees first).
|
|
113
|
+
|
|
114
|
+
## Transaction Lifecycle in AztecKVTxPool
|
|
115
|
+
|
|
116
|
+
### 1. Adding Transactions
|
|
117
|
+
|
|
118
|
+
When `addTxs()` is called:
|
|
119
|
+
|
|
120
|
+
1. Check for duplicates (skip if tx already exists)
|
|
121
|
+
2. Check for nullifier conflicts (see Nullifier Deduplication below)
|
|
122
|
+
3. Store the serialized tx in `#txs`
|
|
123
|
+
4. Index the tx by its anchor block hash
|
|
124
|
+
5. If not already mined, add to pending indexes:
|
|
125
|
+
- Priority-to-hash index (for ordering)
|
|
126
|
+
- Historical header index (for reorg handling)
|
|
127
|
+
- Fee payer index (for balance validation)
|
|
128
|
+
- Nullifier-to-tx-hash index (for conflict detection)
|
|
129
|
+
6. Record metrics
|
|
130
|
+
7. Trigger eviction rules for `TXS_ADDED` event
|
|
131
|
+
8. Emit `txs-added` event
|
|
132
|
+
|
|
133
|
+
### 2. Marking as Mined
|
|
134
|
+
|
|
135
|
+
When a block is finalized, `markAsMined()`:
|
|
136
|
+
|
|
137
|
+
1. Move tx from pending to mined status
|
|
138
|
+
2. If previously soft-deleted, restore to mined status
|
|
139
|
+
3. Trigger eviction rules for `BLOCK_MINED` event
|
|
140
|
+
|
|
141
|
+
### 3. Handling Reorgs
|
|
142
|
+
|
|
143
|
+
When blocks are pruned, `markMinedAsPending()`:
|
|
144
|
+
|
|
145
|
+
1. Remove tx from mined index
|
|
146
|
+
2. Rehydrate pending indexes
|
|
147
|
+
3. Trigger eviction rules for `CHAIN_PRUNED` event
|
|
148
|
+
|
|
149
|
+
### 4. Deleting Transactions
|
|
150
|
+
|
|
151
|
+
The `deleteTxs()` method handles two cases:
|
|
152
|
+
|
|
153
|
+
- **Pending transactions**: Permanently deleted (transactions and all indexes to the transaction)
|
|
154
|
+
- **Mined transactions**: Soft-deleted by default (moved to `#deletedMinedTxHashes`), with option for permanent deletion
|
|
155
|
+
|
|
156
|
+
Soft-deleted mined transactions are retained for potential future reference and can be permanently cleaned up later via `cleanupDeletedMinedTxs()`.
|
|
157
|
+
|
|
158
|
+
### Nullifier Deduplication
|
|
159
|
+
|
|
160
|
+
The pool prevents nullifier spam attacks by ensuring only one pending transaction can reference each unique nullifier. When an incoming transaction shares nullifiers with existing pending transactions:
|
|
161
|
+
|
|
162
|
+
- **Higher fee wins**: If the incoming tx has a higher priority fee than ALL conflicting txs, those conflicting txs are replaced
|
|
163
|
+
- **Existing tx wins on tie**: If any conflicting tx has an equal or higher fee, the incoming tx is rejected
|
|
164
|
+
- **Partial overlap counts**: Even a single shared nullifier triggers conflict resolution
|
|
165
|
+
|
|
166
|
+
This is enforced at entry time via the `#pendingNullifierToTxHash` index, which maps each nullifier to the tx hash that references it. The index is maintained atomically with tx additions and removals.
|
|
167
|
+
|
|
168
|
+
## Eviction System
|
|
169
|
+
|
|
170
|
+
The eviction system automatically removes invalid or low-priority transactions based on configurable rules. See the [`eviction/`](eviction/) subdirectory for implementation details.
|
|
171
|
+
|
|
172
|
+
### Architecture
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
176
|
+
│ EvictionManager │
|
|
177
|
+
│ Orchestrates eviction rules based on pool events │
|
|
178
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
179
|
+
│ │
|
|
180
|
+
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
|
|
181
|
+
│ │EvictionRule #1 │ │EvictionRule #2 │ │EvictionRule #N │ │
|
|
182
|
+
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
|
|
183
|
+
│ │
|
|
184
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
185
|
+
│
|
|
186
|
+
▼
|
|
187
|
+
┌─────────────────┐
|
|
188
|
+
│ TxPoolOperations│
|
|
189
|
+
│ (interface) │
|
|
190
|
+
└─────────────────┘
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The [`EvictionManager`](eviction/eviction_manager.ts) coordinates eviction by:
|
|
194
|
+
|
|
195
|
+
1. Registering multiple `EvictionRule` implementations
|
|
196
|
+
2. Calling each rule when tx pool events occur
|
|
197
|
+
3. Propagating configuration updates to all rules
|
|
198
|
+
|
|
199
|
+
### Eviction Events
|
|
200
|
+
|
|
201
|
+
| Event | Trigger | Purpose |
|
|
202
|
+
|-------|---------|---------|
|
|
203
|
+
| `TXS_ADDED` | New transactions added | Enforce pool size limits |
|
|
204
|
+
| `BLOCK_MINED` | Block finalized | Remove invalidated transactions |
|
|
205
|
+
| `CHAIN_PRUNED` | Chain reorganization | Remove txs referencing pruned blocks and re-evaluate fee payer balances |
|
|
206
|
+
|
|
207
|
+
### Eviction Rules
|
|
208
|
+
|
|
209
|
+
#### 1. `InvalidTxsAfterMiningRule`
|
|
210
|
+
|
|
211
|
+
**Triggers on:** `BLOCK_MINED`
|
|
212
|
+
|
|
213
|
+
Evicts transactions that become invalid after a block is mined:
|
|
214
|
+
|
|
215
|
+
- Duplicate nullifiers: Txs with nullifiers already included in the mined block
|
|
216
|
+
- Expired transactions: Txs with `expirationTimestamp` ≤ mined block timestamp
|
|
217
|
+
|
|
218
|
+
#### 2. `InvalidTxsAfterReorgRule`
|
|
219
|
+
|
|
220
|
+
**Triggers on:** `CHAIN_PRUNED`
|
|
221
|
+
|
|
222
|
+
Evicts transactions that reference blocks no longer in the canonical chain:
|
|
223
|
+
|
|
224
|
+
- Checks each pending tx's anchor block hash against the archive tree
|
|
225
|
+
- Removes txs whose anchor blocks are not found (pruned)
|
|
226
|
+
|
|
227
|
+
#### 3. `FeePayerBalanceEvictionRule`
|
|
228
|
+
|
|
229
|
+
**Triggers on:** `TXS_ADDED`, `BLOCK_MINED`, `CHAIN_PRUNED`
|
|
230
|
+
|
|
231
|
+
Evicts low-priority transactions when a fee payer's pending fee limits exceed their Fee Juice balance:
|
|
232
|
+
|
|
233
|
+
- Evaluates transactions in priority order so higher-priority claims can fund lower-priority spends
|
|
234
|
+
- Accounts for self-funding claims made during setup
|
|
235
|
+
- Removes evictable txs that do not fit within the running balance
|
|
236
|
+
|
|
237
|
+
#### 4. `LowPriorityEvictionRule`
|
|
238
|
+
|
|
239
|
+
**Triggers on:** `TXS_ADDED`
|
|
240
|
+
|
|
241
|
+
Enforces maximum pool size by evicting lowest-priority (by fee) transactions:
|
|
242
|
+
|
|
243
|
+
- Configured via `maxPendingTxCount` option (0 = disabled)
|
|
244
|
+
- Uses `getLowestPriorityEvictable()` to find txs to evict
|
|
245
|
+
|
|
246
|
+
### Non-Evictable Transactions
|
|
247
|
+
|
|
248
|
+
Transactions can be marked as non-evictable via `markTxsAsNonEvictable()`. This protects them from all eviction rules, typically used during block building to ensure transactions being processed aren't evicted mid-operation. The flag is cleared after block processing via `clearNonEvictableTxs()`.
|
|
249
|
+
The `clearNonEvictableTxs` is called upon getting new L2 block.
|
|
250
|
+
|
|
251
|
+
## Configuration
|
|
252
|
+
|
|
253
|
+
The pool accepts configuration via `TxPoolOptions`:
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
type TxPoolOptions = {
|
|
257
|
+
maxPendingTxCount?: number; // Max pending txs (0 = unlimited)
|
|
258
|
+
archivedTxLimit?: number; // Number of archived txs to retain
|
|
259
|
+
};
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Configuration can be updated at runtime via `updateConfig()`.
|
|
263
|
+
|
|
264
|
+
## Telemetry
|
|
265
|
+
|
|
266
|
+
The pool integrates with the telemetry system to report:
|
|
267
|
+
|
|
268
|
+
- Transaction counts (pending vs mined)
|
|
269
|
+
- Transaction sizes
|
|
270
|
+
- Store size estimates
|