diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index ed385d5bc83e..303ef0142f19 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -332,7 +332,17 @@ export class P2PClient * Uses the batched Request Response protocol to request a set of transactions from the network. */ public async requestTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> { - const txs = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes); + const timeoutMs = 8000; // Longer timeout for now + const maxPeers = Math.min(Math.ceil(txHashes.length / 3), 10); + const maxRetryAttempts = 10; // Keep retrying within the timeout + + const txs = await this.p2pService.sendBatchRequest( + ReqRespSubProtocol.TX, + txHashes, + timeoutMs, + maxPeers, + maxRetryAttempts, + ); // Some transactions may return undefined, so we filter them out const filteredTxs = txs.filter((tx): tx is Tx => !!tx); diff --git a/yarn-project/p2p/src/services/reqresp/reqresp.ts b/yarn-project/p2p/src/services/reqresp/reqresp.ts index 85101daf19b5..3c13fdeced1b 100644 --- a/yarn-project/p2p/src/services/reqresp/reqresp.ts +++ b/yarn-project/p2p/src/services/reqresp/reqresp.ts @@ -262,7 +262,7 @@ export class ReqResp { subProtocol: SubProtocol, requests: InstanceType[], timeoutMs = 10000, - maxPeers = Math.min(10, requests.length), + maxPeers = Math.max(10, Math.ceil(requests.length / 3)), maxRetryAttempts = 3, ): Promise<(InstanceType | undefined)[]> { const responseValidator = this.subProtocolValidators[subProtocol]; diff --git a/yarn-project/p2p/src/services/service.ts b/yarn-project/p2p/src/services/service.ts index dddf3bdc727d..8bc0b1171334 100644 --- a/yarn-project/p2p/src/services/service.ts +++ b/yarn-project/p2p/src/services/service.ts @@ -56,6 +56,9 @@ export interface P2PService { sendBatchRequest( protocol: Protocol, requests: InstanceType[], + timeoutMs?: number, + maxPeers?: number, + maxRetryAttempts?: number, ): Promise<(InstanceType | undefined)[]>; // Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963