Skip to content

Commit db4bd98

Browse files
authored
refactor(p2p): remove unused sendBatchRequest (#23273)
`sendBatchRequest` became unused after removing the slow tx flow and the old tx reqresp method. This PR removes sendBatchRequest and cleans up code that becomes unused. It does NOT remove subprotocol validator registration/etc from reqresp. This might be done in a follow-up depending on how https://linear.app/aztec-labs/issue/A-1014/block-txs-reqresp-validator-validaterequestedblocktxs-is-never-invoked becomes solved.
1 parent 437eacb commit db4bd98

14 files changed

Lines changed: 12 additions & 993 deletions

File tree

yarn-project/p2p/src/client/p2p_client.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ describe('P2P Client', () => {
4141
txPool.addPendingTxs.mockResolvedValue({ accepted: [], ignored: [], rejected: [] });
4242

4343
p2pService = mock<P2PService>();
44-
p2pService.sendBatchRequest.mockResolvedValue([]);
4544

4645
l1Constants = EmptyL1RollupConstants;
4746
txCollection = mock<TxCollection>();

yarn-project/p2p/src/client/test/p2p_client.integration_reqresp.test.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -113,44 +113,6 @@ describe('p2p client integration reqresp', () => {
113113
return (p2pService as any).node.peerId;
114114
};
115115

116-
it('can request txs from peers via mock reqresp', async () => {
117-
const numberOfNodes = 2;
118-
const mockGossipSubNetwork = new MockGossipSubNetwork();
119-
120-
const testConfig = {
121-
p2pBaseConfig: { ...p2pBaseConfig, rollupVersion: 1 },
122-
mockAttestationPool: attestationPool,
123-
mockTxPool: txPool,
124-
mockEpochCache: epochCache,
125-
mockWorldState: worldState,
126-
alwaysTrueVerifier: true,
127-
mockGossipSubNetwork,
128-
logger,
129-
};
130-
131-
const clientsAndConfig = await makeAndStartTestP2PClients(numberOfNodes, testConfig);
132-
clients = clientsAndConfig.map(c => c.client);
133-
134-
await sleep(1000);
135-
136-
// Create a mock tx and configure the shared pool to return it
137-
const tx = await createMockTxWithMetadata(testConfig.p2pBaseConfig);
138-
const txHash = tx.getTxHash();
139-
140-
txPool.getTxByHash.mockImplementation((hash: TxHash) => Promise.resolve(hash.equals(txHash) ? tx : undefined));
141-
142-
// Request the tx from node-2, which will route to node-1 via the mock network
143-
const reqresp = getReqResp(clients[1]);
144-
const responses = await reqresp.sendBatchRequest(ReqRespSubProtocol.TX, [new TxHashArray(txHash)], undefined);
145-
146-
expect(responses).toHaveLength(1);
147-
const txArray = responses[0] as TxArray;
148-
expect(txArray).toHaveLength(1);
149-
150-
const receivedTxHash = txArray[0].getTxHash();
151-
expect(receivedTxHash.toString()).toEqual(txHash.toString());
152-
});
153-
154116
it('sendRequestToPeer routes to the correct peer handler', async () => {
155117
const numberOfNodes = 2;
156118
const mockGossipSubNetwork = new MockGossipSubNetwork();
@@ -197,36 +159,4 @@ describe('p2p client integration reqresp', () => {
197159
expect(receivedTxHash.toString()).toEqual(txHash.toString());
198160
}
199161
});
200-
201-
it('reqresp returns empty when peer has no matching txs', async () => {
202-
const numberOfNodes = 2;
203-
const mockGossipSubNetwork = new MockGossipSubNetwork();
204-
205-
const testConfig = {
206-
p2pBaseConfig: { ...p2pBaseConfig, rollupVersion: 1 },
207-
mockAttestationPool: attestationPool,
208-
mockTxPool: txPool,
209-
mockEpochCache: epochCache,
210-
mockWorldState: worldState,
211-
alwaysTrueVerifier: true,
212-
mockGossipSubNetwork,
213-
logger,
214-
};
215-
216-
const clientsAndConfig = await makeAndStartTestP2PClients(numberOfNodes, testConfig);
217-
clients = clientsAndConfig.map(c => c.client);
218-
219-
await sleep(1000);
220-
221-
// Request a random tx hash that no peer has
222-
const randomTxHash = TxHash.random();
223-
const reqresp = getReqResp(clients[1]);
224-
const responses = await reqresp.sendBatchRequest(ReqRespSubProtocol.TX, [new TxHashArray(randomTxHash)], undefined);
225-
226-
// The handler returns an empty TxArray (serialized as a 4-byte vector with count 0),
227-
// so sendBatchRequest includes it as a response with an empty TxArray.
228-
expect(responses).toHaveLength(1);
229-
const txArray = responses[0] as TxArray;
230-
expect(txArray).toHaveLength(0);
231-
});
232162
});

yarn-project/p2p/src/errors/reqresp.error.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,3 @@ export class IndividualReqRespTimeoutError extends Error {
88
super(`Request to peer timed out`);
99
}
1010
}
11-
12-
/** Collective request timeout error
13-
*
14-
* This error will be thrown when a req resp request times out regardless of the peer.
15-
* @category Errors
16-
*/
17-
export class CollectiveReqRespTimeoutError extends Error {
18-
constructor() {
19-
super(`Request to all peers timed out`);
20-
}
21-
}
22-
23-
/** Invalid response error
24-
*
25-
* This error will be thrown when a response is received that is not valid.
26-
*
27-
* This error does not need to be punished as message validators will handle punishing invalid
28-
* requests
29-
* @category Errors
30-
*/
31-
export class InvalidResponseError extends Error {
32-
constructor() {
33-
super(`Invalid response received`);
34-
}
35-
}

yarn-project/p2p/src/services/dummy_service.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,6 @@ export class DummyP2PService implements P2PService {
119119
return Promise.resolve(undefined);
120120
}
121121

122-
/**
123-
* Sends a batch request to a peer.
124-
* @param _protocol - The protocol to send the request on.
125-
* @param _requests - The requests to send.
126-
* @returns The responses from the peer, otherwise undefined.
127-
*/
128-
public sendBatchRequest<Protocol extends ReqRespSubProtocol>(
129-
_protocol: Protocol,
130-
_requests: InstanceType<SubProtocolMap[Protocol]['request']>[],
131-
): Promise<InstanceType<SubProtocolMap[Protocol]['response']>[]> {
132-
return Promise.resolve([]);
133-
}
134-
135122
public sendRequestToPeer(
136123
_peerId: PeerId,
137124
_subProtocol: ReqRespSubProtocol,
@@ -306,16 +293,6 @@ export class DummyReqResp implements ReqRespInterface {
306293
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']> | undefined> {
307294
return Promise.resolve(undefined);
308295
}
309-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
310-
_subProtocol: SubProtocol,
311-
_requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
312-
_pinnedPeer: PeerId | undefined,
313-
_timeoutMs?: number,
314-
_maxPeers?: number,
315-
_maxRetryAttempts?: number,
316-
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
317-
return Promise.resolve([]);
318-
}
319296
public sendRequestToPeer(
320297
_peerId: PeerId,
321298
_subProtocol: ReqRespSubProtocol,

yarn-project/p2p/src/services/libp2p/libp2p_service.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ import {
101101
type ReqRespSubProtocolHandlers,
102102
type ReqRespSubProtocolValidators,
103103
StatusMessage,
104-
type SubProtocolMap,
105104
ValidationError,
106105
pingHandler,
107106
reqGoodbyeHandler,
@@ -702,20 +701,6 @@ export class LibP2PService extends WithTracer implements P2PService {
702701
setImmediate(() => void safeJob());
703702
}
704703

705-
/**
706-
* Send a batch of requests to peers, and return the responses
707-
* @param protocol - The request response protocol to use
708-
* @param requests - The requests to send to the peers
709-
* @returns The responses to the requests
710-
*/
711-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
712-
protocol: SubProtocol,
713-
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
714-
pinnedPeerId: PeerId | undefined,
715-
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
716-
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
717-
}
718-
719704
public sendRequestToPeer(
720705
peerId: PeerId,
721706
subProtocol: ReqRespSubProtocol,

0 commit comments

Comments
 (0)