From 614aac84cba163096d5ff5217048a466dda40324 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Fri, 18 Apr 2025 12:59:35 +0000 Subject: [PATCH 1/3] chore: bump retries for request tx by hash --- yarn-project/p2p/src/client/p2p_client.ts | 13 ++++++++++++- yarn-project/p2p/src/services/reqresp/reqresp.ts | 2 +- yarn-project/p2p/src/services/service.ts | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index ed385d5bc83e..b877b1426fad 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -332,7 +332,18 @@ 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); + // Set collective timeout based on the number of txs we are requesting + const timeoutMs = Math.min(8000, txHashes.length * 100); + 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 From 86bd4fcdf5f64392e116d7803eebca5b2260e689 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Wed, 30 Apr 2025 09:05:39 +0000 Subject: [PATCH 2/3] fix --- yarn-project/p2p/src/client/p2p_client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index b877b1426fad..9a5118290845 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -333,7 +333,7 @@ export class P2PClient */ public async requestTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> { // Set collective timeout based on the number of txs we are requesting - const timeoutMs = Math.min(8000, txHashes.length * 100); + const timeoutMs = Math.min(8000, Math.max(2000, txHashes.length * 100)); const maxPeers = Math.min(Math.ceil(txHashes.length / 3), 10); const maxRetryAttempts = 10; // Keep retrying within the timeout From a661bd540a8a77018e51efd6ec549b4cb1ebe064 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Wed, 30 Apr 2025 09:11:37 +0000 Subject: [PATCH 3/3] just use fixed timeout --- yarn-project/p2p/src/client/p2p_client.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index 9a5118290845..303ef0142f19 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -332,8 +332,7 @@ 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)[]> { - // Set collective timeout based on the number of txs we are requesting - const timeoutMs = Math.min(8000, Math.max(2000, txHashes.length * 100)); + 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