@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,30 @@
|
|
|
1
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
2
|
+
/**
|
|
3
|
+
* BitVector helper class for representing and serializing bit vectors
|
|
4
|
+
*/
|
|
5
|
+
export declare class BitVector {
|
|
6
|
+
private buffer;
|
|
7
|
+
private length;
|
|
8
|
+
constructor(buffer: Buffer, length: number);
|
|
9
|
+
static init(length: number, indices: number[]): BitVector;
|
|
10
|
+
getLength(): number;
|
|
11
|
+
isSet(index: number): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Returns all indices which are set to true
|
|
14
|
+
* */
|
|
15
|
+
getTrueIndices(): number[];
|
|
16
|
+
/**
|
|
17
|
+
* Serializes the BitVector object into a Buffer
|
|
18
|
+
*
|
|
19
|
+
* @returns Buffer representation of the BitVector object
|
|
20
|
+
* */
|
|
21
|
+
toBuffer(): Buffer;
|
|
22
|
+
/**
|
|
23
|
+
* Deserializes buffer into new BitVector
|
|
24
|
+
*
|
|
25
|
+
* @returns A new BitVector instance
|
|
26
|
+
* */
|
|
27
|
+
static fromBuffer(buffer: Buffer | BufferReader): BitVector;
|
|
28
|
+
static byteLength(length: number): number;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=bitvector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitvector.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/bitvector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAY1C,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS;IAqBzD,SAAS,IAAI,MAAM;IAWnB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI7B;;SAEK;IACL,cAAc,IAAI,MAAM,EAAE;IAI1B;;;;SAIK;IACL,QAAQ,IAAI,MAAM;IAIlB;;;;SAIK;IACL,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAQ3D,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM;CAGjC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
|
+
/**
|
|
3
|
+
* BitVector helper class for representing and serializing bit vectors
|
|
4
|
+
*/ export class BitVector {
|
|
5
|
+
buffer;
|
|
6
|
+
length;
|
|
7
|
+
constructor(buffer, length){
|
|
8
|
+
this.buffer = buffer;
|
|
9
|
+
this.length = length;
|
|
10
|
+
}
|
|
11
|
+
/*
|
|
12
|
+
* Creates new BitVector instance
|
|
13
|
+
* @param length - Length of the bit vector
|
|
14
|
+
* @param indices - Array of indices to set to 1 in the bit vector
|
|
15
|
+
*
|
|
16
|
+
* @returns A new BitVector instance with specified length and set indices
|
|
17
|
+
* */ static init(length, indices) {
|
|
18
|
+
if (indices.length > length) {
|
|
19
|
+
throw new Error('Indices length exceeds specified length');
|
|
20
|
+
}
|
|
21
|
+
const buffer = Buffer.alloc(BitVector.byteLength(length));
|
|
22
|
+
indices.forEach((idx)=>{
|
|
23
|
+
const invalidIndex = idx < 0 || idx >= length;
|
|
24
|
+
if (invalidIndex) {
|
|
25
|
+
throw new Error(`Index ${idx} is out of bounds for BitVector of length ${length}`);
|
|
26
|
+
}
|
|
27
|
+
const byteIndex = Math.floor(idx / 8);
|
|
28
|
+
const bitIndex = idx % 8;
|
|
29
|
+
buffer[byteIndex] |= 1 << bitIndex;
|
|
30
|
+
});
|
|
31
|
+
return new BitVector(buffer, length);
|
|
32
|
+
}
|
|
33
|
+
getLength() {
|
|
34
|
+
return this.length;
|
|
35
|
+
}
|
|
36
|
+
/*
|
|
37
|
+
* Checks if element at index is set to true
|
|
38
|
+
*
|
|
39
|
+
* @param index - Index of the bit to check
|
|
40
|
+
*
|
|
41
|
+
* @returns True if the bit at index is set, false otherwise
|
|
42
|
+
* */ isSet(index) {
|
|
43
|
+
return index >= 0 && index < this.length && !!(this.buffer[Math.floor(index / 8)] & 1 << index % 8);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns all indices which are set to true
|
|
47
|
+
* */ getTrueIndices() {
|
|
48
|
+
return Array.from({
|
|
49
|
+
length: this.length
|
|
50
|
+
}, (_, i)=>i).filter((i)=>this.isSet(i));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Serializes the BitVector object into a Buffer
|
|
54
|
+
*
|
|
55
|
+
* @returns Buffer representation of the BitVector object
|
|
56
|
+
* */ toBuffer() {
|
|
57
|
+
return serializeToBuffer([
|
|
58
|
+
this.length,
|
|
59
|
+
this.buffer
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Deserializes buffer into new BitVector
|
|
64
|
+
*
|
|
65
|
+
* @returns A new BitVector instance
|
|
66
|
+
* */ static fromBuffer(buffer) {
|
|
67
|
+
const reader = BufferReader.asReader(buffer);
|
|
68
|
+
const length = reader.readNumber();
|
|
69
|
+
const bitBuffer = reader.readBytes(BitVector.byteLength(length));
|
|
70
|
+
return new BitVector(bitBuffer, length);
|
|
71
|
+
}
|
|
72
|
+
static byteLength(length) {
|
|
73
|
+
return Math.ceil(length / 8);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AttestationPool } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
|
|
2
|
+
import type { TxPool } from '../../../../mem_pools/index.js';
|
|
3
|
+
import type { ReqRespSubProtocolHandler } from '../../interface.js';
|
|
4
|
+
/**
|
|
5
|
+
* Handler for block txs requests
|
|
6
|
+
* @param attestationPool - the attestation pool to check for block proposals
|
|
7
|
+
* @param mempools - the mempools containing the tx pool
|
|
8
|
+
* @returns the BlockTxs request handler
|
|
9
|
+
*/
|
|
10
|
+
export declare function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool: TxPool): ReqRespSubProtocolHandler;
|
|
11
|
+
//# sourceMappingURL=block_txs_handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_txs_handler.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/block_txs_handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4DAA4D,CAAC;AAClG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAKpE;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,yBAAyB,CAmClH"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TxArray } from '@aztec/stdlib/tx';
|
|
2
|
+
import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
|
|
3
|
+
import { BitVector } from './bitvector.js';
|
|
4
|
+
import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
|
|
5
|
+
/**
|
|
6
|
+
* Handler for block txs requests
|
|
7
|
+
* @param attestationPool - the attestation pool to check for block proposals
|
|
8
|
+
* @param mempools - the mempools containing the tx pool
|
|
9
|
+
* @returns the BlockTxs request handler
|
|
10
|
+
*/ export function reqRespBlockTxsHandler(attestationPool, txPool) {
|
|
11
|
+
/**
|
|
12
|
+
* Handler for block txs requests
|
|
13
|
+
* @param msg - the block txs request message
|
|
14
|
+
* @returns the block txs response message
|
|
15
|
+
* @throws if msg is not a valid block txs request
|
|
16
|
+
*/ return async (_peerId, msg)=>{
|
|
17
|
+
let request;
|
|
18
|
+
try {
|
|
19
|
+
request = BlockTxsRequest.fromBuffer(msg);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, {
|
|
22
|
+
cause: err
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const blockProposal = await attestationPool.getBlockProposal(request.blockHash.toString());
|
|
26
|
+
if (!blockProposal) {
|
|
27
|
+
throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
|
|
28
|
+
}
|
|
29
|
+
const txsAvailableInPool = await txPool.hasTxs(blockProposal.txHashes);
|
|
30
|
+
//Map txs in the pool to their indices in the block proposal
|
|
31
|
+
const availableIndices = txsAvailableInPool.map((hasTx, idx)=>hasTx ? idx : -1).filter((idx)=>idx !== -1);
|
|
32
|
+
const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
|
|
33
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
34
|
+
const requestedTxsHashes = blockProposal.txHashes.filter((_, idx)=>requestedIndices.has(idx));
|
|
35
|
+
const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter((tx)=>!!tx);
|
|
36
|
+
const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
|
|
37
|
+
return response.toBuffer();
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { TxArray } from '@aztec/stdlib/tx';
|
|
4
|
+
import { BitVector } from './bitvector.js';
|
|
5
|
+
/**
|
|
6
|
+
* Request message for requesting specific transactions from a block
|
|
7
|
+
*/
|
|
8
|
+
export declare class BlockTxsRequest {
|
|
9
|
+
readonly blockHash: Fr;
|
|
10
|
+
readonly txIndices: BitVector;
|
|
11
|
+
constructor(blockHash: Fr, // 32 byte hash of the proposed block header
|
|
12
|
+
txIndices: BitVector);
|
|
13
|
+
/**
|
|
14
|
+
* Deserializes the BlockTxRequest object from a Buffer
|
|
15
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
16
|
+
* @returns An instance of BlockTxRequest
|
|
17
|
+
*/
|
|
18
|
+
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest;
|
|
19
|
+
/**
|
|
20
|
+
* Serializes the BlockTxRequest object into a Buffer
|
|
21
|
+
* @returns Buffer representation of the BlockTxRequest object
|
|
22
|
+
*/
|
|
23
|
+
toBuffer(): Buffer;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Response message containing requested transactions from a block
|
|
27
|
+
*/
|
|
28
|
+
export declare class BlockTxsResponse {
|
|
29
|
+
readonly blockHash: Fr;
|
|
30
|
+
readonly txs: TxArray;
|
|
31
|
+
readonly txIndices: BitVector;
|
|
32
|
+
constructor(blockHash: Fr, txs: TxArray, // List of transactions we requested and peer has
|
|
33
|
+
txIndices: BitVector);
|
|
34
|
+
/**
|
|
35
|
+
* Deserializes the BlockTxResponse object from a Buffer
|
|
36
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
37
|
+
* @returns An instance of BlockTxResponse
|
|
38
|
+
*/
|
|
39
|
+
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse;
|
|
40
|
+
/**
|
|
41
|
+
* Serializes the BlockTxResponse object into a Buffer
|
|
42
|
+
* @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
|
|
43
|
+
* thus we serialize it last
|
|
44
|
+
* @returns Buffer representation of the BlockTxResponse object
|
|
45
|
+
*/
|
|
46
|
+
toBuffer(): Buffer;
|
|
47
|
+
static empty(): BlockTxsResponse;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=block_txs_reqresp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_txs_reqresp.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;GAEG;AACH,qBAAa,eAAe;IAExB,QAAQ,CAAC,SAAS,EAAE,EAAE;IAGtB,QAAQ,CAAC,SAAS,EAAE,SAAS;gBAHpB,SAAS,EAAE,EAAE,EAAE,4CAA4C;IAG3D,SAAS,EAAE,SAAS;IAG/B;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,eAAe;IAQjE;;;OAGG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAEzB,QAAQ,CAAC,SAAS,EAAE,EAAE;IACtB,QAAQ,CAAC,GAAG,EAAE,OAAO;IAGrB,QAAQ,CAAC,SAAS,EAAE,SAAS;gBAJpB,SAAS,EAAE,EAAE,EACb,GAAG,EAAE,OAAO,EAAE,iDAAiD;IAG/D,SAAS,EAAE,SAAS;IAG/B;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,gBAAgB;IASlE;;;;;OAKG;IACH,QAAQ,IAAI,MAAM;IAIlB,MAAM,CAAC,KAAK,IAAI,gBAAgB;CAGjC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
+
import { TxArray } from '@aztec/stdlib/tx';
|
|
4
|
+
import { BitVector } from './bitvector.js';
|
|
5
|
+
/**
|
|
6
|
+
* Request message for requesting specific transactions from a block
|
|
7
|
+
*/ export class BlockTxsRequest {
|
|
8
|
+
blockHash;
|
|
9
|
+
txIndices;
|
|
10
|
+
constructor(blockHash, // BitVector indicating which txs from the proposal we are requesting
|
|
11
|
+
// 1 means we want the tx, 0 means we don't
|
|
12
|
+
txIndices){
|
|
13
|
+
this.blockHash = blockHash;
|
|
14
|
+
this.txIndices = txIndices;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Deserializes the BlockTxRequest object from a Buffer
|
|
18
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
19
|
+
* @returns An instance of BlockTxRequest
|
|
20
|
+
*/ static fromBuffer(buffer) {
|
|
21
|
+
const reader = BufferReader.asReader(buffer);
|
|
22
|
+
const blockHash = Fr.fromBuffer(reader);
|
|
23
|
+
const txIndices = BitVector.fromBuffer(reader);
|
|
24
|
+
return new BlockTxsRequest(blockHash, txIndices);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Serializes the BlockTxRequest object into a Buffer
|
|
28
|
+
* @returns Buffer representation of the BlockTxRequest object
|
|
29
|
+
*/ toBuffer() {
|
|
30
|
+
return serializeToBuffer([
|
|
31
|
+
this.blockHash,
|
|
32
|
+
this.txIndices.toBuffer()
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Response message containing requested transactions from a block
|
|
38
|
+
*/ export class BlockTxsResponse {
|
|
39
|
+
blockHash;
|
|
40
|
+
txs;
|
|
41
|
+
txIndices;
|
|
42
|
+
constructor(blockHash, txs, // BitVector indicating which txs from the proposal are available at the peer
|
|
43
|
+
// 1 means the tx is available, 0 means it is not
|
|
44
|
+
txIndices){
|
|
45
|
+
this.blockHash = blockHash;
|
|
46
|
+
this.txs = txs;
|
|
47
|
+
this.txIndices = txIndices;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Deserializes the BlockTxResponse object from a Buffer
|
|
51
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
52
|
+
* @returns An instance of BlockTxResponse
|
|
53
|
+
*/ static fromBuffer(buffer) {
|
|
54
|
+
const reader = BufferReader.asReader(buffer);
|
|
55
|
+
const blockHash = Fr.fromBuffer(reader);
|
|
56
|
+
const txs = TxArray.fromBuffer(reader);
|
|
57
|
+
const txIndices = BitVector.fromBuffer(reader);
|
|
58
|
+
return new BlockTxsResponse(blockHash, txs, txIndices);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Serializes the BlockTxResponse object into a Buffer
|
|
62
|
+
* @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
|
|
63
|
+
* thus we serialize it last
|
|
64
|
+
* @returns Buffer representation of the BlockTxResponse object
|
|
65
|
+
*/ toBuffer() {
|
|
66
|
+
return serializeToBuffer([
|
|
67
|
+
this.blockHash,
|
|
68
|
+
this.txs.toBuffer(),
|
|
69
|
+
this.txIndices.toBuffer()
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
static empty() {
|
|
73
|
+
return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC"}
|
|
@@ -76,14 +76,12 @@ export function decodeGoodbyeReason(buffer) {
|
|
|
76
76
|
* @param peerManager - The peer manager.
|
|
77
77
|
* @returns A resolved promise with the goodbye response.
|
|
78
78
|
*/ export function reqGoodbyeHandler(peerManager) {
|
|
79
|
-
return (peerId,
|
|
80
|
-
const reason = decodeGoodbyeReason(
|
|
79
|
+
return (peerId, msg)=>{
|
|
80
|
+
const reason = decodeGoodbyeReason(msg);
|
|
81
81
|
peerManager.goodbyeReceived(peerId, reason);
|
|
82
82
|
// NOTE: In the current implementation this won't be sent to peer,
|
|
83
83
|
// as the connection to peer has been already closed by peerManager.goodbyeReceived
|
|
84
84
|
// We have this just to satisfy interface
|
|
85
|
-
return Promise.resolve(Buffer.
|
|
86
|
-
0x0
|
|
87
|
-
]));
|
|
85
|
+
return Promise.resolve(Buffer.alloc(0));
|
|
88
86
|
};
|
|
89
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
|
|
@@ -26,7 +26,9 @@ export declare class StatusMessage {
|
|
|
26
26
|
* @returns StatusMessage instance
|
|
27
27
|
*/
|
|
28
28
|
static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage;
|
|
29
|
+
static random(): StatusMessage;
|
|
29
30
|
validate(peerStatus: StatusMessage): boolean;
|
|
31
|
+
equals(other: StatusMessage): boolean;
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* Handles the status request. By immediately responding with the current node status.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/status.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEpG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAQhD,qBAAa,aAAa;IAEtB,QAAQ,CAAC,2BAA2B,EAAE,MAAM;IAC5C,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAClC,QAAQ,CAAC,eAAe,EAAE,MAAM;IAChC,QAAQ,CAAC,oBAAoB,EAAE,MAAM;gBAH5B,2BAA2B,EAAE,MAAM,EACnC,iBAAiB,EAAE,MAAM,EACzB,eAAe,EAAE,MAAM,EACvB,oBAAoB,EAAE,MAAM;IAKvC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,aAAa;IAY/D;;;OAGG;IACH,QAAQ;IAWR;;;;;OAKG;IACH,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,GAAG,aAAa;IAUjG,MAAM,CAAC,MAAM,IAAI,aAAa;IAU9B,QAAQ,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO;IAK5C,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;CAQtC;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,2BAA2B,EAAE,MAAM,EACnC,sBAAsB,EAAE,sBAAsB,EAC9C,MAAM,CAAC,EAAE,MAAM,IAED,QAAQ,MAAM,EAAE,MAAM,MAAM,sCAU3C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
1
2
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
3
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
3
4
|
/*
|
|
@@ -43,10 +44,16 @@ import { bufferToHex } from '@aztec/foundation/string';
|
|
|
43
44
|
*/ static fromWorldStateSyncStatus(version, syncStatus) {
|
|
44
45
|
return new StatusMessage(version, syncStatus.latestBlockNumber, syncStatus.latestBlockHash, syncStatus.finalisedBlockNumber);
|
|
45
46
|
}
|
|
47
|
+
static random() {
|
|
48
|
+
return new StatusMessage('1.0.0', Math.floor(Math.random() * 100), Buffer32.random().toString(), Math.floor(Math.random() * 100));
|
|
49
|
+
}
|
|
46
50
|
validate(peerStatus) {
|
|
47
51
|
// TODO: Validate other fields as well
|
|
48
52
|
return this.compressedComponentsVersion === peerStatus.compressedComponentsVersion;
|
|
49
53
|
}
|
|
54
|
+
equals(other) {
|
|
55
|
+
return this.compressedComponentsVersion === other.compressedComponentsVersion && this.latestBlockNumber === other.latestBlockNumber && this.latestBlockHash === other.latestBlockHash && this.finalisedBlockNumber === other.finalisedBlockNumber;
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
/**
|
|
52
59
|
* Handles the status request. By immediately responding with the current node status.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
2
|
+
import { TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
2
3
|
import type { MemPools } from '../../../mem_pools/interface.js';
|
|
3
4
|
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
4
5
|
/**
|
|
@@ -7,7 +8,17 @@ import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
|
7
8
|
*
|
|
8
9
|
* Handler for tx requests
|
|
9
10
|
* @param mempools - the mempools
|
|
10
|
-
* @returns the
|
|
11
|
+
* @returns the Tx request handler
|
|
11
12
|
*/
|
|
12
13
|
export declare function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>): ReqRespSubProtocolHandler;
|
|
14
|
+
/**
|
|
15
|
+
* Helper function to chunk an array of transaction hashes into chunks of a specified size.
|
|
16
|
+
* This is mainly used in ReqResp in order not to request too many transactions at once from the single peer.
|
|
17
|
+
*
|
|
18
|
+
* @param hashes - The array of transaction hashes to chunk.
|
|
19
|
+
* @param chunkSize - The size of each chunk. Default is 8. Reasoning:
|
|
20
|
+
* Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
|
|
21
|
+
* we define Q as max number of transactions per batch, the comment explains why we use 8.
|
|
22
|
+
*/
|
|
23
|
+
export declare function chunkTxHashesRequest(hashes: TxHash[], chunkSize?: number): Array<TxHashArray>;
|
|
13
24
|
//# sourceMappingURL=tx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/tx.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/tx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAW,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIhE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGjE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,yBAAyB,CAwB1G;AAED;;;;;;;;GAQG;AAGH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,SAAI,GAAG,KAAK,CAAC,WAAW,CAAC,CAExF"}
|
|
@@ -1,20 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { chunk } from '@aztec/foundation/collection';
|
|
2
|
+
import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
|
|
3
|
+
import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
2
4
|
/**
|
|
3
5
|
* 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
|
|
4
6
|
* so we need to pass it in as a parameter.
|
|
5
7
|
*
|
|
6
8
|
* Handler for tx requests
|
|
7
9
|
* @param mempools - the mempools
|
|
8
|
-
* @returns the
|
|
10
|
+
* @returns the Tx request handler
|
|
9
11
|
*/ export function reqRespTxHandler(mempools) {
|
|
10
12
|
/**
|
|
11
13
|
* Handler for tx requests
|
|
12
14
|
* @param msg - the tx request message
|
|
13
15
|
* @returns the tx response message
|
|
16
|
+
* @throws if msg is not a valid tx hash
|
|
14
17
|
*/ return async (_peerId, msg)=>{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
let txHashes;
|
|
19
|
+
try {
|
|
20
|
+
txHashes = TxHashArray.fromBuffer(msg);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, {
|
|
23
|
+
cause: err
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const txs = new TxArray(...(await Promise.all(txHashes.map((txHash)=>mempools.txPool.getTxByHash(txHash)))).filter((t)=>!!t));
|
|
28
|
+
return txs.toBuffer();
|
|
29
|
+
} catch (err) {
|
|
30
|
+
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, {
|
|
31
|
+
cause: err
|
|
32
|
+
});
|
|
33
|
+
}
|
|
19
34
|
};
|
|
20
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Helper function to chunk an array of transaction hashes into chunks of a specified size.
|
|
38
|
+
* This is mainly used in ReqResp in order not to request too many transactions at once from the single peer.
|
|
39
|
+
*
|
|
40
|
+
* @param hashes - The array of transaction hashes to chunk.
|
|
41
|
+
* @param chunkSize - The size of each chunk. Default is 8. Reasoning:
|
|
42
|
+
* Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
|
|
43
|
+
* we define Q as max number of transactions per batch, the comment explains why we use 8.
|
|
44
|
+
*/ //TODO: (mralj) chunk size should by default be 8, this is just temporary until the protocol is implemented correctly
|
|
45
|
+
//more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
|
|
46
|
+
export function chunkTxHashesRequest(hashes, chunkSize = 1) {
|
|
47
|
+
return chunk(hashes, chunkSize).map((chunk)=>new TxHashArray(...chunk));
|
|
48
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate_limits.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/rate-limiter/rate_limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAGxF,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"rate_limits.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/rate-limiter/rate_limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAGxF,eAAO,MAAM,mBAAmB,EAAE,4BAuEjC,CAAC"}
|
|
@@ -21,6 +21,16 @@ export const DEFAULT_RATE_LIMITS = {
|
|
|
21
21
|
quotaCount: 10
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
+
[ReqRespSubProtocol.AUTH]: {
|
|
25
|
+
peerLimit: {
|
|
26
|
+
quotaTimeMs: 1000,
|
|
27
|
+
quotaCount: 5
|
|
28
|
+
},
|
|
29
|
+
globalLimit: {
|
|
30
|
+
quotaTimeMs: 1000,
|
|
31
|
+
quotaCount: 10
|
|
32
|
+
}
|
|
33
|
+
},
|
|
24
34
|
[ReqRespSubProtocol.TX]: {
|
|
25
35
|
peerLimit: {
|
|
26
36
|
quotaTimeMs: 1000,
|
|
@@ -50,5 +60,15 @@ export const DEFAULT_RATE_LIMITS = {
|
|
|
50
60
|
quotaTimeMs: 1000,
|
|
51
61
|
quotaCount: 10
|
|
52
62
|
}
|
|
63
|
+
},
|
|
64
|
+
[ReqRespSubProtocol.BLOCK_TXS]: {
|
|
65
|
+
peerLimit: {
|
|
66
|
+
quotaTimeMs: 1000,
|
|
67
|
+
quotaCount: 10
|
|
68
|
+
},
|
|
69
|
+
globalLimit: {
|
|
70
|
+
quotaTimeMs: 1000,
|
|
71
|
+
quotaCount: 200
|
|
72
|
+
}
|
|
53
73
|
}
|
|
54
74
|
};
|
|
@@ -3,7 +3,7 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
3
3
|
import type { Libp2p } from 'libp2p';
|
|
4
4
|
import type { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
5
5
|
import { type P2PReqRespConfig } from './config.js';
|
|
6
|
-
import { type ReqRespInterface, type ReqRespResponse, ReqRespSubProtocol, type ReqRespSubProtocolHandlers, type ReqRespSubProtocolRateLimits, type ReqRespSubProtocolValidators, type SubProtocolMap } from './interface.js';
|
|
6
|
+
import { type ReqRespInterface, type ReqRespResponse, ReqRespSubProtocol, type ReqRespSubProtocolHandler, type ReqRespSubProtocolHandlers, type ReqRespSubProtocolRateLimits, type ReqRespSubProtocolValidators, type SubProtocolMap } from './interface.js';
|
|
7
7
|
/**
|
|
8
8
|
* The Request Response Service
|
|
9
9
|
*
|
|
@@ -22,7 +22,6 @@ export declare class ReqResp implements ReqRespInterface {
|
|
|
22
22
|
private libp2p;
|
|
23
23
|
private peerScoring;
|
|
24
24
|
private logger;
|
|
25
|
-
private overallRequestTimeoutMs;
|
|
26
25
|
private individualRequestTimeoutMs;
|
|
27
26
|
private dialTimeoutMs;
|
|
28
27
|
private subProtocolHandlers;
|
|
@@ -38,40 +37,11 @@ export declare class ReqResp implements ReqRespInterface {
|
|
|
38
37
|
* Start the reqresp service
|
|
39
38
|
*/
|
|
40
39
|
start(subProtocolHandlers: ReqRespSubProtocolHandlers, subProtocolValidators: ReqRespSubProtocolValidators): Promise<void>;
|
|
40
|
+
addSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler, validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol]): Promise<void>;
|
|
41
41
|
/**
|
|
42
42
|
* Stop the reqresp service
|
|
43
43
|
*/
|
|
44
44
|
stop(): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Send a request to peers, returns the first response
|
|
47
|
-
*
|
|
48
|
-
* @param subProtocol - The protocol being requested
|
|
49
|
-
* @param request - The request to send
|
|
50
|
-
* @returns - The response from the peer, otherwise undefined
|
|
51
|
-
*
|
|
52
|
-
* @description
|
|
53
|
-
* This method attempts to send a request to all active peers using the specified sub-protocol.
|
|
54
|
-
* It opens a stream with each peer, sends the request, and awaits a response.
|
|
55
|
-
* If a valid response is received, it returns the response; otherwise, it continues to the next peer.
|
|
56
|
-
* If no response is received from any peer, it returns undefined.
|
|
57
|
-
*
|
|
58
|
-
* The method performs the following steps:
|
|
59
|
-
* - Sample a peer to send the request to.
|
|
60
|
-
* - Opens a stream with the peer using the specified sub-protocol.
|
|
61
|
-
*
|
|
62
|
-
* When a response is received, it is validated using the given sub protocols response validator.
|
|
63
|
-
* To see the interface for the response validator - see `interface.ts`
|
|
64
|
-
*
|
|
65
|
-
* Failing a response validation requests in a severe peer penalty, and will
|
|
66
|
-
* prompt the node to continue to search to the next peer.
|
|
67
|
-
* For example, a transaction request validator will check that the payload returned does in fact
|
|
68
|
-
* match the txHash that was requested. A peer that fails this check an only be an extremely naughty peer.
|
|
69
|
-
*
|
|
70
|
-
* This entire operation is wrapped in an overall timeout, that is independent of the
|
|
71
|
-
* peer it is requesting data from.
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
sendRequest<SubProtocol extends ReqRespSubProtocol>(subProtocol: SubProtocol, request: InstanceType<SubProtocolMap[SubProtocol]['request']>): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']> | undefined>;
|
|
75
45
|
/**
|
|
76
46
|
* Request multiple messages over the same sub protocol, balancing the requests across peers.
|
|
77
47
|
*
|
|
@@ -94,7 +64,7 @@ export declare class ReqResp implements ReqRespInterface {
|
|
|
94
64
|
*
|
|
95
65
|
* @throws {CollectiveReqRespTimeoutError} - If the request batch exceeds the specified timeout (`timeoutMs`).
|
|
96
66
|
*/
|
|
97
|
-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(subProtocol: SubProtocol, requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[], pinnedPeer: PeerId | undefined, timeoutMs?: number, maxPeers?: number, maxRetryAttempts?: number): Promise<
|
|
67
|
+
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(subProtocol: SubProtocol, requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[], pinnedPeer: PeerId | undefined, timeoutMs?: number, maxPeers?: number, maxRetryAttempts?: number): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
|
|
98
68
|
/**
|
|
99
69
|
* Sends a request to a specific peer
|
|
100
70
|
*
|
|
@@ -132,10 +102,6 @@ export declare class ReqResp implements ReqRespInterface {
|
|
|
132
102
|
* @returns If the error is non pubishable, then undefined is returned, otherwise the peer is penalized
|
|
133
103
|
*/
|
|
134
104
|
private handleResponseError;
|
|
135
|
-
/**
|
|
136
|
-
* Categorize the error and log it.
|
|
137
|
-
*/
|
|
138
|
-
private categorizeError;
|
|
139
105
|
/**
|
|
140
106
|
* Read a message returned from a stream into a single buffer
|
|
141
107
|
*
|
|
@@ -148,7 +114,8 @@ export declare class ReqResp implements ReqRespInterface {
|
|
|
148
114
|
* Stream Handler
|
|
149
115
|
* Reads the incoming stream, determines the protocol, then triggers the appropriate handler
|
|
150
116
|
*
|
|
151
|
-
* @param
|
|
117
|
+
* @param protocol - The sub protocol to handle
|
|
118
|
+
* @param incomingStream - The incoming stream data containing the stream and connection
|
|
152
119
|
*
|
|
153
120
|
* @description
|
|
154
121
|
* An individual stream handler will be bound to each sub protocol, and handles returning data back
|
|
@@ -161,6 +128,37 @@ export declare class ReqResp implements ReqRespInterface {
|
|
|
161
128
|
* if they exceed their peer specific limits.
|
|
162
129
|
*/
|
|
163
130
|
private streamHandler;
|
|
164
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Reads incoming data from the stream, processes it according to the sub protocol,
|
|
133
|
+
* and puts response back into the stream.
|
|
134
|
+
*
|
|
135
|
+
* @param protocol - The sub protocol to use for processing the stream
|
|
136
|
+
* @param incomingStream - The incoming stream data containing the stream and connection
|
|
137
|
+
*
|
|
138
|
+
* */
|
|
139
|
+
private processStream;
|
|
140
|
+
/**
|
|
141
|
+
* Try to send error status to the peer. We say try, because the stream,
|
|
142
|
+
* might already be closed
|
|
143
|
+
* @param stream - The stream opened between us and the peer
|
|
144
|
+
* @param status - The error status to send back to the peer
|
|
145
|
+
* @returns true if error was sent successfully, otherwise false
|
|
146
|
+
*
|
|
147
|
+
*/
|
|
148
|
+
private trySendError;
|
|
149
|
+
private handleRequestError;
|
|
150
|
+
/**
|
|
151
|
+
* Categorize the request error and log it.
|
|
152
|
+
*
|
|
153
|
+
* @returns Severity of the error, or undefined if the error is not punishable.
|
|
154
|
+
*/
|
|
155
|
+
private categorizeRequestError;
|
|
156
|
+
/**
|
|
157
|
+
* Categorize the response error and log it.
|
|
158
|
+
*
|
|
159
|
+
* @returns Severity of the error, or undefined if the error is not punishable.
|
|
160
|
+
*/
|
|
161
|
+
private categorizeResponseError;
|
|
162
|
+
private categorizeConnectionErrors;
|
|
165
163
|
}
|
|
166
164
|
//# sourceMappingURL=reqresp.d.ts.map
|