Skip to content

Commit

Permalink
feat: validator use batch request
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jan 19, 2025
1 parent 8bc9016 commit c0b32b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
* @param txHashes - The hashes of the transactions to request.
* @returns A promise that resolves to an array of transactions or undefined.
*/
public requestTxs(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
const requestPromises = txHashes.map(txHash => this.requestTxByHash(txHash));
return Promise.all(requestPromises);
public async requestTxs(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
const res = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes);
return Promise.resolve(res ?? []);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions yarn-project/p2p/src/services/libp2p/libp2p_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,19 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
return this.reqresp.sendRequest(protocol, request);
}

/**
* Send a batch of requests to peers, and return the responses
* @param protocol - The request response protocol to use
* @param requests - The requests to send to the peers
* @returns The responses to the requests
*/
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
protocol: SubProtocol,
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[] | undefined> {
return this.reqresp.sendBatchRequest(protocol, requests);
}

/**
* Get the ENR of the node
* @returns The ENR of the node
Expand Down
12 changes: 12 additions & 0 deletions yarn-project/p2p/src/services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ export interface P2PService {
request: InstanceType<SubProtocolMap[Protocol]['request']>,
): Promise<InstanceType<SubProtocolMap[Protocol]['response']> | undefined>;

/**
* Send a batch of requests to peers, and return the responses
*
* @param protocol - The request response protocol to use
* @param requests - The requests to send to the peers
* @returns The responses to the requests
*/
sendBatchRequest<Protocol extends ReqRespSubProtocol>(
protocol: Protocol,
requests: InstanceType<SubProtocolMap[Protocol]['request']>[],
): Promise<InstanceType<SubProtocolMap[Protocol]['response']>[] | undefined>;

// Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963
registerBlockReceivedCallback(callback: (block: BlockProposal) => Promise<BlockAttestation | undefined>): void;

Expand Down

0 comments on commit c0b32b7

Please sign in to comment.