@aztec/p2p 0.0.1-commit.8f9871590 → 0.0.1-commit.9117c5f5a
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 +18 -28
- package/dest/client/interface.d.ts +10 -19
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +7 -18
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +41 -72
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
- package/dest/config.d.ts +4 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +0 -5
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +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 +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -5
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +12 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/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 +16 -6
- 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 +29 -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 +71 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +21 -12
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +6 -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 +6 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +11 -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 +274 -149
- 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/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/fast_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +39 -33
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
- package/dest/services/tx_collection/file_store_tx_source.d.ts +15 -6
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +47 -16
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/dest/services/tx_collection/slow_tx_collection.d.ts +2 -2
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +10 -8
- package/dest/services/tx_collection/tx_collection.d.ts +5 -4
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +13 -22
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/tx_file_store.js +1 -1
- package/dest/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 +6 -3
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +1 -1
- package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +11 -11
- 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 +27 -48
- package/src/client/interface.ts +11 -20
- package/src/client/p2p_client.ts +47 -104
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
- package/src/config.ts +2 -10
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +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 +2 -2
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +12 -9
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +15 -6
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +96 -10
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +25 -14
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +12 -7
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +303 -144
- 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/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/fast_tx_collection.ts +51 -30
- package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
- package/src/services/tx_collection/file_store_tx_source.ts +61 -17
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
- package/src/services/tx_collection/slow_tx_collection.ts +8 -9
- package/src/services/tx_collection/tx_collection.ts +4 -3
- package/src/services/tx_collection/tx_collection_sink.ts +15 -29
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/tx_file_store.ts +1 -1
- package/src/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 +3 -3
- package/src/testbench/p2p_client_testbench_worker.ts +20 -17
- 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,
|
|
@@ -79,32 +75,6 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
79
75
|
const rollupAddress = inputConfig.l1Contracts.rollupAddress.toString().toLowerCase().replace(/^0x/, '');
|
|
80
76
|
const txFileStoreBasePath = `aztec-${inputConfig.l1ChainId}-${inputConfig.rollupVersion}-0x${rollupAddress}`;
|
|
81
77
|
|
|
82
|
-
/** Validator factory for pool re-validation (double-spend + block header only). */
|
|
83
|
-
const createPoolTxValidator = async () => {
|
|
84
|
-
await worldStateSynchronizer.syncImmediate();
|
|
85
|
-
return new AggregateTxValidator<TxMetaData>(
|
|
86
|
-
new DoubleSpendTxValidator<TxMetaData>(
|
|
87
|
-
{
|
|
88
|
-
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
89
|
-
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
90
|
-
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
91
|
-
return indices.map(index => index !== undefined);
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
bindings,
|
|
95
|
-
),
|
|
96
|
-
new BlockHeaderTxValidator<TxMetaData>(
|
|
97
|
-
{
|
|
98
|
-
getArchiveIndices: (archives: BlockHash[]) => {
|
|
99
|
-
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
100
|
-
return merkleTree.findLeafIndices(MerkleTreeId.ARCHIVE, archives);
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
bindings,
|
|
104
|
-
),
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
78
|
const txPool =
|
|
109
79
|
deps.txPool ??
|
|
110
80
|
new AztecKVTxPoolV2(
|
|
@@ -113,13 +83,23 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
113
83
|
{
|
|
114
84
|
l2BlockSource: archiver,
|
|
115
85
|
worldStateSynchronizer,
|
|
116
|
-
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
|
+
},
|
|
117
96
|
},
|
|
118
97
|
telemetry,
|
|
119
98
|
{
|
|
120
99
|
maxPendingTxCount: config.maxPendingTxCount,
|
|
121
100
|
archivedTxLimit: config.archivedTxLimit,
|
|
122
101
|
minTxPoolAgeMs: config.minTxPoolAgeMs,
|
|
102
|
+
dropTransactionsProbability: config.dropTransactionsProbability,
|
|
123
103
|
},
|
|
124
104
|
dateProvider,
|
|
125
105
|
);
|
|
@@ -129,9 +109,8 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
129
109
|
attestationPool: deps.attestationPool ?? new AttestationPool(attestationStore, telemetry),
|
|
130
110
|
};
|
|
131
111
|
|
|
132
|
-
const p2pService = await createP2PService
|
|
112
|
+
const p2pService = await createP2PService(
|
|
133
113
|
config,
|
|
134
|
-
clientType,
|
|
135
114
|
archiver,
|
|
136
115
|
proofVerifier,
|
|
137
116
|
worldStateSynchronizer,
|
|
@@ -147,6 +126,7 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
147
126
|
|
|
148
127
|
const nodeSources = [
|
|
149
128
|
...createNodeRpcTxSources(config.txCollectionNodeRpcUrls, config),
|
|
129
|
+
...(deps.rpcTxProviders ?? []).map((node, i) => new NodeRpcTxSource(node, `node-rpc-provider-${i}`)),
|
|
150
130
|
...(deps.txCollectionNodeSources ?? []),
|
|
151
131
|
];
|
|
152
132
|
if (nodeSources.length > 0) {
|
|
@@ -159,6 +139,7 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
159
139
|
config.txCollectionFileStoreUrls,
|
|
160
140
|
txFileStoreBasePath,
|
|
161
141
|
logger.createChild('file-store-tx-source'),
|
|
142
|
+
telemetry,
|
|
162
143
|
);
|
|
163
144
|
if (fileStoreSources.length > 0) {
|
|
164
145
|
logger.info(`Using ${fileStoreSources.length} file store sources for tx collection.`, {
|
|
@@ -187,7 +168,6 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
187
168
|
);
|
|
188
169
|
|
|
189
170
|
return new P2PClient(
|
|
190
|
-
clientType,
|
|
191
171
|
store,
|
|
192
172
|
archiver,
|
|
193
173
|
mempools,
|
|
@@ -201,9 +181,8 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
201
181
|
);
|
|
202
182
|
}
|
|
203
183
|
|
|
204
|
-
async function createP2PService
|
|
184
|
+
async function createP2PService(
|
|
205
185
|
config: P2PConfig & DataStoreConfig,
|
|
206
|
-
clientType: T,
|
|
207
186
|
archiver: L2BlockSource & ContractDataSource,
|
|
208
187
|
proofVerifier: ClientProtocolCircuitVerifier,
|
|
209
188
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
@@ -211,7 +190,7 @@ async function createP2PService<T extends P2PClientType>(
|
|
|
211
190
|
store: AztecAsyncKVStore,
|
|
212
191
|
peerStore: AztecLMDBStoreV2,
|
|
213
192
|
mempools: MemPools,
|
|
214
|
-
p2pServiceFactory: P2PClientDeps
|
|
193
|
+
p2pServiceFactory: P2PClientDeps['p2pServiceFactory'],
|
|
215
194
|
packageVersion: string,
|
|
216
195
|
logger: Logger,
|
|
217
196
|
telemetry: TelemetryClient,
|
|
@@ -227,7 +206,7 @@ async function createP2PService<T extends P2PClientType>(
|
|
|
227
206
|
const peerIdPrivateKey = await getPeerIdPrivateKey(config, store, logger);
|
|
228
207
|
const peerId = await createLibP2PPeerIdFromPrivateKey(peerIdPrivateKey.getValue());
|
|
229
208
|
|
|
230
|
-
const p2pService = await (p2pServiceFactory ?? LibP2PService.new
|
|
209
|
+
const p2pService = await (p2pServiceFactory ?? LibP2PService.new)(config, peerId, {
|
|
231
210
|
packageVersion,
|
|
232
211
|
mempools,
|
|
233
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.
|
|
@@ -220,10 +205,13 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
220
205
|
/** Identifies a p2p client. */
|
|
221
206
|
isP2PClient(): true;
|
|
222
207
|
|
|
208
|
+
/** Returns the tx provider used for fetching transactions. */
|
|
209
|
+
getTxProvider(): ITxProvider;
|
|
210
|
+
|
|
223
211
|
updateP2PConfig(config: Partial<P2PConfig>): Promise<void>;
|
|
224
212
|
|
|
225
|
-
/** Validates a set of txs. */
|
|
226
|
-
|
|
213
|
+
/** Validates a set of txs received in a block proposal. */
|
|
214
|
+
validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void>;
|
|
227
215
|
|
|
228
216
|
/** Clears the db. */
|
|
229
217
|
clear(): Promise<void>;
|
|
@@ -241,4 +229,7 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
241
229
|
|
|
242
230
|
/** If node running this P2P stack is validator, passes in validator address to P2P layer */
|
|
243
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>;
|
|
244
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;
|
|
@@ -426,36 +422,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
426
422
|
this.p2pService.registerDuplicateAttestationCallback(callback);
|
|
427
423
|
}
|
|
428
424
|
|
|
429
|
-
/**
|
|
430
|
-
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
431
|
-
*/
|
|
432
|
-
private async requestTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<Tx[]> {
|
|
433
|
-
const timeoutMs = 8000; // Longer timeout for now
|
|
434
|
-
const maxRetryAttempts = 10; // Keep retrying within the timeout
|
|
435
|
-
const requests = chunkTxHashesRequest(txHashes);
|
|
436
|
-
const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
|
|
437
|
-
|
|
438
|
-
const txBatches = await this.p2pService.sendBatchRequest(
|
|
439
|
-
ReqRespSubProtocol.TX,
|
|
440
|
-
requests,
|
|
441
|
-
pinnedPeerId,
|
|
442
|
-
timeoutMs,
|
|
443
|
-
maxPeers,
|
|
444
|
-
maxRetryAttempts,
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
const txs = txBatches.flat();
|
|
448
|
-
if (txs.length > 0) {
|
|
449
|
-
await this.txPool.addPendingTxs(txs);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const txHashesStr = txHashes.map(tx => tx.toString()).join(', ');
|
|
453
|
-
this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
|
|
454
|
-
|
|
455
|
-
// We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
|
|
456
|
-
return txs;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
425
|
public async getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
|
|
460
426
|
if (limit !== undefined && limit <= 0) {
|
|
461
427
|
throw new TypeError('limit must be greater than 0');
|
|
@@ -523,49 +489,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
523
489
|
return this.txPool.hasTxs(txHashes);
|
|
524
490
|
}
|
|
525
491
|
|
|
526
|
-
/**
|
|
527
|
-
* Returns transactions in the transaction pool by hash.
|
|
528
|
-
* If a transaction is not in the pool, it will be requested from the network.
|
|
529
|
-
* @param txHashes - Hashes of the transactions to look for.
|
|
530
|
-
* @returns The txs found, or undefined if not found in the order requested.
|
|
531
|
-
*/
|
|
532
|
-
async getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]> {
|
|
533
|
-
const txs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
|
|
534
|
-
const missingTxHashes = txs
|
|
535
|
-
.map((tx, index) => [tx, index] as const)
|
|
536
|
-
.filter(([tx, _index]) => !tx)
|
|
537
|
-
.map(([_tx, index]) => txHashes[index]);
|
|
538
|
-
|
|
539
|
-
if (missingTxHashes.length === 0) {
|
|
540
|
-
return txs as Tx[];
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
|
|
544
|
-
// TODO: optimize
|
|
545
|
-
// Merge the found txs in order
|
|
546
|
-
const mergingTxs = txHashes.map(txHash => {
|
|
547
|
-
// Is it in the txs list from the mempool?
|
|
548
|
-
for (const tx of txs) {
|
|
549
|
-
if (tx !== undefined && tx.getTxHash().equals(txHash)) {
|
|
550
|
-
return tx;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// Is it in the fetched missing txs?
|
|
555
|
-
// Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
|
|
556
|
-
for (const tx of missingTxs) {
|
|
557
|
-
if (tx.getTxHash().equals(txHash)) {
|
|
558
|
-
return tx;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// Otherwise return undefined
|
|
563
|
-
return undefined;
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
return mergingTxs;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
492
|
/**
|
|
570
493
|
* Returns an archived transaction in the transaction pool by its hash.
|
|
571
494
|
* @param txHash - Hash of the archived transaction to look for.
|
|
@@ -582,23 +505,22 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
582
505
|
**/
|
|
583
506
|
public async sendTx(tx: Tx): Promise<void> {
|
|
584
507
|
this.#assertIsReady();
|
|
585
|
-
const result = await this.txPool.addPendingTxs([tx]);
|
|
508
|
+
const result = await this.txPool.addPendingTxs([tx], { feeComparisonOnly: true });
|
|
586
509
|
if (result.accepted.length === 1) {
|
|
587
510
|
await this.p2pService.propagate(tx);
|
|
588
|
-
|
|
589
|
-
this.log.warn(
|
|
590
|
-
`Tx ${tx.getTxHash()} not propagated: accepted=${result.accepted.length} ignored=${result.ignored.length} rejected=${result.rejected.length}`,
|
|
591
|
-
);
|
|
511
|
+
return;
|
|
592
512
|
}
|
|
593
|
-
}
|
|
594
513
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
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
|
+
);
|
|
602
524
|
}
|
|
603
525
|
|
|
604
526
|
/**
|
|
@@ -759,10 +681,31 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
759
681
|
|
|
760
682
|
/**
|
|
761
683
|
* Updates the tx pool after a chain prune.
|
|
684
|
+
* Detects epoch prunes (checkpoint number changed) and deletes all txs in that case.
|
|
762
685
|
* @param latestBlock - The block ID the chain was pruned to.
|
|
686
|
+
* @param newCheckpoint - The checkpoint ID after the prune.
|
|
763
687
|
*/
|
|
764
|
-
private async handlePruneL2Blocks(latestBlock: L2BlockId): Promise<void> {
|
|
765
|
-
|
|
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;
|
|
766
709
|
}
|
|
767
710
|
|
|
768
711
|
/** Checks if the slot has changed and calls prepareForSlot if so. */
|
|
@@ -812,8 +755,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
812
755
|
this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
|
|
813
756
|
}
|
|
814
757
|
|
|
815
|
-
public
|
|
816
|
-
return this.p2pService.
|
|
758
|
+
public validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
759
|
+
return this.p2pService.validateTxsReceivedInBlockProposal(txs);
|
|
817
760
|
}
|
|
818
761
|
|
|
819
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
|
);
|
package/src/config.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface P2PConfig
|
|
|
38
38
|
ChainConfig,
|
|
39
39
|
TxCollectionConfig,
|
|
40
40
|
TxFileStoreConfig,
|
|
41
|
-
Pick<SequencerConfig, 'blockDurationMs'> {
|
|
41
|
+
Pick<SequencerConfig, 'blockDurationMs' | 'expectedBlockProposalsPerSlot'> {
|
|
42
42
|
/** A flag dictating whether the P2P subsystem should be enabled. */
|
|
43
43
|
p2pEnabled: boolean;
|
|
44
44
|
|
|
@@ -173,10 +173,7 @@ export interface P2PConfig
|
|
|
173
173
|
/** Whether transactions are disabled for this node. This means transactions will be rejected at the RPC and P2P layers. */
|
|
174
174
|
disableTransactions: boolean;
|
|
175
175
|
|
|
176
|
-
/**
|
|
177
|
-
dropTransactions: boolean;
|
|
178
|
-
|
|
179
|
-
/** The probability that a transaction is discarded. - For testing purposes only */
|
|
176
|
+
/** The probability that a transaction is discarded (0 = disabled). - For testing purposes only */
|
|
180
177
|
dropTransactionsProbability: number;
|
|
181
178
|
|
|
182
179
|
/** Whether to delete transactions from the pool after a reorg instead of moving them back to pending. */
|
|
@@ -430,11 +427,6 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
430
427
|
description: 'Number of auth attempts to allow before peer is banned. Number is inclusive',
|
|
431
428
|
...numberConfigHelper(3),
|
|
432
429
|
},
|
|
433
|
-
dropTransactions: {
|
|
434
|
-
env: 'P2P_DROP_TX',
|
|
435
|
-
description: 'True to simulate discarding transactions. - For testing purposes only',
|
|
436
|
-
...booleanConfigHelper(false),
|
|
437
|
-
},
|
|
438
430
|
dropTransactionsProbability: {
|
|
439
431
|
env: 'P2P_DROP_TX_CHANCE',
|
|
440
432
|
description: 'The probability that a transaction is discarded (0 - 1). - For testing purposes only',
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TxPoolRejectionError } from '../mem_pools/tx_pool_v2/eviction/interfaces.js';
|
|
2
|
+
|
|
3
|
+
/** Error thrown when a transaction is not added to the mempool. */
|
|
4
|
+
export class TxPoolError extends Error {
|
|
5
|
+
public readonly data: TxPoolRejectionError;
|
|
6
|
+
|
|
7
|
+
constructor(public readonly reason: TxPoolRejectionError) {
|
|
8
|
+
super(reason.message);
|
|
9
|
+
this.name = 'TxPoolError';
|
|
10
|
+
this.data = reason;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -301,6 +301,17 @@ export class DeletedPool {
|
|
|
301
301
|
return this.#state.size;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
+
/** Gets the count of soft-deleted transactions (both prune-based and slot-based). */
|
|
305
|
+
getSoftDeletedCount(): number {
|
|
306
|
+
let count = this.#slotDeletedTxs.size;
|
|
307
|
+
for (const state of this.#state.values()) {
|
|
308
|
+
if (state.softDeleted) {
|
|
309
|
+
count++;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return count;
|
|
313
|
+
}
|
|
314
|
+
|
|
304
315
|
/**
|
|
305
316
|
* Gets all transaction hashes from pruned blocks.
|
|
306
317
|
*/
|