@aztec/p2p 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.dbf9cec
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 +6 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +23 -30
- package/dest/client/interface.d.ts +14 -19
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +9 -18
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +52 -72
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
- package/dest/config.d.ts +13 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -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/attestation_pool.d.ts +4 -2
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +5 -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 +30 -13
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +91 -20
- 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 +5 -2
- 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 +12 -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 +7 -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 +14 -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/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- 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 +20 -6
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +34 -8
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +76 -10
- 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 +36 -14
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
- 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 +13 -5
- 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 +297 -143
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +219 -58
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- 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 +4 -4
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +4 -4
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +9 -8
- 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 +16 -13
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +69 -81
- 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 +19 -46
- 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/batch-tx-requester/peer_collection.d.ts +17 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- 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 +2 -1
- package/dest/services/service.d.ts +5 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +13 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +30 -0
- 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 +38 -29
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +126 -77
- package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -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 +49 -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 +5 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +17 -12
- package/dest/services/tx_collection/tx_collection.d.ts +9 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +26 -10
- 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.d.ts +3 -2
- 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 +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +8 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +8 -3
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +7 -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 +13 -13
- 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 +39 -48
- package/src/client/interface.ts +17 -20
- package/src/client/p2p_client.ts +60 -104
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
- package/src/config.ts +10 -10
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +8 -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 +43 -27
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +109 -22
- 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 +5 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -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 +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -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/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +21 -6
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +107 -17
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +18 -7
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +326 -138
- package/src/msg_validators/tx_validator/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
- package/src/msg_validators/tx_validator/factory.ts +353 -77
- package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
- package/src/services/dummy_service.ts +6 -6
- package/src/services/encoding.ts +7 -7
- 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 +80 -90
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
- 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/batch-tx-requester/peer_collection.ts +63 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/reqresp.ts +3 -1
- package/src/services/service.ts +11 -2
- package/src/services/tx_collection/config.ts +42 -0
- package/src/services/tx_collection/fast_tx_collection.ts +51 -30
- package/src/services/tx_collection/file_store_tx_collection.ts +143 -93
- package/src/services/tx_collection/file_store_tx_source.ts +64 -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 +17 -13
- package/src/services/tx_collection/tx_collection.ts +45 -14
- 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 +6 -4
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +0 -2
- package/src/test-helpers/mock-pubsub.ts +13 -6
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/test-helpers/testbench-utils.ts +11 -3
- package/src/testbench/p2p_client_testbench_worker.ts +22 -19
- package/src/util.ts +7 -1
package/src/client/factory.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
5
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
5
6
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
6
7
|
import { AztecLMDBStoreV2, createStore } from '@aztec/kv-store/lmdb-v2';
|
|
7
|
-
import type {
|
|
8
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
8
9
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
9
10
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
10
|
-
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
12
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
11
|
+
import type { AztecNode, ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
13
12
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
13
|
|
|
15
14
|
import { P2PClient } from '../client/p2p_client.js';
|
|
@@ -17,26 +16,24 @@ import type { P2PConfig } from '../config.js';
|
|
|
17
16
|
import { AttestationPool, type AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
18
17
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
19
18
|
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
20
|
-
import type { TxMetaData } from '../mem_pools/tx_pool_v2/tx_metadata.js';
|
|
21
19
|
import { AztecKVTxPoolV2 } from '../mem_pools/tx_pool_v2/tx_pool_v2.js';
|
|
22
|
-
import {
|
|
23
|
-
import { BlockHeaderTxValidator } from '../msg_validators/tx_validator/block_header_validator.js';
|
|
24
|
-
import { DoubleSpendTxValidator } from '../msg_validators/tx_validator/double_spend_validator.js';
|
|
20
|
+
import { createTxValidatorForTransactionsEnteringPendingTxPool } from '../msg_validators/index.js';
|
|
25
21
|
import { DummyP2PService } from '../services/dummy_service.js';
|
|
26
22
|
import { LibP2PService } from '../services/index.js';
|
|
27
23
|
import { createFileStoreTxSources } from '../services/tx_collection/file_store_tx_source.js';
|
|
28
24
|
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
29
|
-
import { type TxSource, createNodeRpcTxSources } from '../services/tx_collection/tx_source.js';
|
|
25
|
+
import { NodeRpcTxSource, type TxSource, createNodeRpcTxSources } from '../services/tx_collection/tx_source.js';
|
|
30
26
|
import { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
|
|
31
27
|
import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js';
|
|
32
28
|
|
|
33
|
-
export type P2PClientDeps
|
|
29
|
+
export type P2PClientDeps = {
|
|
34
30
|
txPool?: TxPoolV2;
|
|
35
31
|
store?: AztecAsyncKVStore;
|
|
36
32
|
attestationPool?: AttestationPoolApi;
|
|
37
33
|
logger?: Logger;
|
|
38
34
|
txCollectionNodeSources?: TxSource[];
|
|
39
|
-
|
|
35
|
+
rpcTxProviders?: AztecNode[];
|
|
36
|
+
p2pServiceFactory?: (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService>;
|
|
40
37
|
};
|
|
41
38
|
|
|
42
39
|
export const P2P_STORE_NAME = 'p2p';
|
|
@@ -44,8 +41,7 @@ export const P2P_ARCHIVE_STORE_NAME = 'p2p-archive';
|
|
|
44
41
|
export const P2P_PEER_STORE_NAME = 'p2p-peers';
|
|
45
42
|
export const P2P_ATTESTATION_STORE_NAME = 'p2p-attestation';
|
|
46
43
|
|
|
47
|
-
export async function createP2PClient
|
|
48
|
-
clientType: T,
|
|
44
|
+
export async function createP2PClient(
|
|
49
45
|
inputConfig: P2PConfig & DataStoreConfig & ChainConfig,
|
|
50
46
|
archiver: L2BlockSource & ContractDataSource,
|
|
51
47
|
proofVerifier: ClientProtocolCircuitVerifier,
|
|
@@ -54,7 +50,7 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
54
50
|
packageVersion: string,
|
|
55
51
|
dateProvider: DateProvider = new DateProvider(),
|
|
56
52
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
57
|
-
deps: P2PClientDeps
|
|
53
|
+
deps: P2PClientDeps = {},
|
|
58
54
|
) {
|
|
59
55
|
const config = await configureP2PClientAddresses({
|
|
60
56
|
...inputConfig,
|
|
@@ -76,31 +72,8 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
76
72
|
const attestationStore = await createStore(P2P_ATTESTATION_STORE_NAME, 1, config, bindings);
|
|
77
73
|
const l1Constants = await archiver.getL1Constants();
|
|
78
74
|
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
await worldStateSynchronizer.syncImmediate();
|
|
82
|
-
return new AggregateTxValidator<TxMetaData>(
|
|
83
|
-
new DoubleSpendTxValidator<TxMetaData>(
|
|
84
|
-
{
|
|
85
|
-
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
86
|
-
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
87
|
-
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
88
|
-
return indices.map(index => index !== undefined);
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
bindings,
|
|
92
|
-
),
|
|
93
|
-
new BlockHeaderTxValidator<TxMetaData>(
|
|
94
|
-
{
|
|
95
|
-
getArchiveIndices: (archives: BlockHash[]) => {
|
|
96
|
-
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
97
|
-
return merkleTree.findLeafIndices(MerkleTreeId.ARCHIVE, archives);
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
bindings,
|
|
101
|
-
),
|
|
102
|
-
);
|
|
103
|
-
};
|
|
75
|
+
const rollupAddress = inputConfig.l1Contracts.rollupAddress.toString().toLowerCase().replace(/^0x/, '');
|
|
76
|
+
const txFileStoreBasePath = `aztec-${inputConfig.l1ChainId}-${inputConfig.rollupVersion}-0x${rollupAddress}`;
|
|
104
77
|
|
|
105
78
|
const txPool =
|
|
106
79
|
deps.txPool ??
|
|
@@ -110,13 +83,25 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
110
83
|
{
|
|
111
84
|
l2BlockSource: archiver,
|
|
112
85
|
worldStateSynchronizer,
|
|
113
|
-
createTxValidator:
|
|
86
|
+
createTxValidator: async () => {
|
|
87
|
+
// We accept transactions if they are not expired by the next slot and block number (checked based on the ExpirationTimestamp field)
|
|
88
|
+
const currentBlockNumber = await archiver.getBlockNumber();
|
|
89
|
+
const { ts: nextSlotTimestamp } = epochCache.getEpochAndSlotInNextL1Slot();
|
|
90
|
+
return createTxValidatorForTransactionsEnteringPendingTxPool(
|
|
91
|
+
worldStateSynchronizer,
|
|
92
|
+
nextSlotTimestamp,
|
|
93
|
+
BlockNumber(currentBlockNumber + 1),
|
|
94
|
+
);
|
|
95
|
+
},
|
|
114
96
|
},
|
|
115
97
|
telemetry,
|
|
116
98
|
{
|
|
117
99
|
maxPendingTxCount: config.maxPendingTxCount,
|
|
118
100
|
archivedTxLimit: config.archivedTxLimit,
|
|
101
|
+
minTxPoolAgeMs: config.minTxPoolAgeMs,
|
|
102
|
+
dropTransactionsProbability: config.dropTransactionsProbability,
|
|
119
103
|
},
|
|
104
|
+
dateProvider,
|
|
120
105
|
);
|
|
121
106
|
|
|
122
107
|
const mempools: MemPools = {
|
|
@@ -124,9 +109,8 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
124
109
|
attestationPool: deps.attestationPool ?? new AttestationPool(attestationStore, telemetry),
|
|
125
110
|
};
|
|
126
111
|
|
|
127
|
-
const p2pService = await createP2PService
|
|
112
|
+
const p2pService = await createP2PService(
|
|
128
113
|
config,
|
|
129
|
-
clientType,
|
|
130
114
|
archiver,
|
|
131
115
|
proofVerifier,
|
|
132
116
|
worldStateSynchronizer,
|
|
@@ -142,6 +126,7 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
142
126
|
|
|
143
127
|
const nodeSources = [
|
|
144
128
|
...createNodeRpcTxSources(config.txCollectionNodeRpcUrls, config),
|
|
129
|
+
...(deps.rpcTxProviders ?? []).map((node, i) => new NodeRpcTxSource(node, `node-rpc-provider-${i}`)),
|
|
145
130
|
...(deps.txCollectionNodeSources ?? []),
|
|
146
131
|
];
|
|
147
132
|
if (nodeSources.length > 0) {
|
|
@@ -152,7 +137,9 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
152
137
|
|
|
153
138
|
const fileStoreSources = await createFileStoreTxSources(
|
|
154
139
|
config.txCollectionFileStoreUrls,
|
|
140
|
+
txFileStoreBasePath,
|
|
155
141
|
logger.createChild('file-store-tx-source'),
|
|
142
|
+
telemetry,
|
|
156
143
|
);
|
|
157
144
|
if (fileStoreSources.length > 0) {
|
|
158
145
|
logger.info(`Using ${fileStoreSources.length} file store sources for tx collection.`, {
|
|
@@ -172,10 +159,15 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
172
159
|
logger.createChild('tx-collection'),
|
|
173
160
|
);
|
|
174
161
|
|
|
175
|
-
const txFileStore = await TxFileStore.create(
|
|
162
|
+
const txFileStore = await TxFileStore.create(
|
|
163
|
+
mempools.txPool,
|
|
164
|
+
config,
|
|
165
|
+
txFileStoreBasePath,
|
|
166
|
+
logger.createChild('tx-file-store'),
|
|
167
|
+
telemetry,
|
|
168
|
+
);
|
|
176
169
|
|
|
177
170
|
return new P2PClient(
|
|
178
|
-
clientType,
|
|
179
171
|
store,
|
|
180
172
|
archiver,
|
|
181
173
|
mempools,
|
|
@@ -189,9 +181,8 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
189
181
|
);
|
|
190
182
|
}
|
|
191
183
|
|
|
192
|
-
async function createP2PService
|
|
184
|
+
async function createP2PService(
|
|
193
185
|
config: P2PConfig & DataStoreConfig,
|
|
194
|
-
clientType: T,
|
|
195
186
|
archiver: L2BlockSource & ContractDataSource,
|
|
196
187
|
proofVerifier: ClientProtocolCircuitVerifier,
|
|
197
188
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
@@ -199,7 +190,7 @@ async function createP2PService<T extends P2PClientType>(
|
|
|
199
190
|
store: AztecAsyncKVStore,
|
|
200
191
|
peerStore: AztecLMDBStoreV2,
|
|
201
192
|
mempools: MemPools,
|
|
202
|
-
p2pServiceFactory: P2PClientDeps
|
|
193
|
+
p2pServiceFactory: P2PClientDeps['p2pServiceFactory'],
|
|
203
194
|
packageVersion: string,
|
|
204
195
|
logger: Logger,
|
|
205
196
|
telemetry: TelemetryClient,
|
|
@@ -215,7 +206,7 @@ async function createP2PService<T extends P2PClientType>(
|
|
|
215
206
|
const peerIdPrivateKey = await getPeerIdPrivateKey(config, store, logger);
|
|
216
207
|
const peerId = await createLibP2PPeerIdFromPrivateKey(peerIdPrivateKey.getValue());
|
|
217
208
|
|
|
218
|
-
const p2pService = await (p2pServiceFactory ?? LibP2PService.new
|
|
209
|
+
const p2pService = await (p2pServiceFactory ?? LibP2PService.new)(config, peerId, {
|
|
219
210
|
packageVersion,
|
|
220
211
|
mempools,
|
|
221
212
|
l2BlockSource: archiver,
|
package/src/client/interface.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress, L2BlockId } from '@aztec/stdlib/block';
|
|
3
|
-
import type {
|
|
4
|
-
import type { BlockProposal, CheckpointAttestation, CheckpointProposal,
|
|
3
|
+
import type { ITxProvider, P2PClient } from '@aztec/stdlib/interfaces/server';
|
|
4
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
|
|
5
5
|
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
7
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -48,7 +48,7 @@ export interface P2PSyncState {
|
|
|
48
48
|
/**
|
|
49
49
|
* Interface of a P2P client.
|
|
50
50
|
**/
|
|
51
|
-
export type P2P
|
|
51
|
+
export type P2P = P2PClient & {
|
|
52
52
|
/**
|
|
53
53
|
* Broadcasts a block proposal to other peers.
|
|
54
54
|
*
|
|
@@ -107,13 +107,6 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
107
107
|
**/
|
|
108
108
|
sendTx(tx: Tx): Promise<void>;
|
|
109
109
|
|
|
110
|
-
/**
|
|
111
|
-
* Adds transactions to the pool. Does not send to peers or validate the tx.
|
|
112
|
-
* @param txs - The transactions.
|
|
113
|
-
* @returns The number of txs added to the pool. Note if the transaction already exists, it will not be added again.
|
|
114
|
-
**/
|
|
115
|
-
addTxsToPool(txs: Tx[]): Promise<number>;
|
|
116
|
-
|
|
117
110
|
/**
|
|
118
111
|
* Handles failed transaction execution by removing txs from the pool.
|
|
119
112
|
* @param txHashes - Hashes of the transactions that failed execution.
|
|
@@ -141,14 +134,6 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
141
134
|
*/
|
|
142
135
|
hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]>;
|
|
143
136
|
|
|
144
|
-
/**
|
|
145
|
-
* Returns transactions in the transaction pool by hash, requesting from the network if not found.
|
|
146
|
-
* @param txHashes - Hashes of tx to return.
|
|
147
|
-
* @param pinnedPeerId - An optional peer id that will be used to request the tx from (in addition to other random peers).
|
|
148
|
-
* @returns An array of tx or undefined.
|
|
149
|
-
*/
|
|
150
|
-
getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]>;
|
|
151
|
-
|
|
152
137
|
/**
|
|
153
138
|
* Returns an archived transaction from the transaction pool by its hash.
|
|
154
139
|
* @param txHash - Hash of tx to return.
|
|
@@ -166,6 +151,9 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
166
151
|
/** Returns an iterator over pending txs on the mempool. */
|
|
167
152
|
iteratePendingTxs(): AsyncIterableIterator<Tx>;
|
|
168
153
|
|
|
154
|
+
/** Returns an iterator over pending txs that have been in the pool long enough to be eligible for block building. */
|
|
155
|
+
iterateEligiblePendingTxs(): AsyncIterableIterator<Tx>;
|
|
156
|
+
|
|
169
157
|
/** Returns the number of pending txs in the mempool. */
|
|
170
158
|
getPendingTxCount(): Promise<number>;
|
|
171
159
|
|
|
@@ -217,10 +205,13 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
217
205
|
/** Identifies a p2p client. */
|
|
218
206
|
isP2PClient(): true;
|
|
219
207
|
|
|
208
|
+
/** Returns the tx provider used for fetching transactions. */
|
|
209
|
+
getTxProvider(): ITxProvider;
|
|
210
|
+
|
|
220
211
|
updateP2PConfig(config: Partial<P2PConfig>): Promise<void>;
|
|
221
212
|
|
|
222
|
-
/** Validates a set of txs. */
|
|
223
|
-
|
|
213
|
+
/** Validates a set of txs received in a block proposal. */
|
|
214
|
+
validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void>;
|
|
224
215
|
|
|
225
216
|
/** Clears the db. */
|
|
226
217
|
clear(): Promise<void>;
|
|
@@ -233,6 +224,12 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
233
224
|
|
|
234
225
|
handleAuthRequestFromPeer(authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage>;
|
|
235
226
|
|
|
227
|
+
/** Checks if any block proposals exist for the given slot. */
|
|
228
|
+
hasBlockProposalsForSlot(slot: SlotNumber): Promise<boolean>;
|
|
229
|
+
|
|
236
230
|
/** If node running this P2P stack is validator, passes in validator address to P2P layer */
|
|
237
231
|
registerThisValidatorAddresses(address: EthAddress[]): void;
|
|
232
|
+
|
|
233
|
+
/** Returns the number of peers in the GossipSub mesh for a given topic type. */
|
|
234
|
+
getGossipMeshPeerCount(topicType: TopicType): Promise<number>;
|
|
238
235
|
};
|
package/src/client/p2p_client.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
2
2
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
3
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { RunningPromise } from '@aztec/foundation/promise';
|
|
6
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
7
7
|
import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
8
8
|
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
9
9
|
import {
|
|
10
|
+
type CheckpointId,
|
|
10
11
|
type EthAddress,
|
|
11
12
|
type L2Block,
|
|
12
13
|
type L2BlockId,
|
|
@@ -19,12 +20,7 @@ import {
|
|
|
19
20
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
20
21
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
21
22
|
import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
|
|
22
|
-
import {
|
|
23
|
-
type BlockProposal,
|
|
24
|
-
CheckpointAttestation,
|
|
25
|
-
type CheckpointProposal,
|
|
26
|
-
type P2PClientType,
|
|
27
|
-
} from '@aztec/stdlib/p2p';
|
|
23
|
+
import { type BlockProposal, CheckpointAttestation, type CheckpointProposal, type TopicType } from '@aztec/stdlib/p2p';
|
|
28
24
|
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
29
25
|
import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
30
26
|
|
|
@@ -32,6 +28,7 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
32
28
|
import type { ENR } from '@nethermindeth/enr';
|
|
33
29
|
|
|
34
30
|
import { type P2PConfig, getP2PDefaultConfig } from '../config.js';
|
|
31
|
+
import { TxPoolError } from '../errors/tx-pool.error.js';
|
|
35
32
|
import type { AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
36
33
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
37
34
|
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
@@ -41,7 +38,6 @@ import {
|
|
|
41
38
|
type ReqRespSubProtocolHandler,
|
|
42
39
|
type ReqRespSubProtocolValidators,
|
|
43
40
|
} from '../services/reqresp/interface.js';
|
|
44
|
-
import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
|
|
45
41
|
import type {
|
|
46
42
|
DuplicateAttestationInfo,
|
|
47
43
|
DuplicateProposalInfo,
|
|
@@ -57,10 +53,7 @@ import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
|
57
53
|
/**
|
|
58
54
|
* The P2P client implementation.
|
|
59
55
|
*/
|
|
60
|
-
export class P2PClient
|
|
61
|
-
extends WithTracer
|
|
62
|
-
implements P2P, P2P<P2PClientType.Prover>
|
|
63
|
-
{
|
|
56
|
+
export class P2PClient extends WithTracer implements P2P {
|
|
64
57
|
/** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */
|
|
65
58
|
private runningPromise!: Promise<void>;
|
|
66
59
|
|
|
@@ -92,7 +85,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
92
85
|
private slotMonitor: RunningPromise | undefined;
|
|
93
86
|
|
|
94
87
|
constructor(
|
|
95
|
-
_clientType: T,
|
|
96
88
|
private store: AztecAsyncKVStore,
|
|
97
89
|
private l2BlockSource: L2BlockSource & ContractDataSource,
|
|
98
90
|
mempools: MemPools,
|
|
@@ -165,6 +157,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
165
157
|
return Promise.resolve(this.p2pService.getPeers(includePending));
|
|
166
158
|
}
|
|
167
159
|
|
|
160
|
+
public getGossipMeshPeerCount(topicType: TopicType): Promise<number> {
|
|
161
|
+
return Promise.resolve(this.p2pService.getGossipMeshPeerCount(topicType));
|
|
162
|
+
}
|
|
163
|
+
|
|
168
164
|
public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
169
165
|
return this.l2Tips.getL2BlockHash(number);
|
|
170
166
|
}
|
|
@@ -200,7 +196,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
200
196
|
break;
|
|
201
197
|
case 'chain-pruned':
|
|
202
198
|
this.txCollection.stopCollectingForBlocksAfter(event.block.number);
|
|
203
|
-
await this.handlePruneL2Blocks(event.block);
|
|
199
|
+
await this.handlePruneL2Blocks(event.block, event.checkpoint);
|
|
204
200
|
break;
|
|
205
201
|
case 'chain-checkpointed':
|
|
206
202
|
break;
|
|
@@ -404,6 +400,10 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
404
400
|
return this.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
405
401
|
}
|
|
406
402
|
|
|
403
|
+
public hasBlockProposalsForSlot(slot: SlotNumber): Promise<boolean> {
|
|
404
|
+
return this.attestationPool.hasBlockProposalsForSlot(slot);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
407
|
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
408
408
|
// ^ This pattern is not my favorite (md)
|
|
409
409
|
public registerBlockProposalHandler(handler: P2PBlockReceivedCallback): void {
|
|
@@ -422,36 +422,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
422
422
|
this.p2pService.registerDuplicateAttestationCallback(callback);
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
/**
|
|
426
|
-
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
427
|
-
*/
|
|
428
|
-
private async requestTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<Tx[]> {
|
|
429
|
-
const timeoutMs = 8000; // Longer timeout for now
|
|
430
|
-
const maxRetryAttempts = 10; // Keep retrying within the timeout
|
|
431
|
-
const requests = chunkTxHashesRequest(txHashes);
|
|
432
|
-
const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
|
|
433
|
-
|
|
434
|
-
const txBatches = await this.p2pService.sendBatchRequest(
|
|
435
|
-
ReqRespSubProtocol.TX,
|
|
436
|
-
requests,
|
|
437
|
-
pinnedPeerId,
|
|
438
|
-
timeoutMs,
|
|
439
|
-
maxPeers,
|
|
440
|
-
maxRetryAttempts,
|
|
441
|
-
);
|
|
442
|
-
|
|
443
|
-
const txs = txBatches.flat();
|
|
444
|
-
if (txs.length > 0) {
|
|
445
|
-
await this.txPool.addPendingTxs(txs);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
const txHashesStr = txHashes.map(tx => tx.toString()).join(', ');
|
|
449
|
-
this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
|
|
450
|
-
|
|
451
|
-
// We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
|
|
452
|
-
return txs;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
425
|
public async getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
|
|
456
426
|
if (limit !== undefined && limit <= 0) {
|
|
457
427
|
throw new TypeError('limit must be greater than 0');
|
|
@@ -488,6 +458,15 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
488
458
|
}
|
|
489
459
|
}
|
|
490
460
|
|
|
461
|
+
public async *iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
462
|
+
for (const txHash of await this.txPool.getEligiblePendingTxHashes()) {
|
|
463
|
+
const tx = await this.txPool.getTxByHash(txHash);
|
|
464
|
+
if (tx) {
|
|
465
|
+
yield tx;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
491
470
|
/**
|
|
492
471
|
* Returns a transaction in the transaction pool by its hash.
|
|
493
472
|
* @param txHash - Hash of the transaction to look for in the pool.
|
|
@@ -510,49 +489,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
510
489
|
return this.txPool.hasTxs(txHashes);
|
|
511
490
|
}
|
|
512
491
|
|
|
513
|
-
/**
|
|
514
|
-
* Returns transactions in the transaction pool by hash.
|
|
515
|
-
* If a transaction is not in the pool, it will be requested from the network.
|
|
516
|
-
* @param txHashes - Hashes of the transactions to look for.
|
|
517
|
-
* @returns The txs found, or undefined if not found in the order requested.
|
|
518
|
-
*/
|
|
519
|
-
async getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]> {
|
|
520
|
-
const txs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
|
|
521
|
-
const missingTxHashes = txs
|
|
522
|
-
.map((tx, index) => [tx, index] as const)
|
|
523
|
-
.filter(([tx, _index]) => !tx)
|
|
524
|
-
.map(([_tx, index]) => txHashes[index]);
|
|
525
|
-
|
|
526
|
-
if (missingTxHashes.length === 0) {
|
|
527
|
-
return txs as Tx[];
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
|
|
531
|
-
// TODO: optimize
|
|
532
|
-
// Merge the found txs in order
|
|
533
|
-
const mergingTxs = txHashes.map(txHash => {
|
|
534
|
-
// Is it in the txs list from the mempool?
|
|
535
|
-
for (const tx of txs) {
|
|
536
|
-
if (tx !== undefined && tx.getTxHash().equals(txHash)) {
|
|
537
|
-
return tx;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
// Is it in the fetched missing txs?
|
|
542
|
-
// Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
|
|
543
|
-
for (const tx of missingTxs) {
|
|
544
|
-
if (tx.getTxHash().equals(txHash)) {
|
|
545
|
-
return tx;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// Otherwise return undefined
|
|
550
|
-
return undefined;
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
return mergingTxs;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
492
|
/**
|
|
557
493
|
* Returns an archived transaction in the transaction pool by its hash.
|
|
558
494
|
* @param txHash - Hash of the archived transaction to look for.
|
|
@@ -569,23 +505,22 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
569
505
|
**/
|
|
570
506
|
public async sendTx(tx: Tx): Promise<void> {
|
|
571
507
|
this.#assertIsReady();
|
|
572
|
-
const result = await this.txPool.addPendingTxs([tx]);
|
|
508
|
+
const result = await this.txPool.addPendingTxs([tx], { feeComparisonOnly: true });
|
|
573
509
|
if (result.accepted.length === 1) {
|
|
574
510
|
await this.p2pService.propagate(tx);
|
|
575
|
-
|
|
576
|
-
this.log.warn(
|
|
577
|
-
`Tx ${tx.getTxHash()} not propagated: accepted=${result.accepted.length} ignored=${result.ignored.length} rejected=${result.rejected.length}`,
|
|
578
|
-
);
|
|
511
|
+
return;
|
|
579
512
|
}
|
|
580
|
-
}
|
|
581
513
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
514
|
+
const txHashStr = tx.getTxHash().toString();
|
|
515
|
+
const reason = result.errors?.get(txHashStr);
|
|
516
|
+
if (reason) {
|
|
517
|
+
this.log.warn(`Tx ${txHashStr} not added to pool: ${reason.message}`);
|
|
518
|
+
throw new TxPoolError(reason);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
this.log.warn(
|
|
522
|
+
`Tx ${txHashStr} not propagated: accepted=${result.accepted.length} ignored=${result.ignored.length} rejected=${result.rejected.length}`,
|
|
523
|
+
);
|
|
589
524
|
}
|
|
590
525
|
|
|
591
526
|
/**
|
|
@@ -746,10 +681,31 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
746
681
|
|
|
747
682
|
/**
|
|
748
683
|
* Updates the tx pool after a chain prune.
|
|
684
|
+
* Detects epoch prunes (checkpoint number changed) and deletes all txs in that case.
|
|
749
685
|
* @param latestBlock - The block ID the chain was pruned to.
|
|
686
|
+
* @param newCheckpoint - The checkpoint ID after the prune.
|
|
750
687
|
*/
|
|
751
|
-
private async handlePruneL2Blocks(latestBlock: L2BlockId): Promise<void> {
|
|
752
|
-
|
|
688
|
+
private async handlePruneL2Blocks(latestBlock: L2BlockId, newCheckpoint: CheckpointId): Promise<void> {
|
|
689
|
+
const deleteAllTxs = this.config.txPoolDeleteTxsAfterReorg && (await this.isEpochPrune(newCheckpoint));
|
|
690
|
+
await this.txPool.handlePrunedBlocks(latestBlock, { deleteAllTxs });
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Returns true if the prune crossed a checkpoint boundary.
|
|
695
|
+
* If the old and new checkpoint numbers are the same, the prune is within a single checkpoint.
|
|
696
|
+
* If they differ, the prune spans across checkpoints (epoch prune).
|
|
697
|
+
*/
|
|
698
|
+
private async isEpochPrune(newCheckpoint: CheckpointId): Promise<boolean> {
|
|
699
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
700
|
+
const oldCheckpointNumber = tips.checkpointed.checkpoint.number;
|
|
701
|
+
if (oldCheckpointNumber <= CheckpointNumber.ZERO) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
const isEpochPrune = oldCheckpointNumber !== newCheckpoint.number;
|
|
705
|
+
this.log.info(
|
|
706
|
+
`Detected epoch prune: ${isEpochPrune}. Old checkpoint: ${oldCheckpointNumber}, new checkpoint: ${newCheckpoint.number}`,
|
|
707
|
+
);
|
|
708
|
+
return isEpochPrune;
|
|
753
709
|
}
|
|
754
710
|
|
|
755
711
|
/** Checks if the slot has changed and calls prepareForSlot if so. */
|
|
@@ -799,8 +755,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
799
755
|
this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
|
|
800
756
|
}
|
|
801
757
|
|
|
802
|
-
public
|
|
803
|
-
return this.p2pService.
|
|
758
|
+
public validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
759
|
+
return this.p2pService.validateTxsReceivedInBlockProposal(txs);
|
|
804
760
|
}
|
|
805
761
|
|
|
806
762
|
/**
|
|
@@ -8,7 +8,7 @@ import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
|
8
8
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
9
9
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
10
10
|
import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import {
|
|
11
|
+
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
12
12
|
import type { Tx, TxValidationResult } from '@aztec/stdlib/tx';
|
|
13
13
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
14
|
|
|
@@ -16,14 +16,12 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
16
16
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
17
17
|
|
|
18
18
|
import type { P2PConfig } from '../../../config.js';
|
|
19
|
+
import { BatchTxRequesterCollector, SendBatchRequestCollector } from '../../../services/index.js';
|
|
19
20
|
import type { IBatchRequestTxValidator } from '../../../services/reqresp/batch-tx-requester/tx_validator.js';
|
|
20
21
|
import { RateLimitStatus } from '../../../services/reqresp/rate-limiter/rate_limiter.js';
|
|
22
|
+
import { MissingTxsTracker } from '../../../services/tx_collection/missing_txs_tracker.js';
|
|
21
23
|
import {
|
|
22
|
-
|
|
23
|
-
SendBatchRequestCollector,
|
|
24
|
-
} from '../../../services/tx_collection/proposal_tx_collector.js';
|
|
25
|
-
import { AlwaysTrueCircuitVerifier } from '../../../test-helpers/reqresp-nodes.js';
|
|
26
|
-
import {
|
|
24
|
+
AlwaysTrueCircuitVerifier,
|
|
27
25
|
BENCHMARK_CONSTANTS,
|
|
28
26
|
InMemoryAttestationPool,
|
|
29
27
|
InMemoryTxPool,
|
|
@@ -31,7 +29,7 @@ import {
|
|
|
31
29
|
calculateInternalTimeout,
|
|
32
30
|
createMockEpochCache,
|
|
33
31
|
createMockWorldStateSynchronizer,
|
|
34
|
-
} from '../../../test-helpers/
|
|
32
|
+
} from '../../../test-helpers/index.js';
|
|
35
33
|
import { createP2PClient } from '../../index.js';
|
|
36
34
|
import type { P2PClient } from '../../p2p_client.js';
|
|
37
35
|
import {
|
|
@@ -116,7 +114,6 @@ async function startClient(config: P2PConfig, clientIndex: number) {
|
|
|
116
114
|
};
|
|
117
115
|
|
|
118
116
|
client = await createP2PClient(
|
|
119
|
-
P2PClientType.Full,
|
|
120
117
|
config as P2PConfig & DataStoreConfig,
|
|
121
118
|
l2BlockSource as L2BlockSource & ContractDataSource,
|
|
122
119
|
proofVerifier as ClientProtocolCircuitVerifier,
|
|
@@ -214,7 +211,13 @@ async function runCollector(cmd: Extract<WorkerCommand, { type: 'RUN_COLLECTOR'
|
|
|
214
211
|
if (collectorType === 'batch-requester') {
|
|
215
212
|
const collector = new BatchTxRequesterCollector(p2pService, logger, new DateProvider(), noopTxValidator);
|
|
216
213
|
const fetched = await executeTimeout(
|
|
217
|
-
(_signal: AbortSignal) =>
|
|
214
|
+
(_signal: AbortSignal) =>
|
|
215
|
+
collector.collectTxs(
|
|
216
|
+
MissingTxsTracker.fromArray(parsedTxHashes),
|
|
217
|
+
parsedProposal,
|
|
218
|
+
pinnedPeer,
|
|
219
|
+
internalTimeoutMs,
|
|
220
|
+
),
|
|
218
221
|
timeoutMs,
|
|
219
222
|
() => new Error(`Collector timed out after ${timeoutMs}ms`),
|
|
220
223
|
);
|
|
@@ -226,7 +229,13 @@ async function runCollector(cmd: Extract<WorkerCommand, { type: 'RUN_COLLECTOR'
|
|
|
226
229
|
BENCHMARK_CONSTANTS.FIXED_MAX_RETRY_ATTEMPTS,
|
|
227
230
|
);
|
|
228
231
|
const fetched = await executeTimeout(
|
|
229
|
-
(_signal: AbortSignal) =>
|
|
232
|
+
(_signal: AbortSignal) =>
|
|
233
|
+
collector.collectTxs(
|
|
234
|
+
MissingTxsTracker.fromArray(parsedTxHashes),
|
|
235
|
+
parsedProposal,
|
|
236
|
+
pinnedPeer,
|
|
237
|
+
internalTimeoutMs,
|
|
238
|
+
),
|
|
230
239
|
timeoutMs,
|
|
231
240
|
() => new Error(`Collector timed out after ${timeoutMs}ms`),
|
|
232
241
|
);
|