@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f8ca9b2f3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +3 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +38 -7
- package/dest/client/interface.d.ts +26 -15
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +31 -35
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +97 -138
- package/dest/config.d.ts +10 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +9 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +18 -11
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +62 -37
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +53 -53
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -1
- package/dest/mem_pools/index.d.ts +2 -1
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +87 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +180 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +25 -3
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +36 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
- 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 +77 -74
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +2 -2
- package/dest/services/libp2p/libp2p_service.d.ts +11 -3
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +71 -35
- package/dest/services/reqresp/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +11 -4
- package/dest/services/service.d.ts +18 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +7 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +16 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +17 -3
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +44 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +118 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +27 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +57 -0
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +48 -19
- package/dest/services/tx_collection/tx_collection.d.ts +17 -7
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +58 -2
- package/dest/services/tx_collection/tx_collection_sink.d.ts +15 -6
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +13 -7
- package/dest/services/tx_file_store/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +3 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +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 +5 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +27 -1
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +97 -2
- package/dest/test-helpers/testbench-utils.d.ts +30 -24
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +87 -35
- package/dest/testbench/p2p_client_testbench_worker.js +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +65 -8
- package/src/client/interface.ts +26 -13
- package/src/client/p2p_client.ts +123 -158
- package/src/config.ts +16 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +87 -44
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +57 -53
- package/src/mem_pools/attestation_pool/index.ts +3 -3
- package/src/mem_pools/index.ts +3 -0
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +59 -9
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +234 -0
- package/src/mem_pools/tx_pool_v2/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +2 -2
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +51 -5
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +90 -77
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/timestamp_validator.ts +19 -14
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +2 -2
- package/src/services/libp2p/libp2p_service.ts +70 -37
- package/src/services/reqresp/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +13 -3
- package/src/services/service.ts +20 -0
- package/src/services/tx_collection/config.ts +26 -0
- package/src/services/tx_collection/fast_tx_collection.ts +14 -2
- package/src/services/tx_collection/file_store_tx_collection.ts +152 -0
- package/src/services/tx_collection/file_store_tx_source.ts +70 -0
- package/src/services/tx_collection/index.ts +1 -0
- package/src/services/tx_collection/slow_tx_collection.ts +55 -26
- package/src/services/tx_collection/tx_collection.ts +78 -12
- package/src/services/tx_collection/tx_collection_sink.ts +17 -7
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +4 -4
- package/src/services/tx_provider.ts +8 -7
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +133 -3
- package/src/test-helpers/testbench-utils.ts +100 -40
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
|
@@ -5,13 +5,13 @@ import { elapsed } from '@aztec/foundation/timer';
|
|
|
5
5
|
import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
|
|
6
6
|
import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
8
|
-
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
8
|
+
import { type BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
9
9
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
10
10
|
|
|
11
11
|
import type { PeerId } from '@libp2p/interface';
|
|
12
12
|
|
|
13
13
|
import type { P2PClient } from '../client/p2p_client.js';
|
|
14
|
-
import type {
|
|
14
|
+
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
15
15
|
import type { FastCollectionRequestInput, TxCollection } from './tx_collection/tx_collection.js';
|
|
16
16
|
import { TxProviderInstrumentation } from './tx_provider_instrumentation.js';
|
|
17
17
|
|
|
@@ -24,7 +24,7 @@ export class TxProvider implements ITxProvider {
|
|
|
24
24
|
|
|
25
25
|
constructor(
|
|
26
26
|
private txCollection: TxCollection,
|
|
27
|
-
private txPool:
|
|
27
|
+
private txPool: TxPoolV2,
|
|
28
28
|
private txValidator: Pick<P2PClient, 'validate'>,
|
|
29
29
|
private log: Logger = createLogger('p2p:tx-collector'),
|
|
30
30
|
client: TelemetryClient = getTelemetryClient(),
|
|
@@ -144,6 +144,7 @@ export class TxProvider implements ITxProvider {
|
|
|
144
144
|
// Take txs from the proposal body if there are any
|
|
145
145
|
// Note that we still have to validate these txs, but we do it in parallel with tx collection
|
|
146
146
|
const proposal = request.type === 'proposal' ? request.blockProposal : undefined;
|
|
147
|
+
const proposalBlockHeader = proposal?.blockHeader;
|
|
147
148
|
const txsFromProposal = this.extractFromProposal(proposal, [...missingTxHashes]);
|
|
148
149
|
if (txsFromProposal.length > 0) {
|
|
149
150
|
this.instrumentation.incTxsFromProposals(txsFromProposal.length);
|
|
@@ -155,7 +156,7 @@ export class TxProvider implements ITxProvider {
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
if (missingTxHashes.size === 0) {
|
|
158
|
-
await this.processProposalTxs(txsFromProposal);
|
|
159
|
+
await this.processProposalTxs(txsFromProposal, proposalBlockHeader!);
|
|
159
160
|
this.instrumentation.incTxsFromP2P(0, txHashes.length);
|
|
160
161
|
return { txsFromMempool, txsFromProposal };
|
|
161
162
|
}
|
|
@@ -163,7 +164,7 @@ export class TxProvider implements ITxProvider {
|
|
|
163
164
|
// Start tx collection from the network if needed, while we validate the txs taken from the proposal in parallel
|
|
164
165
|
const [txsFromNetwork] = await Promise.all([
|
|
165
166
|
this.collectFromP2P(request, [...missingTxHashes], opts),
|
|
166
|
-
this.processProposalTxs(txsFromProposal),
|
|
167
|
+
this.processProposalTxs(txsFromProposal, proposalBlockHeader!),
|
|
167
168
|
] as const);
|
|
168
169
|
|
|
169
170
|
if (txsFromNetwork.length > 0) {
|
|
@@ -222,11 +223,11 @@ export class TxProvider implements ITxProvider {
|
|
|
222
223
|
return compactArray(proposal.txs ?? []).filter(tx => missingTxHashes.includes(tx.getTxHash().toString()));
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
private async processProposalTxs(txs: Tx[]): Promise<void> {
|
|
226
|
+
private async processProposalTxs(txs: Tx[], blockHeader: BlockHeader): Promise<void> {
|
|
226
227
|
if (txs.length === 0) {
|
|
227
228
|
return;
|
|
228
229
|
}
|
|
229
230
|
await this.txValidator.validate(txs);
|
|
230
|
-
await this.txPool.
|
|
231
|
+
await this.txPool.addProtectedTxs(txs, blockHeader);
|
|
231
232
|
}
|
|
232
233
|
}
|
|
@@ -13,7 +13,7 @@ import { createP2PClient } from '../client/index.js';
|
|
|
13
13
|
import type { P2PClient } from '../client/p2p_client.js';
|
|
14
14
|
import type { P2PConfig } from '../config.js';
|
|
15
15
|
import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
16
|
-
import type {
|
|
16
|
+
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
17
17
|
import { generatePeerIdPrivateKeys } from '../test-helpers/generate-peer-id-private-keys.js';
|
|
18
18
|
import { getPorts } from './get-ports.js';
|
|
19
19
|
import { makeEnrs } from './make-enrs.js';
|
|
@@ -22,7 +22,7 @@ import { AlwaysFalseCircuitVerifier, AlwaysTrueCircuitVerifier } from './reqresp
|
|
|
22
22
|
|
|
23
23
|
export interface MakeTestP2PClientOptions {
|
|
24
24
|
mockAttestationPool: AttestationPool;
|
|
25
|
-
mockTxPool:
|
|
25
|
+
mockTxPool: TxPoolV2;
|
|
26
26
|
mockEpochCache: EpochCache;
|
|
27
27
|
mockWorldState: WorldStateSynchronizer;
|
|
28
28
|
alwaysTrueVerifier?: boolean;
|
|
@@ -108,7 +108,7 @@ export async function makeTestP2PClient(
|
|
|
108
108
|
undefined,
|
|
109
109
|
undefined,
|
|
110
110
|
{
|
|
111
|
-
txPool: mockTxPool as unknown as
|
|
111
|
+
txPool: mockTxPool as unknown as TxPoolV2,
|
|
112
112
|
attestationPool: mockAttestationPool as unknown as AttestationPool,
|
|
113
113
|
store: kvStore,
|
|
114
114
|
logger,
|
|
@@ -19,8 +19,20 @@ import {
|
|
|
19
19
|
|
|
20
20
|
import type { P2PConfig } from '../config.js';
|
|
21
21
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
22
|
-
import { DummyPeerDiscoveryService, DummyPeerManager,
|
|
23
|
-
import type {
|
|
22
|
+
import { DummyPeerDiscoveryService, DummyPeerManager, LibP2PService } from '../services/index.js';
|
|
23
|
+
import type { P2PReqRespConfig } from '../services/reqresp/config.js';
|
|
24
|
+
import type { ConnectionSampler } from '../services/reqresp/connection-sampler/connection_sampler.js';
|
|
25
|
+
import {
|
|
26
|
+
type ReqRespInterface,
|
|
27
|
+
type ReqRespResponse,
|
|
28
|
+
type ReqRespSubProtocol,
|
|
29
|
+
type ReqRespSubProtocolHandler,
|
|
30
|
+
type ReqRespSubProtocolHandlers,
|
|
31
|
+
type ReqRespSubProtocolValidators,
|
|
32
|
+
type SubProtocolMap,
|
|
33
|
+
responseFromBuffer,
|
|
34
|
+
} from '../services/reqresp/interface.js';
|
|
35
|
+
import { ReqRespStatus } from '../services/reqresp/status.js';
|
|
24
36
|
import { GossipSubEvent } from '../types/index.js';
|
|
25
37
|
import type { PubSubLibp2p } from '../util.js';
|
|
26
38
|
|
|
@@ -52,7 +64,7 @@ export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
|
|
|
52
64
|
deps.logger.verbose('Creating mock PubSub service');
|
|
53
65
|
const libp2p = new MockPubSub(peerId, network);
|
|
54
66
|
const peerManager = new DummyPeerManager(peerId, network);
|
|
55
|
-
const reqresp: ReqRespInterface = new
|
|
67
|
+
const reqresp: ReqRespInterface = new MockReqResp(peerId, network);
|
|
56
68
|
const peerDiscoveryService = new DummyPeerDiscoveryService();
|
|
57
69
|
const service = new LibP2PService<T>(
|
|
58
70
|
clientType as T,
|
|
@@ -74,6 +86,115 @@ export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
|
|
|
74
86
|
};
|
|
75
87
|
}
|
|
76
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Mock implementation of ReqRespInterface that routes requests to other peers' handlers through the mock network.
|
|
91
|
+
* When a peer calls sendBatchRequest, the mock iterates over network peers and invokes their registered handler
|
|
92
|
+
* for the sub-protocol, simulating the request-response protocol without actual libp2p streams.
|
|
93
|
+
*/
|
|
94
|
+
class MockReqResp implements ReqRespInterface {
|
|
95
|
+
private handlers: Partial<ReqRespSubProtocolHandlers> = {};
|
|
96
|
+
private logger = createLogger('p2p:test:mock-reqresp');
|
|
97
|
+
|
|
98
|
+
constructor(
|
|
99
|
+
private peerId: PeerId,
|
|
100
|
+
private network: MockGossipSubNetwork,
|
|
101
|
+
) {
|
|
102
|
+
network.registerReqRespPeer(this);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
updateConfig(_config: Partial<P2PReqRespConfig>): void {}
|
|
106
|
+
|
|
107
|
+
start(
|
|
108
|
+
subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
|
|
109
|
+
_subProtocolValidators: ReqRespSubProtocolValidators,
|
|
110
|
+
): Promise<void> {
|
|
111
|
+
Object.assign(this.handlers, subProtocolHandlers);
|
|
112
|
+
return Promise.resolve();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
addSubProtocol(
|
|
116
|
+
subProtocol: ReqRespSubProtocol,
|
|
117
|
+
handler: ReqRespSubProtocolHandler,
|
|
118
|
+
_validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
119
|
+
): Promise<void> {
|
|
120
|
+
this.handlers[subProtocol] = handler;
|
|
121
|
+
return Promise.resolve();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
stop(): Promise<void> {
|
|
125
|
+
this.handlers = {};
|
|
126
|
+
return Promise.resolve();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getHandler(subProtocol: ReqRespSubProtocol): ReqRespSubProtocolHandler | undefined {
|
|
130
|
+
return this.handlers[subProtocol];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
134
|
+
subProtocol: SubProtocol,
|
|
135
|
+
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
136
|
+
pinnedPeer: PeerId | undefined,
|
|
137
|
+
_timeoutMs?: number,
|
|
138
|
+
_maxPeers?: number,
|
|
139
|
+
_maxRetryAttempts?: number,
|
|
140
|
+
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
|
|
141
|
+
const responses: InstanceType<SubProtocolMap[SubProtocol]['response']>[] = [];
|
|
142
|
+
const peers = this.network.getReqRespPeers().filter(p => !p.peerId.equals(this.peerId));
|
|
143
|
+
const targetPeers = pinnedPeer ? peers.filter(p => p.peerId.equals(pinnedPeer)) : peers;
|
|
144
|
+
|
|
145
|
+
for (const request of requests) {
|
|
146
|
+
const requestBuffer = request.toBuffer();
|
|
147
|
+
for (const peer of targetPeers) {
|
|
148
|
+
const handler = peer.getHandler(subProtocol);
|
|
149
|
+
if (!handler) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const responseBuffer = await handler(this.peerId, requestBuffer);
|
|
154
|
+
if (responseBuffer.length > 0) {
|
|
155
|
+
const response = responseFromBuffer(subProtocol, responseBuffer);
|
|
156
|
+
responses.push(response as InstanceType<SubProtocolMap[SubProtocol]['response']>);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
this.logger.debug(`Mock reqresp handler error from peer ${peer.peerId}`, { err });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return responses;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async sendRequestToPeer(
|
|
169
|
+
peerId: PeerId,
|
|
170
|
+
subProtocol: ReqRespSubProtocol,
|
|
171
|
+
payload: Buffer,
|
|
172
|
+
_dialTimeout?: number,
|
|
173
|
+
): Promise<ReqRespResponse> {
|
|
174
|
+
const peer = this.network.getReqRespPeers().find(p => p.peerId.equals(peerId));
|
|
175
|
+
const handler = peer?.getHandler(subProtocol);
|
|
176
|
+
if (!handler) {
|
|
177
|
+
return { status: ReqRespStatus.SUCCESS, data: Buffer.from([]) };
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
const data = await handler(this.peerId, payload);
|
|
181
|
+
return { status: ReqRespStatus.SUCCESS, data };
|
|
182
|
+
} catch {
|
|
183
|
+
return { status: ReqRespStatus.FAILURE };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'> {
|
|
188
|
+
return {
|
|
189
|
+
getPeerListSortedByConnectionCountAsc: () =>
|
|
190
|
+
this.network
|
|
191
|
+
.getReqRespPeers()
|
|
192
|
+
.filter(p => !p.peerId.equals(this.peerId))
|
|
193
|
+
.map(p => p.peerId),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
77
198
|
/**
|
|
78
199
|
* Implementation of PubSub services that relies on a mock gossip sub network.
|
|
79
200
|
* This is used in tests to simulate a gossip sub network without needing a real P2P network.
|
|
@@ -157,6 +278,7 @@ class MockGossipSubService extends TypedEventEmitter<GossipsubEvents> implements
|
|
|
157
278
|
*/
|
|
158
279
|
export class MockGossipSubNetwork {
|
|
159
280
|
private peers: MockGossipSubService[] = [];
|
|
281
|
+
private reqRespPeers: MockReqResp[] = [];
|
|
160
282
|
private nextMsgId = 0;
|
|
161
283
|
|
|
162
284
|
private logger = createLogger('p2p:test:mock-gossipsub-network');
|
|
@@ -169,6 +291,14 @@ export class MockGossipSubNetwork {
|
|
|
169
291
|
this.peers.push(peer);
|
|
170
292
|
}
|
|
171
293
|
|
|
294
|
+
public registerReqRespPeer(peer: MockReqResp): void {
|
|
295
|
+
this.reqRespPeers.push(peer);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
public getReqRespPeers(): MockReqResp[] {
|
|
299
|
+
return this.reqRespPeers;
|
|
300
|
+
}
|
|
301
|
+
|
|
172
302
|
public publishToPeers(topic: TopicStr, data: Uint8Array, sender: PeerId): void {
|
|
173
303
|
const msgId = (this.nextMsgId++).toString();
|
|
174
304
|
this.logger.debug(`Network is distributing message on topic ${topic}`, {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import {
|
|
2
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { L2Block, L2BlockId } from '@aztec/stdlib/block';
|
|
4
5
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
5
6
|
import type {
|
|
6
7
|
BlockProposal,
|
|
@@ -13,14 +14,16 @@ import { type BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
|
13
14
|
import EventEmitter from 'events';
|
|
14
15
|
|
|
15
16
|
import type { TryAddResult } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
16
|
-
import type {
|
|
17
|
+
import type { AddTxsResult, TxPoolV2, TxPoolV2Config } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
18
|
+
import type { TxState } from '../mem_pools/tx_pool_v2/tx_metadata.js';
|
|
17
19
|
import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.js';
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* In-memory TxPool implementation for testing.
|
|
21
23
|
* Provides basic tx storage without persistence.
|
|
24
|
+
* Implements TxPoolV2 interface with stub implementations for testing.
|
|
22
25
|
*/
|
|
23
|
-
export class InMemoryTxPool extends EventEmitter implements
|
|
26
|
+
export class InMemoryTxPool extends EventEmitter implements TxPoolV2 {
|
|
24
27
|
private txsByHash = new Map<string, Tx>();
|
|
25
28
|
private logger: Logger | null = null;
|
|
26
29
|
|
|
@@ -54,63 +57,106 @@ export class InMemoryTxPool extends EventEmitter implements TxPool {
|
|
|
54
57
|
this.removeAllListeners();
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
// === Core Operations (TxPoolV2) ===
|
|
61
|
+
|
|
62
|
+
addPendingTxs(txs: Tx[], opts?: { source?: string }): Promise<AddTxsResult> {
|
|
63
|
+
const accepted: TxHash[] = [];
|
|
58
64
|
const newTxs: Tx[] = [];
|
|
59
|
-
let added = 0;
|
|
60
65
|
for (const tx of txs) {
|
|
61
66
|
const key = tx.getTxHash().toString();
|
|
62
67
|
if (!this.txsByHash.has(key)) {
|
|
63
68
|
newTxs.push(tx);
|
|
64
|
-
|
|
69
|
+
accepted.push(tx.getTxHash());
|
|
65
70
|
}
|
|
66
71
|
this.txsByHash.set(key, tx);
|
|
67
72
|
}
|
|
68
73
|
if (newTxs.length > 0) {
|
|
69
74
|
this.emit('txs-added', { txs: newTxs, source: opts?.source });
|
|
70
75
|
}
|
|
71
|
-
return Promise.resolve(
|
|
76
|
+
return Promise.resolve({ accepted, ignored: [], rejected: [] });
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored' | 'rejected'> {
|
|
80
|
+
const key = tx.getTxHash().toString();
|
|
81
|
+
if (this.txsByHash.has(key)) {
|
|
82
|
+
return Promise.resolve('ignored');
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve('accepted');
|
|
76
85
|
}
|
|
77
86
|
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
addProtectedTxs(txs: Tx[], _block: BlockHeader, opts?: { source?: string }): Promise<void> {
|
|
88
|
+
for (const tx of txs) {
|
|
89
|
+
const key = tx.getTxHash().toString();
|
|
90
|
+
this.txsByHash.set(key, tx);
|
|
91
|
+
}
|
|
92
|
+
if (txs.length > 0) {
|
|
93
|
+
this.emit('txs-added', { txs, source: opts?.source });
|
|
94
|
+
}
|
|
95
|
+
return Promise.resolve();
|
|
83
96
|
}
|
|
84
97
|
|
|
85
|
-
|
|
86
|
-
|
|
98
|
+
protectTxs(txHashes: TxHash[], _block: BlockHeader): Promise<TxHash[]> {
|
|
99
|
+
const notFound: TxHash[] = [];
|
|
100
|
+
for (const txHash of txHashes) {
|
|
101
|
+
if (!this.txsByHash.has(txHash.toString())) {
|
|
102
|
+
notFound.push(txHash);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return Promise.resolve(notFound);
|
|
87
106
|
}
|
|
88
107
|
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
addMinedTxs(txs: Tx[], _block: BlockHeader, _opts?: { source?: string }): Promise<void> {
|
|
109
|
+
for (const tx of txs) {
|
|
110
|
+
const key = tx.getTxHash().toString();
|
|
111
|
+
this.txsByHash.set(key, tx);
|
|
112
|
+
}
|
|
113
|
+
return Promise.resolve();
|
|
91
114
|
}
|
|
92
115
|
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
// === State Transition Handlers (TxPoolV2) ===
|
|
117
|
+
|
|
118
|
+
handleMinedBlock(_block: L2Block): Promise<void> {
|
|
119
|
+
return Promise.resolve();
|
|
95
120
|
}
|
|
96
121
|
|
|
97
|
-
|
|
122
|
+
prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
|
|
123
|
+
return Promise.resolve();
|
|
124
|
+
}
|
|
98
125
|
|
|
99
|
-
|
|
126
|
+
handlePrunedBlocks(_latestBlock: L2BlockId): Promise<void> {
|
|
127
|
+
return Promise.resolve();
|
|
128
|
+
}
|
|
100
129
|
|
|
101
|
-
|
|
130
|
+
handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
102
131
|
for (const txHash of txHashes) {
|
|
103
132
|
this.txsByHash.delete(txHash.toString());
|
|
104
133
|
}
|
|
105
134
|
return Promise.resolve();
|
|
106
135
|
}
|
|
107
136
|
|
|
108
|
-
|
|
109
|
-
return Promise.resolve(
|
|
137
|
+
handleFinalizedBlock(_block: BlockHeader): Promise<void> {
|
|
138
|
+
return Promise.resolve();
|
|
110
139
|
}
|
|
111
140
|
|
|
112
|
-
|
|
113
|
-
|
|
141
|
+
// === Query Operations (TxPoolV2) ===
|
|
142
|
+
|
|
143
|
+
getTxByHash(hash: TxHash): Promise<Tx | undefined> {
|
|
144
|
+
return Promise.resolve(this.txsByHash.get(hash.toString()));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getTxsByHash(hashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
148
|
+
const result = hashes.map(h => this.txsByHash.get(h.toString()));
|
|
149
|
+
const found = result.filter(tx => tx !== undefined).length;
|
|
150
|
+
this.logger?.debug(`[TxPool] getTxsByHash: requested ${hashes.length}, found ${found}`);
|
|
151
|
+
return Promise.resolve(result);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
hasTxs(hashes: TxHash[]): Promise<boolean[]> {
|
|
155
|
+
return Promise.resolve(hashes.map(h => this.txsByHash.has(h.toString())));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getArchivedTxByHash(_hash: TxHash): Promise<Tx | undefined> {
|
|
159
|
+
return Promise.resolve(undefined);
|
|
114
160
|
}
|
|
115
161
|
|
|
116
162
|
getPendingTxHashes(): Promise<TxHash[]> {
|
|
@@ -121,26 +167,40 @@ export class InMemoryTxPool extends EventEmitter implements TxPool {
|
|
|
121
167
|
return Promise.resolve(this.txsByHash.size);
|
|
122
168
|
}
|
|
123
169
|
|
|
124
|
-
getMinedTxHashes(): Promise<[
|
|
170
|
+
getMinedTxHashes(): Promise<[TxHash, L2BlockId][]> {
|
|
125
171
|
return Promise.resolve([]);
|
|
126
172
|
}
|
|
127
173
|
|
|
128
|
-
|
|
129
|
-
return Promise.resolve(
|
|
174
|
+
getMinedTxCount(): Promise<number> {
|
|
175
|
+
return Promise.resolve(0);
|
|
130
176
|
}
|
|
131
177
|
|
|
132
|
-
|
|
178
|
+
getTxStatus(hash: TxHash): Promise<TxState | 'deleted' | undefined> {
|
|
179
|
+
return Promise.resolve(this.txsByHash.has(hash.toString()) ? 'pending' : undefined);
|
|
180
|
+
}
|
|
133
181
|
|
|
134
182
|
isEmpty(): Promise<boolean> {
|
|
135
183
|
return Promise.resolve(this.txsByHash.size === 0);
|
|
136
184
|
}
|
|
137
185
|
|
|
138
|
-
|
|
186
|
+
getLowestPriorityPending(_limit: number): Promise<TxHash[]> {
|
|
187
|
+
return Promise.resolve([]);
|
|
188
|
+
}
|
|
139
189
|
|
|
140
|
-
|
|
190
|
+
// === Configuration (TxPoolV2) ===
|
|
141
191
|
|
|
142
|
-
|
|
143
|
-
return Promise.resolve(
|
|
192
|
+
updateConfig(_config: Partial<TxPoolV2Config>): Promise<void> {
|
|
193
|
+
return Promise.resolve();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// === Lifecycle (TxPoolV2) ===
|
|
197
|
+
|
|
198
|
+
start(): Promise<void> {
|
|
199
|
+
return Promise.resolve();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
stop(): Promise<void> {
|
|
203
|
+
return Promise.resolve();
|
|
144
204
|
}
|
|
145
205
|
}
|
|
146
206
|
|
|
@@ -155,10 +215,10 @@ export class InMemoryAttestationPool {
|
|
|
155
215
|
const id = blockProposal.archive.toString();
|
|
156
216
|
const alreadyExists = this.proposals.has(id);
|
|
157
217
|
if (alreadyExists) {
|
|
158
|
-
return Promise.resolve({ added: false, alreadyExists: true,
|
|
218
|
+
return Promise.resolve({ added: false, alreadyExists: true, count: 1 });
|
|
159
219
|
}
|
|
160
220
|
this.proposals.set(id, blockProposal);
|
|
161
|
-
return Promise.resolve({ added: true, alreadyExists: false,
|
|
221
|
+
return Promise.resolve({ added: true, alreadyExists: false, count: 1 });
|
|
162
222
|
}
|
|
163
223
|
|
|
164
224
|
getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
@@ -166,7 +226,7 @@ export class InMemoryAttestationPool {
|
|
|
166
226
|
}
|
|
167
227
|
|
|
168
228
|
tryAddCheckpointProposal(_proposal: CheckpointProposal): Promise<TryAddResult> {
|
|
169
|
-
return Promise.resolve({ added: true, alreadyExists: false,
|
|
229
|
+
return Promise.resolve({ added: true, alreadyExists: false, count: 1 });
|
|
170
230
|
}
|
|
171
231
|
|
|
172
232
|
getCheckpointProposal(_id: string): Promise<CheckpointProposalCore | undefined> {
|
|
@@ -188,8 +248,8 @@ export class InMemoryAttestationPool {
|
|
|
188
248
|
return Promise.resolve([]);
|
|
189
249
|
}
|
|
190
250
|
|
|
191
|
-
tryAddCheckpointAttestation(_attestation: CheckpointAttestation
|
|
192
|
-
return Promise.resolve({ added: true, alreadyExists: false,
|
|
251
|
+
tryAddCheckpointAttestation(_attestation: CheckpointAttestation): Promise<TryAddResult> {
|
|
252
|
+
return Promise.resolve({ added: true, alreadyExists: false, count: 1 });
|
|
193
253
|
}
|
|
194
254
|
|
|
195
255
|
isEmpty(): Promise<boolean> {
|
|
@@ -144,7 +144,7 @@ class TestLibP2PService<T extends P2PClientType = P2PClientType.Full> extends Li
|
|
|
144
144
|
const txHash = tx.getTxHash();
|
|
145
145
|
const txHashString = txHash.toString();
|
|
146
146
|
this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()}.`);
|
|
147
|
-
await this.mempools.txPool.
|
|
147
|
+
await this.mempools.txPool.addPendingTxs([tx]);
|
|
148
148
|
} else {
|
|
149
149
|
await super.handleGossipedTx(payload, msgId, source);
|
|
150
150
|
}
|