@aztec/p2p 1.2.1 → 2.0.0-nightly.20250813
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +5 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +29 -12
- package/dest/client/interface.d.ts +8 -13
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +18 -22
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +86 -83
- package/dest/config.d.ts +30 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +34 -1
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +13 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +117 -10
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +4 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +22 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +4 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +21 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -10
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +8 -3
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +64 -37
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +8 -3
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +18 -10
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -2
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +73 -44
- package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +2 -2
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -59
- package/dest/msg_validators/tx_validator/double_spend_validator.js +2 -2
- package/dest/msg_validators/tx_validator/gas_validator.js +4 -4
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +21 -21
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +3 -3
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +4 -1
- package/dest/services/dummy_service.d.ts +13 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +26 -3
- package/dest/services/index.d.ts +3 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +3 -1
- package/dest/services/libp2p/libp2p_service.d.ts +13 -20
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +123 -46
- package/dest/services/peer-manager/interface.d.ts +8 -1
- package/dest/services/peer-manager/interface.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts +70 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +369 -39
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +3 -3
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +3 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +35 -52
- package/dest/services/reqresp/index.d.ts +2 -1
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +61 -10
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +41 -6
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +5 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +28 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.js +3 -5
- package/dest/services/reqresp/protocols/index.d.ts +2 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/status.d.ts +2 -0
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -0
- package/dest/services/reqresp/protocols/tx.d.ts +12 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +37 -39
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +220 -220
- package/dest/services/reqresp/status.d.ts +8 -3
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +6 -2
- package/dest/services/service.d.ts +10 -10
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +58 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +295 -0
- package/dest/services/tx_collection/index.d.ts +3 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +2 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +34 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +176 -0
- package/dest/services/tx_collection/tx_collection.d.ts +109 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +127 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +81 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +49 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +206 -0
- package/dest/services/{tx_collect_instrumentation.d.ts → tx_provider_instrumentation.d.ts} +2 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/{tx_collect_instrumentation.js → tx_provider_instrumentation.js} +5 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +4 -3
- package/dest/test-helpers/mock-pubsub.d.ts +2 -1
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +2 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +8 -4
- package/dest/testbench/p2p_client_testbench_worker.js +11 -5
- package/dest/util.d.ts +1 -1
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -15
- package/src/client/factory.ts +87 -12
- package/src/client/interface.ts +19 -15
- package/src/client/p2p_client.ts +108 -92
- package/src/config.ts +52 -1
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +15 -1
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +155 -4
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +28 -1
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +28 -2
- package/src/mem_pools/attestation_pool/mocks.ts +1 -3
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +59 -41
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +19 -9
- package/src/mem_pools/tx_pool/tx_pool.ts +7 -2
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +63 -40
- package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
- package/src/msg_validators/tx_validator/data_validator.ts +36 -27
- package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +4 -4
- package/src/msg_validators/tx_validator/metadata_validator.ts +22 -28
- package/src/msg_validators/tx_validator/phases_validator.ts +2 -2
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -2
- package/src/services/discv5/discV5_service.ts +4 -1
- package/src/services/dummy_service.ts +44 -4
- package/src/services/index.ts +3 -1
- package/src/services/libp2p/libp2p_service.ts +147 -55
- package/src/services/peer-manager/interface.ts +10 -1
- package/src/services/peer-manager/peer_manager.ts +441 -41
- package/src/services/reqresp/config.ts +3 -3
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +38 -63
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +63 -17
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +24 -3
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +3 -3
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +20 -0
- package/src/services/reqresp/protocols/tx.ts +35 -6
- package/src/services/reqresp/rate-limiter/rate_limits.ts +20 -0
- package/src/services/reqresp/reqresp.ts +294 -264
- package/src/services/reqresp/status.ts +9 -3
- package/src/services/service.ts +23 -14
- package/src/services/tx_collection/config.ts +84 -0
- package/src/services/tx_collection/fast_tx_collection.ts +338 -0
- package/src/services/tx_collection/index.ts +2 -0
- package/src/services/tx_collection/instrumentation.ts +43 -0
- package/src/services/tx_collection/slow_tx_collection.ts +232 -0
- package/src/services/tx_collection/tx_collection.ts +214 -0
- package/src/services/tx_collection/tx_collection_sink.ts +98 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +215 -0
- package/src/services/{tx_collect_instrumentation.ts → tx_provider_instrumentation.ts} +5 -5
- package/src/test-helpers/make-test-p2p-clients.ts +4 -2
- package/src/test-helpers/mock-pubsub.ts +1 -0
- package/src/test-helpers/reqresp-nodes.ts +7 -1
- package/src/testbench/p2p_client_testbench_worker.ts +9 -2
- package/src/util.ts +1 -1
- package/dest/services/tx_collect_instrumentation.d.ts.map +0 -1
- package/dest/services/tx_collector.d.ts +0 -23
- package/dest/services/tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collector.js +0 -95
- package/src/services/tx_collector.ts +0 -134
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
+
import { TxArray } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import { BitVector } from './bitvector.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Request message for requesting specific transactions from a block
|
|
9
|
+
*/
|
|
10
|
+
export class BlockTxsRequest {
|
|
11
|
+
constructor(
|
|
12
|
+
readonly blockHash: Fr, // 32 byte hash of the proposed block header
|
|
13
|
+
// BitVector indicating which txs from the proposal we are requesting
|
|
14
|
+
// 1 means we want the tx, 0 means we don't
|
|
15
|
+
readonly txIndices: BitVector,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Deserializes the BlockTxRequest object from a Buffer
|
|
20
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
21
|
+
* @returns An instance of BlockTxRequest
|
|
22
|
+
*/
|
|
23
|
+
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
|
|
24
|
+
const reader = BufferReader.asReader(buffer);
|
|
25
|
+
const blockHash = Fr.fromBuffer(reader);
|
|
26
|
+
const txIndices = BitVector.fromBuffer(reader);
|
|
27
|
+
|
|
28
|
+
return new BlockTxsRequest(blockHash, txIndices);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Serializes the BlockTxRequest object into a Buffer
|
|
33
|
+
* @returns Buffer representation of the BlockTxRequest object
|
|
34
|
+
*/
|
|
35
|
+
toBuffer(): Buffer {
|
|
36
|
+
return serializeToBuffer([this.blockHash, this.txIndices.toBuffer()]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Response message containing requested transactions from a block
|
|
42
|
+
*/
|
|
43
|
+
export class BlockTxsResponse {
|
|
44
|
+
constructor(
|
|
45
|
+
readonly blockHash: Fr,
|
|
46
|
+
readonly txs: TxArray, // List of transactions we requested and peer has
|
|
47
|
+
// BitVector indicating which txs from the proposal are available at the peer
|
|
48
|
+
// 1 means the tx is available, 0 means it is not
|
|
49
|
+
readonly txIndices: BitVector,
|
|
50
|
+
) {}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Deserializes the BlockTxResponse object from a Buffer
|
|
54
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
55
|
+
* @returns An instance of BlockTxResponse
|
|
56
|
+
*/
|
|
57
|
+
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
|
|
58
|
+
const reader = BufferReader.asReader(buffer);
|
|
59
|
+
const blockHash = Fr.fromBuffer(reader);
|
|
60
|
+
const txs = TxArray.fromBuffer(reader);
|
|
61
|
+
const txIndices = BitVector.fromBuffer(reader);
|
|
62
|
+
|
|
63
|
+
return new BlockTxsResponse(blockHash, txs, txIndices);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Serializes the BlockTxResponse object into a Buffer
|
|
68
|
+
* @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
|
|
69
|
+
* thus we serialize it last
|
|
70
|
+
* @returns Buffer representation of the BlockTxResponse object
|
|
71
|
+
*/
|
|
72
|
+
toBuffer(): Buffer {
|
|
73
|
+
return serializeToBuffer([this.blockHash, this.txs.toBuffer(), this.txIndices.toBuffer()]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static empty(): BlockTxsResponse {
|
|
77
|
+
return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -90,14 +90,14 @@ export class GoodbyeProtocolHandler {
|
|
|
90
90
|
* @returns A resolved promise with the goodbye response.
|
|
91
91
|
*/
|
|
92
92
|
export function reqGoodbyeHandler(peerManager: PeerManagerInterface): ReqRespSubProtocolHandler {
|
|
93
|
-
return (peerId: PeerId,
|
|
94
|
-
const reason = decodeGoodbyeReason(
|
|
93
|
+
return (peerId: PeerId, msg: Buffer) => {
|
|
94
|
+
const reason = decodeGoodbyeReason(msg);
|
|
95
95
|
|
|
96
96
|
peerManager.goodbyeReceived(peerId, reason);
|
|
97
97
|
|
|
98
98
|
// NOTE: In the current implementation this won't be sent to peer,
|
|
99
99
|
// as the connection to peer has been already closed by peerManager.goodbyeReceived
|
|
100
100
|
// We have this just to satisfy interface
|
|
101
|
-
return Promise.resolve(Buffer.
|
|
101
|
+
return Promise.resolve(Buffer.alloc(0));
|
|
102
102
|
};
|
|
103
103
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
1
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
4
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
@@ -69,10 +70,29 @@ export class StatusMessage {
|
|
|
69
70
|
);
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
static random(): StatusMessage {
|
|
74
|
+
return new StatusMessage(
|
|
75
|
+
'1.0.0',
|
|
76
|
+
Math.floor(Math.random() * 100),
|
|
77
|
+
Buffer32.random().toString(),
|
|
78
|
+
Math.floor(Math.random() * 100),
|
|
79
|
+
//TODO: add finalisedBlockHash
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
validate(peerStatus: StatusMessage): boolean {
|
|
73
84
|
// TODO: Validate other fields as well
|
|
74
85
|
return this.compressedComponentsVersion === peerStatus.compressedComponentsVersion;
|
|
75
86
|
}
|
|
87
|
+
|
|
88
|
+
equals(other: StatusMessage): boolean {
|
|
89
|
+
return (
|
|
90
|
+
this.compressedComponentsVersion === other.compressedComponentsVersion &&
|
|
91
|
+
this.latestBlockNumber === other.latestBlockNumber &&
|
|
92
|
+
this.latestBlockHash === other.latestBlockHash &&
|
|
93
|
+
this.finalisedBlockNumber === other.finalisedBlockNumber
|
|
94
|
+
);
|
|
95
|
+
}
|
|
76
96
|
}
|
|
77
97
|
|
|
78
98
|
/**
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { chunk } from '@aztec/foundation/collection';
|
|
1
2
|
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
2
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
3
4
|
|
|
4
5
|
import type { PeerId } from '@libp2p/interface';
|
|
5
6
|
|
|
6
7
|
import type { MemPools } from '../../../mem_pools/interface.js';
|
|
7
8
|
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
9
|
+
import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* We want to keep the logic of the req resp handler in this file, but we do not have a reference to the mempools here
|
|
@@ -12,18 +14,45 @@ import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
|
12
14
|
*
|
|
13
15
|
* Handler for tx requests
|
|
14
16
|
* @param mempools - the mempools
|
|
15
|
-
* @returns the
|
|
17
|
+
* @returns the Tx request handler
|
|
16
18
|
*/
|
|
17
19
|
export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>): ReqRespSubProtocolHandler {
|
|
18
20
|
/**
|
|
19
21
|
* Handler for tx requests
|
|
20
22
|
* @param msg - the tx request message
|
|
21
23
|
* @returns the tx response message
|
|
24
|
+
* @throws if msg is not a valid tx hash
|
|
22
25
|
*/
|
|
23
26
|
return async (_peerId: PeerId, msg: Buffer) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
let txHashes: TxHashArray;
|
|
28
|
+
try {
|
|
29
|
+
txHashes = TxHashArray.fromBuffer(msg);
|
|
30
|
+
} catch (err: any) {
|
|
31
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const txs = new TxArray(
|
|
36
|
+
...(await Promise.all(txHashes.map(txHash => mempools.txPool.getTxByHash(txHash)))).filter(t => !!t),
|
|
37
|
+
);
|
|
38
|
+
return txs.toBuffer();
|
|
39
|
+
} catch (err: any) {
|
|
40
|
+
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
|
|
41
|
+
}
|
|
28
42
|
};
|
|
29
43
|
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Helper function to chunk an array of transaction hashes into chunks of a specified size.
|
|
47
|
+
* This is mainly used in ReqResp in order not to request too many transactions at once from the single peer.
|
|
48
|
+
*
|
|
49
|
+
* @param hashes - The array of transaction hashes to chunk.
|
|
50
|
+
* @param chunkSize - The size of each chunk. Default is 8. Reasoning:
|
|
51
|
+
* Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
|
|
52
|
+
* we define Q as max number of transactions per batch, the comment explains why we use 8.
|
|
53
|
+
*/
|
|
54
|
+
//TODO: (mralj) chunk size should by default be 8, this is just temporary until the protocol is implemented correctly
|
|
55
|
+
//more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
|
|
56
|
+
export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
|
|
57
|
+
return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
|
|
58
|
+
}
|
|
@@ -22,6 +22,16 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
22
22
|
quotaCount: 10,
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
+
[ReqRespSubProtocol.AUTH]: {
|
|
26
|
+
peerLimit: {
|
|
27
|
+
quotaTimeMs: 1000,
|
|
28
|
+
quotaCount: 5,
|
|
29
|
+
},
|
|
30
|
+
globalLimit: {
|
|
31
|
+
quotaTimeMs: 1000,
|
|
32
|
+
quotaCount: 10,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
25
35
|
[ReqRespSubProtocol.TX]: {
|
|
26
36
|
peerLimit: {
|
|
27
37
|
quotaTimeMs: 1000,
|
|
@@ -52,4 +62,14 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
52
62
|
quotaCount: 10,
|
|
53
63
|
},
|
|
54
64
|
},
|
|
65
|
+
[ReqRespSubProtocol.BLOCK_TXS]: {
|
|
66
|
+
peerLimit: {
|
|
67
|
+
quotaTimeMs: 1000,
|
|
68
|
+
quotaCount: 10,
|
|
69
|
+
},
|
|
70
|
+
globalLimit: {
|
|
71
|
+
quotaTimeMs: 1000,
|
|
72
|
+
quotaCount: 200,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
55
75
|
};
|