@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.7b97ef96e
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 +7 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +46 -11
- package/dest/client/interface.d.ts +43 -23
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +38 -42
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +145 -145
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -6
- package/dest/config.d.ts +23 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -1
- 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/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 +104 -88
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- 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/index.d.ts +3 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/interface.d.ts +5 -5
- package/dest/mem_pools/interface.d.ts.map +1 -1
- 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 +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -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.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +4 -1
- 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 +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -3
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +1 -1
- 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 +8 -4
- 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/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -0
- 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 +16 -4
- 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 +31 -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 +62 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
- 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 +27 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +8 -3
- 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 +11 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +12 -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 +239 -109
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- 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 +12 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +9 -0
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +4 -3
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +346 -0
- package/dest/services/libp2p/libp2p_service.d.ts +85 -35
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +370 -267
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +25 -2
- 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/reqresp/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
- 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 +15 -0
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- 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 +11 -4
- package/dest/services/service.d.ts +38 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +19 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +46 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +56 -36
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +90 -0
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- 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 +7 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +60 -26
- package/dest/services/tx_collection/tx_collection.d.ts +23 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +75 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +26 -29
- 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/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +9 -6
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +5 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +29 -2
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +103 -2
- 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/reqresp-nodes.js +2 -1
- package/dest/test-helpers/testbench-utils.d.ts +43 -38
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +128 -59
- 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 +10 -10
- 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 +86 -15
- package/src/client/interface.ts +59 -23
- package/src/client/p2p_client.ts +184 -167
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
- package/src/config.ts +34 -2
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +496 -91
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/index.ts +4 -1
- package/src/mem_pools/interface.ts +4 -4
- 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 +76 -10
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -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 +4 -1
- 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 +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +8 -7
- 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/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +16 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +90 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +32 -5
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +17 -6
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +274 -104
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +17 -1
- package/src/services/encoding.ts +4 -3
- package/src/services/gossipsub/README.md +641 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +487 -0
- package/src/services/libp2p/libp2p_service.ts +367 -271
- package/src/services/peer-manager/peer_scoring.ts +25 -0
- 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/reqresp/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +13 -3
- package/src/services/service.ts +50 -1
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +65 -32
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +1 -0
- 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 +66 -33
- package/src/services/tx_collection/tx_collection.ts +113 -16
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +10 -8
- package/src/services/tx_provider.ts +8 -7
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +143 -3
- package/src/test-helpers/reqresp-nodes.ts +2 -1
- package/src/test-helpers/testbench-utils.ts +127 -71
- package/src/testbench/p2p_client_testbench_worker.ts +22 -15
- package/src/util.ts +7 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
|
@@ -67,6 +67,42 @@ export interface PreAddPoolAccess {
|
|
|
67
67
|
getLowestPriorityPendingTx(): TxMetaData | undefined;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/** A single eviction tagged with the rule that caused it. */
|
|
71
|
+
export interface TaggedEviction {
|
|
72
|
+
readonly txHash: string;
|
|
73
|
+
readonly reason: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Machine-readable rejection codes for pre-add rule rejections.
|
|
78
|
+
*/
|
|
79
|
+
export const TxPoolRejectionCode = {
|
|
80
|
+
LOW_PRIORITY_FEE: 'LOW_PRIORITY_FEE',
|
|
81
|
+
INSUFFICIENT_FEE_PAYER_BALANCE: 'INSUFFICIENT_FEE_PAYER_BALANCE',
|
|
82
|
+
NULLIFIER_CONFLICT: 'NULLIFIER_CONFLICT',
|
|
83
|
+
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
84
|
+
} as const;
|
|
85
|
+
|
|
86
|
+
export type TxPoolRejectionCode = (typeof TxPoolRejectionCode)[keyof typeof TxPoolRejectionCode];
|
|
87
|
+
|
|
88
|
+
/** Structured rejection reason returned by pre-add rules. */
|
|
89
|
+
export type TxPoolRejectionError =
|
|
90
|
+
| {
|
|
91
|
+
code: typeof TxPoolRejectionCode.LOW_PRIORITY_FEE;
|
|
92
|
+
message: string;
|
|
93
|
+
minimumPriorityFee: bigint;
|
|
94
|
+
txPriorityFee: bigint;
|
|
95
|
+
}
|
|
96
|
+
| {
|
|
97
|
+
code: typeof TxPoolRejectionCode.INSUFFICIENT_FEE_PAYER_BALANCE;
|
|
98
|
+
message: string;
|
|
99
|
+
currentBalance: bigint;
|
|
100
|
+
availableBalance: bigint;
|
|
101
|
+
feeLimit: bigint;
|
|
102
|
+
}
|
|
103
|
+
| { code: typeof TxPoolRejectionCode.NULLIFIER_CONFLICT; message: string; conflictingTxHash: string }
|
|
104
|
+
| { code: typeof TxPoolRejectionCode.INTERNAL_ERROR; message: string };
|
|
105
|
+
|
|
70
106
|
/**
|
|
71
107
|
* Result of a pre-add check for a single transaction.
|
|
72
108
|
*/
|
|
@@ -75,8 +111,16 @@ export interface PreAddResult {
|
|
|
75
111
|
readonly shouldIgnore: boolean;
|
|
76
112
|
/** Tx hashes (as strings) that should be evicted if this tx is added */
|
|
77
113
|
readonly txHashesToEvict: string[];
|
|
114
|
+
/** Evictions tagged with the rule name that produced them. Populated by EvictionManager. */
|
|
115
|
+
readonly evictions?: TaggedEviction[];
|
|
78
116
|
/** Optional reason for ignoring */
|
|
79
|
-
readonly reason?:
|
|
117
|
+
readonly reason?: TxPoolRejectionError;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Context passed to pre-add rules from addPendingTxs. */
|
|
121
|
+
export interface PreAddContext {
|
|
122
|
+
/** If true, compare priority fee only (no tx hash tiebreaker). Used for RPC submissions. */
|
|
123
|
+
feeComparisonOnly?: boolean;
|
|
80
124
|
}
|
|
81
125
|
|
|
82
126
|
/**
|
|
@@ -90,9 +134,10 @@ export interface PreAddRule {
|
|
|
90
134
|
* Check if incoming tx should be added and which existing txs to evict.
|
|
91
135
|
* @param incomingMeta - Metadata for the incoming transaction
|
|
92
136
|
* @param poolAccess - Read-only access to current pool state
|
|
137
|
+
* @param context - Optional context from addPendingTxs caller
|
|
93
138
|
* @returns Result indicating whether to ignore and what to evict
|
|
94
139
|
*/
|
|
95
|
-
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult>;
|
|
140
|
+
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, context?: PreAddContext): Promise<PreAddResult>;
|
|
96
141
|
|
|
97
142
|
/**
|
|
98
143
|
* Updates the configuration for this rule.
|
|
@@ -120,8 +165,8 @@ export interface PoolOperations {
|
|
|
120
165
|
/** Get the N lowest priority pending tx hashes */
|
|
121
166
|
getLowestPriorityPending(limit: number): string[];
|
|
122
167
|
|
|
123
|
-
/** Delete transactions by hash */
|
|
124
|
-
deleteTxs(txHashes: string[]): Promise<void>;
|
|
168
|
+
/** Delete transactions by hash, with an optional reason for metrics */
|
|
169
|
+
deleteTxs(txHashes: string[], reason?: string): Promise<void>;
|
|
125
170
|
}
|
|
126
171
|
|
|
127
172
|
/**
|
|
@@ -35,15 +35,14 @@ export class InvalidTxsAfterMiningRule implements EvictionRule {
|
|
|
35
35
|
for (const meta of pendingTxs) {
|
|
36
36
|
// Evict pending txs that share nullifiers with mined txs
|
|
37
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
38
|
txsToEvict.push(meta.txHash);
|
|
40
39
|
continue;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
// Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
|
|
44
|
-
if (meta.
|
|
43
|
+
if (meta.expirationTimestamp <= timestamp) {
|
|
45
44
|
this.log.verbose(
|
|
46
|
-
`Evicting tx ${meta.txHash} from pool due to the tx being expired (
|
|
45
|
+
`Evicting tx ${meta.txHash} from pool due to the tx being expired (expirationTimestamp: ${meta.expirationTimestamp}, mined block timestamp: ${timestamp})`,
|
|
47
46
|
);
|
|
48
47
|
txsToEvict.push(meta.txHash);
|
|
49
48
|
continue;
|
|
@@ -51,10 +50,11 @@ export class InvalidTxsAfterMiningRule implements EvictionRule {
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
if (txsToEvict.length > 0) {
|
|
54
|
-
|
|
53
|
+
this.log.info(`Evicted ${txsToEvict.length} invalid txs after block mined`);
|
|
54
|
+
await pool.deleteTxs(txsToEvict, this.name);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
this.log.debug(`Evicted ${txsToEvict.length} invalid txs after block mined
|
|
57
|
+
this.log.debug(`Evicted ${txsToEvict.length} invalid txs after block mined`, { txHashes: txsToEvict });
|
|
58
58
|
|
|
59
59
|
return {
|
|
60
60
|
reason: 'block_mined_invalid_txs',
|
|
@@ -72,8 +72,8 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
if (txsToEvict.length > 0) {
|
|
75
|
-
this.log.
|
|
76
|
-
await pool.deleteTxs(txsToEvict);
|
|
75
|
+
this.log.info(`Evicting ${txsToEvict.length} txs from pool due to referencing pruned blocks`);
|
|
76
|
+
await pool.deleteTxs(txsToEvict, this.name);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const keptCount = pendingTxs.length - txsToEvict.length;
|
|
@@ -81,7 +81,7 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
|
|
|
81
81
|
this.log.verbose(`Kept ${keptCount} txs that did not reference pruned blocks`);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
this.log.debug(`Evicted ${txsToEvict.length} invalid txs after reorg
|
|
84
|
+
this.log.debug(`Evicted ${txsToEvict.length} invalid txs after reorg`, { txHashes: txsToEvict });
|
|
85
85
|
|
|
86
86
|
return {
|
|
87
87
|
reason: 'reorg_invalid_txs',
|
|
@@ -48,19 +48,20 @@ export class LowPriorityEvictionRule implements EvictionRule {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
this.log.
|
|
52
|
-
`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${this.maxPoolSize}`,
|
|
53
|
-
);
|
|
51
|
+
this.log.info(`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${this.maxPoolSize}`);
|
|
54
52
|
const numberToEvict = currentTxCount - this.maxPoolSize;
|
|
55
53
|
const txsToEvict = pool.getLowestPriorityPending(numberToEvict);
|
|
54
|
+
const toEvictSet = new Set(txsToEvict);
|
|
55
|
+
const numNewTxsEvicted = context.newTxHashes.filter(newTxHash => toEvictSet.has(newTxHash)).length;
|
|
56
56
|
|
|
57
57
|
if (txsToEvict.length > 0) {
|
|
58
|
-
|
|
58
|
+
this.log.info(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`);
|
|
59
|
+
await pool.deleteTxs(txsToEvict, this.name);
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
this.log.debug(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`, {
|
|
63
|
+
txHashes: txsToEvict,
|
|
64
|
+
});
|
|
64
65
|
|
|
65
66
|
return {
|
|
66
67
|
reason: 'low_priority',
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
|
-
import type
|
|
4
|
-
import
|
|
3
|
+
import { type TxMetaData, comparePriority } from '../tx_metadata.js';
|
|
4
|
+
import {
|
|
5
|
+
type EvictionConfig,
|
|
6
|
+
type PreAddContext,
|
|
7
|
+
type PreAddPoolAccess,
|
|
8
|
+
type PreAddResult,
|
|
9
|
+
type PreAddRule,
|
|
10
|
+
TxPoolRejectionCode,
|
|
11
|
+
} from './interfaces.js';
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* Pre-add rule that checks if the pool is at capacity and handles low-priority eviction.
|
|
@@ -20,7 +27,7 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
20
27
|
this.maxPoolSize = config.maxPoolSize;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
|
|
30
|
+
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, context?: PreAddContext): Promise<PreAddResult> {
|
|
24
31
|
// Skip if max pool size is disabled (0 = unlimited)
|
|
25
32
|
if (this.maxPoolSize === 0) {
|
|
26
33
|
return Promise.resolve({ shouldIgnore: false, txHashesToEvict: [] });
|
|
@@ -40,8 +47,14 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
40
47
|
return Promise.resolve({ shouldIgnore: false, txHashesToEvict: [] });
|
|
41
48
|
}
|
|
42
49
|
|
|
43
|
-
//
|
|
44
|
-
|
|
50
|
+
// Compare incoming tx against lowest priority tx.
|
|
51
|
+
// feeOnly mode (RPC): use strict fee comparison only — avoids churn from hash ordering
|
|
52
|
+
// Default (gossip): use full comparePriority (fee + tx hash tiebreaker) for determinism
|
|
53
|
+
const isHigherPriority = context?.feeComparisonOnly
|
|
54
|
+
? incomingMeta.priorityFee > lowestPriorityMeta.priorityFee
|
|
55
|
+
: comparePriority(incomingMeta, lowestPriorityMeta) > 0;
|
|
56
|
+
|
|
57
|
+
if (isHigherPriority) {
|
|
45
58
|
this.log.debug(
|
|
46
59
|
`Pool at capacity (${currentCount}/${this.maxPoolSize}), evicting ${lowestPriorityMeta.txHash} ` +
|
|
47
60
|
`(priority ${lowestPriorityMeta.priorityFee}) for ${incomingMeta.txHash} (priority ${incomingMeta.priorityFee})`,
|
|
@@ -60,7 +73,12 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
60
73
|
return Promise.resolve({
|
|
61
74
|
shouldIgnore: true,
|
|
62
75
|
txHashesToEvict: [],
|
|
63
|
-
reason:
|
|
76
|
+
reason: {
|
|
77
|
+
code: TxPoolRejectionCode.LOW_PRIORITY_FEE,
|
|
78
|
+
message: `Tx does not meet minimum priority fee. Required: ${lowestPriorityMeta.priorityFee + 1n}, got: ${incomingMeta.priorityFee}`,
|
|
79
|
+
minimumPriorityFee: lowestPriorityMeta.priorityFee + 1n,
|
|
80
|
+
txPriorityFee: incomingMeta.priorityFee,
|
|
81
|
+
},
|
|
64
82
|
});
|
|
65
83
|
}
|
|
66
84
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
3
|
import { type TxMetaData, checkNullifierConflict } from '../tx_metadata.js';
|
|
4
|
-
import type { PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
|
|
4
|
+
import type { PreAddContext, PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Pre-add rule that checks for nullifier conflicts between incoming and existing transactions.
|
|
@@ -15,7 +15,7 @@ export class NullifierConflictRule implements PreAddRule {
|
|
|
15
15
|
|
|
16
16
|
private log = createLogger('p2p:tx_pool_v2:nullifier_conflict_rule');
|
|
17
17
|
|
|
18
|
-
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
|
|
18
|
+
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, _context?: PreAddContext): Promise<PreAddResult> {
|
|
19
19
|
const result = checkNullifierConflict(
|
|
20
20
|
incomingMeta,
|
|
21
21
|
nullifier => poolAccess.getTxHashByNullifier(nullifier),
|
|
@@ -23,7 +23,7 @@ export class NullifierConflictRule implements PreAddRule {
|
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
if (result.shouldIgnore) {
|
|
26
|
-
this.log.debug(`Ignoring tx ${incomingMeta.txHash}: ${result.reason}`);
|
|
26
|
+
this.log.debug(`Ignoring tx ${incomingMeta.txHash}: ${result.reason?.message}`);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
return Promise.resolve(result);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Attributes,
|
|
3
|
+
type Meter,
|
|
4
|
+
Metrics,
|
|
5
|
+
type ObservableGauge,
|
|
6
|
+
type ObservableResult,
|
|
7
|
+
type TelemetryClient,
|
|
8
|
+
type UpDownCounter,
|
|
9
|
+
createUpDownCounterWithDefault,
|
|
10
|
+
} from '@aztec/telemetry-client';
|
|
11
|
+
|
|
12
|
+
/** Callback that returns the current estimated metadata memory in bytes. */
|
|
13
|
+
export type MetadataMemoryCallback = () => number;
|
|
14
|
+
|
|
15
|
+
/** Instrumentation for TxPoolV2Impl internal operations. */
|
|
16
|
+
export class TxPoolV2Instrumentation {
|
|
17
|
+
#evictedCounter: UpDownCounter;
|
|
18
|
+
#ignoredCounter: UpDownCounter;
|
|
19
|
+
#rejectedCounter: UpDownCounter;
|
|
20
|
+
#softDeletedHitsCounter: UpDownCounter;
|
|
21
|
+
#missingOnProtectCounter: UpDownCounter;
|
|
22
|
+
#missingPreviouslyEvictedCounter: UpDownCounter;
|
|
23
|
+
#metadataMemoryGauge: ObservableGauge;
|
|
24
|
+
|
|
25
|
+
constructor(telemetry: TelemetryClient, metadataMemoryCallback: MetadataMemoryCallback) {
|
|
26
|
+
const meter: Meter = telemetry.getMeter('TxPoolV2Impl');
|
|
27
|
+
|
|
28
|
+
this.#evictedCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_EVICTED_COUNT);
|
|
29
|
+
this.#ignoredCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_IGNORED_COUNT);
|
|
30
|
+
this.#rejectedCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_REJECTED_COUNT);
|
|
31
|
+
this.#softDeletedHitsCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_SOFT_DELETED_HITS);
|
|
32
|
+
this.#missingOnProtectCounter = createUpDownCounterWithDefault(
|
|
33
|
+
meter,
|
|
34
|
+
Metrics.MEMPOOL_TX_POOL_V2_MISSING_ON_PROTECT,
|
|
35
|
+
);
|
|
36
|
+
this.#missingPreviouslyEvictedCounter = createUpDownCounterWithDefault(
|
|
37
|
+
meter,
|
|
38
|
+
Metrics.MEMPOOL_TX_POOL_V2_MISSING_PREVIOUSLY_EVICTED,
|
|
39
|
+
);
|
|
40
|
+
this.#metadataMemoryGauge = meter.createObservableGauge(Metrics.MEMPOOL_TX_POOL_V2_METADATA_MEMORY);
|
|
41
|
+
this.#metadataMemoryGauge.addCallback((result: ObservableResult) => {
|
|
42
|
+
result.observe(metadataMemoryCallback());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
recordEvictions(count: number, reason: string) {
|
|
47
|
+
this.#evictedCounter.add(count, { [Attributes.TX_POOL_EVICTION_REASON]: reason });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
recordIgnored(count: number) {
|
|
51
|
+
this.#ignoredCounter.add(count);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
recordRejected(count: number) {
|
|
55
|
+
this.#rejectedCounter.add(count);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
recordSoftDeletedHits(count: number) {
|
|
59
|
+
this.#softDeletedHitsCounter.add(count);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
recordMissingOnProtect(count: number) {
|
|
63
|
+
this.#missingOnProtectCounter.add(count);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
recordMissingPreviouslyEvicted(count: number) {
|
|
67
|
+
this.#missingPreviouslyEvictedCounter.add(count);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -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
|
/**
|
|
@@ -37,6 +40,10 @@ export type TxPoolV2Config = {
|
|
|
37
40
|
maxPendingTxCount: number;
|
|
38
41
|
/** Maximum number of archived transactions to retain (0 = disabled) */
|
|
39
42
|
archivedTxLimit: number;
|
|
43
|
+
/** Minimum age (ms) a transaction must have been in the pool before it's eligible for block building */
|
|
44
|
+
minTxPoolAgeMs: number;
|
|
45
|
+
/** Maximum number of evicted tx hashes to remember for metrics tracking */
|
|
46
|
+
evictedTxCacheSize: number;
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
/**
|
|
@@ -45,6 +52,8 @@ export type TxPoolV2Config = {
|
|
|
45
52
|
export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
|
|
46
53
|
maxPendingTxCount: 0, // 0 = disabled
|
|
47
54
|
archivedTxLimit: 0, // 0 = disabled
|
|
55
|
+
minTxPoolAgeMs: 2_000,
|
|
56
|
+
evictedTxCacheSize: 10_000,
|
|
48
57
|
};
|
|
49
58
|
|
|
50
59
|
/**
|
|
@@ -55,8 +64,8 @@ export type TxPoolV2Dependencies = {
|
|
|
55
64
|
l2BlockSource: L2BlockSource;
|
|
56
65
|
/** World state synchronizer for validating transactions after chain prunes */
|
|
57
66
|
worldStateSynchronizer: WorldStateSynchronizer;
|
|
58
|
-
/**
|
|
59
|
-
|
|
67
|
+
/** Factory that creates a validator for re-validating pool transactions using metadata */
|
|
68
|
+
createTxValidator: () => Promise<TxValidator<TxMetaData>>;
|
|
60
69
|
};
|
|
61
70
|
|
|
62
71
|
/**
|
|
@@ -95,7 +104,7 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
95
104
|
* @param opts - Optional metadata (e.g., source for logging)
|
|
96
105
|
* @returns Result categorizing each transaction as accepted, rejected, or ignored
|
|
97
106
|
*/
|
|
98
|
-
addPendingTxs(txs: Tx[], opts?: { source?: string }): Promise<AddTxsResult>;
|
|
107
|
+
addPendingTxs(txs: Tx[], opts?: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult>;
|
|
99
108
|
|
|
100
109
|
/**
|
|
101
110
|
* Checks if a transaction can be added without modifying the pool.
|
|
@@ -156,7 +165,7 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
156
165
|
* and validates them before returning to pending.
|
|
157
166
|
* @param latestBlock - The latest valid block ID after the prune
|
|
158
167
|
*/
|
|
159
|
-
handlePrunedBlocks(latestBlock: L2BlockId): Promise<void>;
|
|
168
|
+
handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void>;
|
|
160
169
|
|
|
161
170
|
/**
|
|
162
171
|
* Handles failed transaction execution.
|
|
@@ -187,6 +196,9 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
187
196
|
/** Gets pending transaction hashes sorted by priority (highest first) */
|
|
188
197
|
getPendingTxHashes(): Promise<TxHash[]>;
|
|
189
198
|
|
|
199
|
+
/** Gets pending transaction hashes that have been in the pool long enough per minTxPoolAgeMs, sorted by priority (highest first) */
|
|
200
|
+
getEligiblePendingTxHashes(): Promise<TxHash[]>;
|
|
201
|
+
|
|
190
202
|
/** Gets the count of pending transactions */
|
|
191
203
|
getPendingTxCount(): Promise<number>;
|
|
192
204
|
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import type
|
|
4
|
+
import { BlockHash, type L2BlockId } from '@aztec/stdlib/block';
|
|
4
5
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
7
|
import { getFeePayerBalanceDelta } from '../../msg_validators/tx_validator/fee_payer_balance.js';
|
|
7
8
|
import { getTxPriorityFee } from '../tx_pool/priority.js';
|
|
8
|
-
import type
|
|
9
|
+
import { type PreAddResult, TxPoolRejectionCode } from './eviction/interfaces.js';
|
|
10
|
+
|
|
11
|
+
/** Validator-compatible data interface, mirroring the subset of PrivateKernelTailCircuitPublicInputs used by validators. */
|
|
12
|
+
export type TxMetaValidationData = {
|
|
13
|
+
getNonEmptyNullifiers(): Fr[];
|
|
14
|
+
expirationTimestamp: bigint;
|
|
15
|
+
constants: {
|
|
16
|
+
anchorBlockHeader: {
|
|
17
|
+
hash(): Promise<BlockHash>;
|
|
18
|
+
globalVariables: {
|
|
19
|
+
blockNumber: BlockNumber;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
9
24
|
|
|
10
25
|
/**
|
|
11
26
|
* Lightweight in-memory representation of a transaction.
|
|
@@ -41,26 +56,41 @@ export type TxMetaData = {
|
|
|
41
56
|
readonly nullifiers: readonly string[];
|
|
42
57
|
|
|
43
58
|
/** Timestamp by which the transaction must be included (for expiration checks) */
|
|
44
|
-
readonly
|
|
59
|
+
readonly expirationTimestamp: bigint;
|
|
60
|
+
|
|
61
|
+
/** Validator-compatible data, providing the same access patterns as Tx.data */
|
|
62
|
+
readonly data: TxMetaValidationData;
|
|
63
|
+
|
|
64
|
+
/** Timestamp (ms) when the tx was received into the pool. 0 for hydrated txs (always eligible). */
|
|
65
|
+
receivedAt: number;
|
|
66
|
+
|
|
67
|
+
/** Estimated memory footprint of this metadata object in bytes */
|
|
68
|
+
readonly estimatedSizeBytes: number;
|
|
45
69
|
};
|
|
46
70
|
|
|
47
71
|
/** Transaction state derived from TxMetaData fields and pool protection status */
|
|
48
|
-
export type TxState = 'pending' | 'protected' | 'mined';
|
|
72
|
+
export type TxState = 'pending' | 'protected' | 'mined' | 'deleted';
|
|
49
73
|
|
|
50
74
|
/**
|
|
51
75
|
* Builds TxMetaData from a full Tx object.
|
|
52
76
|
* Extracts all relevant fields for efficient in-memory storage and querying.
|
|
77
|
+
* Fr values are captured in closures for zero-cost re-validation.
|
|
53
78
|
*/
|
|
54
79
|
export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
|
|
55
80
|
const txHash = tx.getTxHash().toString();
|
|
56
|
-
const
|
|
81
|
+
const nullifierFrs = tx.data.getNonEmptyNullifiers();
|
|
82
|
+
const nullifiers = nullifierFrs.map(n => n.toString());
|
|
83
|
+
const anchorBlockHeaderHashFr = await tx.data.constants.anchorBlockHeader.hash();
|
|
84
|
+
const anchorBlockHeaderHash = anchorBlockHeaderHashFr.toString();
|
|
85
|
+
const expirationTimestamp = tx.data.expirationTimestamp;
|
|
86
|
+
const anchorBlockNumber = tx.data.constants.anchorBlockHeader.globalVariables.blockNumber;
|
|
57
87
|
const priorityFee = getTxPriorityFee(tx);
|
|
58
88
|
const feePayer = tx.data.feePayer.toString();
|
|
59
|
-
const nullifiers = tx.data.getNonEmptyNullifiers().map(n => n.toString());
|
|
60
|
-
const includeByTimestamp = tx.data.includeByTimestamp;
|
|
61
89
|
|
|
62
90
|
const { feeLimit, claimAmount } = await getFeePayerBalanceDelta(tx, ProtocolContractAddress.FeeJuice);
|
|
63
91
|
|
|
92
|
+
const estimatedSizeBytes = estimateTxMetaDataSize(nullifiers.length);
|
|
93
|
+
|
|
64
94
|
return {
|
|
65
95
|
txHash,
|
|
66
96
|
anchorBlockHeaderHash,
|
|
@@ -69,10 +99,43 @@ export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
|
|
|
69
99
|
claimAmount,
|
|
70
100
|
feeLimit,
|
|
71
101
|
nullifiers,
|
|
72
|
-
|
|
102
|
+
expirationTimestamp,
|
|
103
|
+
receivedAt: 0,
|
|
104
|
+
estimatedSizeBytes,
|
|
105
|
+
data: {
|
|
106
|
+
getNonEmptyNullifiers: () => nullifierFrs,
|
|
107
|
+
expirationTimestamp,
|
|
108
|
+
constants: {
|
|
109
|
+
anchorBlockHeader: {
|
|
110
|
+
hash: () => Promise.resolve(anchorBlockHeaderHashFr),
|
|
111
|
+
globalVariables: { blockNumber: anchorBlockNumber },
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
73
115
|
};
|
|
74
116
|
}
|
|
75
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
|
+
|
|
76
139
|
/** Minimal fields required for priority comparison. */
|
|
77
140
|
type PriorityComparable = Pick<TxMetaData, 'txHash' | 'priorityFee'>;
|
|
78
141
|
|
|
@@ -152,10 +215,28 @@ export function checkNullifierConflict(
|
|
|
152
215
|
return {
|
|
153
216
|
shouldIgnore: true,
|
|
154
217
|
txHashesToEvict: [],
|
|
155
|
-
reason:
|
|
218
|
+
reason: {
|
|
219
|
+
code: TxPoolRejectionCode.NULLIFIER_CONFLICT,
|
|
220
|
+
message: `Nullifier conflict with existing tx ${conflictingHashStr}`,
|
|
221
|
+
conflictingTxHash: conflictingHashStr,
|
|
222
|
+
},
|
|
156
223
|
};
|
|
157
224
|
}
|
|
158
225
|
}
|
|
159
226
|
|
|
160
227
|
return { shouldIgnore: false, txHashesToEvict };
|
|
161
228
|
}
|
|
229
|
+
|
|
230
|
+
/** Creates a stub TxMetaValidationData for tests that don't exercise validators. */
|
|
231
|
+
export function stubTxMetaValidationData(overrides: { expirationTimestamp?: bigint } = {}): TxMetaValidationData {
|
|
232
|
+
return {
|
|
233
|
+
getNonEmptyNullifiers: () => [],
|
|
234
|
+
expirationTimestamp: overrides.expirationTimestamp ?? 0n,
|
|
235
|
+
constants: {
|
|
236
|
+
anchorBlockHeader: {
|
|
237
|
+
hash: () => Promise.resolve(new BlockHash(Fr.ZERO)),
|
|
238
|
+
globalVariables: { blockNumber: BlockNumber(0) },
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
@@ -72,7 +72,7 @@ export class TxPoolIndices {
|
|
|
72
72
|
* Iterates pending transaction hashes in priority order.
|
|
73
73
|
* @param order - 'desc' for highest priority first, 'asc' for lowest priority first
|
|
74
74
|
*/
|
|
75
|
-
*iteratePendingByPriority(order: 'asc' | 'desc'): Generator<string> {
|
|
75
|
+
*iteratePendingByPriority(order: 'asc' | 'desc', filter?: (hash: string) => boolean): Generator<string> {
|
|
76
76
|
// Use compareFee from tx_metadata, swap args for descending order
|
|
77
77
|
const feeCompareFn = order === 'desc' ? (a: bigint, b: bigint) => compareFee(b, a) : compareFee;
|
|
78
78
|
const hashCompareFn = order === 'desc' ? (a: string, b: string) => compareTxHash(b, a) : compareTxHash;
|
|
@@ -84,11 +84,27 @@ export class TxPoolIndices {
|
|
|
84
84
|
// Use compareTxHash from tx_metadata, swap args for descending order
|
|
85
85
|
const sortedHashes = [...hashesAtFee].sort(hashCompareFn);
|
|
86
86
|
for (const hash of sortedHashes) {
|
|
87
|
-
|
|
87
|
+
if (filter === undefined || filter(hash)) {
|
|
88
|
+
yield hash;
|
|
89
|
+
}
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Iterates pending transaction hashes in priority order, skipping txs received after maxReceivedAt.
|
|
96
|
+
* @param order - 'desc' for highest priority first, 'asc' for lowest priority first
|
|
97
|
+
* @param maxReceivedAt - Only yield txs with receivedAt <= this value
|
|
98
|
+
*/
|
|
99
|
+
*iterateEligiblePendingByPriority(order: 'asc' | 'desc', maxReceivedAt: number): Generator<string> {
|
|
100
|
+
const filter = (hash: string) => {
|
|
101
|
+
const meta = this.#metadata.get(hash);
|
|
102
|
+
return meta !== undefined && meta.receivedAt <= maxReceivedAt;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
yield* this.iteratePendingByPriority(order, filter);
|
|
106
|
+
}
|
|
107
|
+
|
|
92
108
|
/** Iterates all metadata entries */
|
|
93
109
|
*iterateMetadata(): Generator<[string, TxMetaData]> {
|
|
94
110
|
yield* this.#metadata;
|
|
@@ -332,13 +348,15 @@ export class TxPoolIndices {
|
|
|
332
348
|
// METRICS
|
|
333
349
|
// ============================================================================
|
|
334
350
|
|
|
335
|
-
/** Counts transactions by state */
|
|
336
|
-
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 } {
|
|
337
353
|
let pending = 0;
|
|
338
354
|
let protected_ = 0;
|
|
339
355
|
let mined = 0;
|
|
356
|
+
let totalMetadataBytes = 0;
|
|
340
357
|
|
|
341
358
|
for (const meta of this.#metadata.values()) {
|
|
359
|
+
totalMetadataBytes += meta.estimatedSizeBytes;
|
|
342
360
|
const state = this.getTxState(meta);
|
|
343
361
|
if (state === 'pending') {
|
|
344
362
|
pending++;
|
|
@@ -349,7 +367,16 @@ export class TxPoolIndices {
|
|
|
349
367
|
}
|
|
350
368
|
}
|
|
351
369
|
|
|
352
|
-
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;
|
|
353
380
|
}
|
|
354
381
|
|
|
355
382
|
/** Gets all mined transactions with their block IDs */
|