File tree Expand file tree Collapse file tree 5 files changed +45
-4
lines changed Expand file tree Collapse file tree 5 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -444,9 +444,9 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
444
444
* @param txHashes - The hashes of the transactions to request.
445
445
* @returns A promise that resolves to an array of transactions or undefined.
446
446
*/
447
- public requestTxs ( txHashes : TxHash [ ] ) : Promise < ( Tx | undefined ) [ ] > {
448
- const requestPromises = txHashes . map ( txHash => this . requestTxByHash ( txHash ) ) ;
449
- return Promise . all ( requestPromises ) ;
447
+ public async requestTxs ( txHashes : TxHash [ ] ) : Promise < ( Tx | undefined ) [ ] > {
448
+ const res = await this . p2pService . sendBatchRequest ( ReqRespSubProtocol . TX , txHashes ) ;
449
+ return Promise . resolve ( res ?? [ ] ) ;
450
450
}
451
451
452
452
/**
Original file line number Diff line number Diff line change @@ -61,6 +61,19 @@ export class DummyP2PService implements P2PService {
61
61
return Promise . resolve ( undefined ) ;
62
62
}
63
63
64
+ /**
65
+ * Sends a batch request to a peer.
66
+ * @param _protocol - The protocol to send the request on.
67
+ * @param _requests - The requests to send.
68
+ * @returns The responses from the peer, otherwise undefined.
69
+ */
70
+ public sendBatchRequest < Protocol extends ReqRespSubProtocol > (
71
+ _protocol : Protocol ,
72
+ _requests : InstanceType < SubProtocolMap [ Protocol ] [ 'request' ] > [ ] ,
73
+ ) : Promise < InstanceType < SubProtocolMap [ Protocol ] [ 'response' ] > [ ] > {
74
+ return Promise . resolve ( [ ] ) ;
75
+ }
76
+
64
77
/**
65
78
* Returns the ENR of the peer.
66
79
* @returns The ENR of the peer, otherwise undefined.
Original file line number Diff line number Diff line change @@ -400,6 +400,19 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
400
400
return this . reqresp . sendRequest ( protocol , request ) ;
401
401
}
402
402
403
+ /**
404
+ * Send a batch of requests to peers, and return the responses
405
+ * @param protocol - The request response protocol to use
406
+ * @param requests - The requests to send to the peers
407
+ * @returns The responses to the requests
408
+ */
409
+ sendBatchRequest < SubProtocol extends ReqRespSubProtocol > (
410
+ protocol : SubProtocol ,
411
+ requests : InstanceType < SubProtocolMap [ SubProtocol ] [ 'request' ] > [ ] ,
412
+ ) : Promise < InstanceType < SubProtocolMap [ SubProtocol ] [ 'response' ] > [ ] | undefined > {
413
+ return this . reqresp . sendBatchRequest ( protocol , requests ) ;
414
+ }
415
+
403
416
/**
404
417
* Get the ENR of the node
405
418
* @returns The ENR of the node
Original file line number Diff line number Diff line change @@ -112,7 +112,10 @@ export const DEFAULT_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
112
112
* The Request Response Pair interface defines the methods that each
113
113
* request response pair must implement
114
114
*/
115
- interface RequestResponsePair < Req , Res > {
115
+ interface RequestResponsePair < Req extends { toBuffer ( ) : Buffer } , Res > {
116
+ /**
117
+ * The request must implement the toBuffer method (generic serialisation)
118
+ */
116
119
request : new ( ...args : any [ ] ) => Req ;
117
120
/**
118
121
* The response must implement the static fromBuffer method (generic serialisation)
Original file line number Diff line number Diff line change @@ -45,6 +45,18 @@ export interface P2PService {
45
45
request : InstanceType < SubProtocolMap [ Protocol ] [ 'request' ] > ,
46
46
) : Promise < InstanceType < SubProtocolMap [ Protocol ] [ 'response' ] > | undefined > ;
47
47
48
+ /**
49
+ * Send a batch of requests to peers, and return the responses
50
+ *
51
+ * @param protocol - The request response protocol to use
52
+ * @param requests - The requests to send to the peers
53
+ * @returns The responses to the requests
54
+ */
55
+ sendBatchRequest < Protocol extends ReqRespSubProtocol > (
56
+ protocol : Protocol ,
57
+ requests : InstanceType < SubProtocolMap [ Protocol ] [ 'request' ] > [ ] ,
58
+ ) : Promise < InstanceType < SubProtocolMap [ Protocol ] [ 'response' ] > [ ] | undefined > ;
59
+
48
60
// Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963
49
61
registerBlockReceivedCallback ( callback : ( block : BlockProposal ) => Promise < BlockAttestation | undefined > ) : void ;
50
62
You can’t perform that action at this time.
0 commit comments