@aztec/p2p 4.0.0-devnet.2-patch.4 → 4.0.0-devnet.3-patch.0
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/README.md +129 -3
- package/dest/client/factory.d.ts +4 -5
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +30 -28
- package/dest/client/interface.d.ts +8 -13
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +6 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +22 -88
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +2 -4
- package/dest/config.d.ts +29 -10
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +80 -31
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +4 -4
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +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 +3 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -2
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +2 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +10 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +9 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +46 -8
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +81 -17
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +9 -10
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +5 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +179 -151
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +133 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +247 -60
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
- package/dest/services/dummy_service.d.ts +4 -4
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +4 -4
- package/dest/services/encoding.d.ts +6 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +14 -8
- package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +32 -10
- package/dest/services/libp2p/libp2p_service.d.ts +16 -13
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +97 -93
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +16 -8
- package/dest/services/service.d.ts +5 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- package/dest/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +8 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +2 -2
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +2 -1
- package/dest/testbench/p2p_client_testbench_worker.js +7 -6
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +4 -1
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +49 -45
- package/src/client/interface.ts +8 -13
- package/src/client/p2p_client.ts +24 -117
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +2 -3
- package/src/config.ts +115 -33
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool/priority.ts +4 -4
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
- package/src/mem_pools/tx_pool_v2/README.md +9 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +2 -2
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +10 -6
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +113 -18
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +11 -11
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +14 -2
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +188 -153
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
- package/src/msg_validators/tx_validator/README.md +119 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/factory.ts +394 -78
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/services/dummy_service.ts +6 -6
- package/src/services/encoding.ts +14 -7
- package/src/services/gossipsub/README.md +29 -14
- package/src/services/gossipsub/topic_score_params.ts +49 -13
- package/src/services/libp2p/libp2p_service.ts +111 -101
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/reqresp.ts +18 -10
- package/src/services/service.ts +11 -2
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/tx_source.ts +8 -7
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +0 -2
- package/src/test-helpers/mock-pubsub.ts +13 -6
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/test-helpers/testbench-utils.ts +2 -1
- package/src/testbench/p2p_client_testbench_worker.ts +3 -6
- package/src/testbench/worker_client_manager.ts +11 -4
- package/src/util.ts +7 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# ReqResp Protocols
|
|
2
|
+
|
|
3
|
+
This module implements libp2p request-response protocols for the Aztec P2P network. All protocols share common transport-level validation (rate limiting, timeouts, Snappy decompression, error penalties) with protocol-specific logic layered on top.
|
|
4
|
+
|
|
5
|
+
## Common Transport Validation
|
|
6
|
+
|
|
7
|
+
### Rate Limiting (Responder Side)
|
|
8
|
+
|
|
9
|
+
Applied before the protocol handler runs.
|
|
10
|
+
|
|
11
|
+
| Protocol | Peer Limit | Global Limit | File |
|
|
12
|
+
|----------|-----------|-------------|------|
|
|
13
|
+
| PING | 5/s | 10/s | `rate-limiter/rate_limits.ts` |
|
|
14
|
+
| STATUS | 5/s | 10/s | same |
|
|
15
|
+
| AUTH | 5/s | 10/s | same |
|
|
16
|
+
| GOODBYE | 5/s | 10/s | same |
|
|
17
|
+
| BLOCK | 2/s | 5/s | same |
|
|
18
|
+
| BLOCK_TXS | 10/s | 200/s | same |
|
|
19
|
+
| TX | (see rate limits file) | (see rate limits file) | same |
|
|
20
|
+
|
|
21
|
+
- Per-peer limit exceeded: `HighToleranceError` penalty + `RATE_LIMIT_EXCEEDED` status. Penalty fires inside `RequestResponseRateLimiter.allow()`, not the stream handler.
|
|
22
|
+
- Global limit exceeded: `RATE_LIMIT_EXCEEDED` status only (no peer penalty).
|
|
23
|
+
|
|
24
|
+
### Response Status Byte (Requester Side)
|
|
25
|
+
|
|
26
|
+
| Rule | Consequence | File |
|
|
27
|
+
|------|-------------|------|
|
|
28
|
+
| First chunk must be exactly 1 byte | `ReqRespStatusError(UNKNOWN)` | `status.ts` |
|
|
29
|
+
| Byte must be valid `ReqRespStatus` enum (0-4, 126, 127) | `ReqRespStatusError(UNKNOWN)` | same |
|
|
30
|
+
|
|
31
|
+
Note: `prettyPrintReqRespStatus` is missing a `NOT_FOUND` case (minor logging bug).
|
|
32
|
+
|
|
33
|
+
### Snappy Decompression (Requester Side)
|
|
34
|
+
|
|
35
|
+
Per-protocol size limits checked via preamble before decompression.
|
|
36
|
+
|
|
37
|
+
### Timeouts (Requester Side)
|
|
38
|
+
|
|
39
|
+
| Timeout | Default | Penalty |
|
|
40
|
+
|---------|---------|---------|
|
|
41
|
+
| Individual request | 10s | HighToleranceError |
|
|
42
|
+
| Dial | 5s | HighToleranceError |
|
|
43
|
+
|
|
44
|
+
### Error Penalty Categorization (Requester Side)
|
|
45
|
+
|
|
46
|
+
| Error Type | Severity |
|
|
47
|
+
|------------|----------|
|
|
48
|
+
| GOODBYE subprotocol errors | None |
|
|
49
|
+
| `CollectiveReqRespTimeoutError` / `InvalidResponseError` | None |
|
|
50
|
+
| `AbortError` / connection close / muxer closed | None |
|
|
51
|
+
| `ECONNRESET` / `EPIPE` / `ECONNREFUSED` / `ERR_UNEXPECTED_EOF` | HighToleranceError |
|
|
52
|
+
| `ERR_UNSUPPORTED_PROTOCOL` | HighToleranceError |
|
|
53
|
+
| `IndividualReqRespTimeoutError` / `TimeoutError` | HighToleranceError |
|
|
54
|
+
| Catch-all | HighToleranceError |
|
|
55
|
+
|
|
56
|
+
### Request Error Penalty (Responder Side)
|
|
57
|
+
|
|
58
|
+
| Error Type | Severity |
|
|
59
|
+
|------------|----------|
|
|
60
|
+
| `BADLY_FORMED_REQUEST` | LowToleranceError |
|
|
61
|
+
| All others | None |
|
|
62
|
+
|
|
63
|
+
### Notes
|
|
64
|
+
|
|
65
|
+
- Request payloads are NOT snappy-compressed (asymmetric: only responses use snappy).
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Handshake Protocols
|
|
70
|
+
|
|
71
|
+
### Connection-Level Gating (Before Any Handshake)
|
|
72
|
+
|
|
73
|
+
| Rule | Consequence | File |
|
|
74
|
+
|------|-------------|------|
|
|
75
|
+
| Deny inbound connection from IP/peerId with too many failed auth handshakes | Connection denied | `libp2p_service.ts` |
|
|
76
|
+
| Threshold: `p2pMaxFailedAuthAttemptsAllowed` (default 3) | Tracked per peerId AND per IP | `peer_manager.ts` |
|
|
77
|
+
| Failed auth entries expire after 1 hour | Peer can reconnect; no escalating penalty for repeat offenders | same |
|
|
78
|
+
|
|
79
|
+
### Handshake Trigger Logic (`peer:connect`)
|
|
80
|
+
|
|
81
|
+
1. `p2pDisableStatusHandshake` = true: no handshake
|
|
82
|
+
2. `p2pAllowOnlyValidators` = false: STATUS handshake
|
|
83
|
+
3. Peer is protected (trusted/private/preferred): STATUS handshake
|
|
84
|
+
4. Otherwise: AUTH handshake (superset of STATUS)
|
|
85
|
+
|
|
86
|
+
Config constraint: `p2pDisableStatusHandshake && p2pAllowOnlyValidators` is disallowed.
|
|
87
|
+
|
|
88
|
+
### STATUS Protocol (`/aztec/req/status/1.0.0`)
|
|
89
|
+
|
|
90
|
+
**Requester side** (`peer_manager.ts`):
|
|
91
|
+
|
|
92
|
+
| Rule | Consequence |
|
|
93
|
+
|------|-------------|
|
|
94
|
+
| Response status must be SUCCESS | Peer scheduled for disconnect |
|
|
95
|
+
| `compressedComponentsVersion` must match | Peer scheduled for disconnect |
|
|
96
|
+
| Any exception | Peer scheduled for disconnect |
|
|
97
|
+
|
|
98
|
+
`StatusMessage.validate()` currently only checks `compressedComponentsVersion`. Fields `latestBlockNumber`, `latestBlockHash`, `finalizedBlockNumber` are NOT validated (TODO in code).
|
|
99
|
+
|
|
100
|
+
**Responder side**: no validation of incoming request content (always responds with own status). This means the requester leaks its blockchain state to any peer before validation.
|
|
101
|
+
|
|
102
|
+
**Deserialization bounds**: `MAX_VERSION_STRING_LENGTH` = 64 bytes, `MAX_BLOCK_HASH_STRING_LENGTH` = 128 bytes. Expected response size: 1 KB.
|
|
103
|
+
|
|
104
|
+
### AUTH Protocol (`/aztec/req/auth/1.0.0`)
|
|
105
|
+
|
|
106
|
+
**Requester side** (`peer_manager.ts`):
|
|
107
|
+
|
|
108
|
+
| # | Rule | Consequence |
|
|
109
|
+
|---|------|-------------|
|
|
110
|
+
| 1 | Response status is SUCCESS | `markAuthHandshakeFailed` + disconnect |
|
|
111
|
+
| 2 | `compressedComponentsVersion` match | `markAuthHandshakeFailed` + disconnect |
|
|
112
|
+
| 3 | Valid ECDSA signature recovery from challenge response | `markAuthHandshakeFailed` + disconnect |
|
|
113
|
+
| 4 | Recovered address is a registered validator | `markAuthHandshakeFailed` + disconnect |
|
|
114
|
+
| 5 | Validator address not already authenticated to different peerId | Silent return (no disconnect, no failure marking -- peer stays connected but unauthenticated) |
|
|
115
|
+
| 6 | Any exception | `markAuthHandshakeFailed` + disconnect |
|
|
116
|
+
|
|
117
|
+
Challenge: random `Fr`, payload = `keccak256("Aztec Validator Challenge:" + challenge)`, signed with `eth_sign` style. Challenge is NOT bound to peer identity (transport encryption via Noise is the binding layer).
|
|
118
|
+
|
|
119
|
+
On success: peer added to authenticated maps, prior failures cleared (including IP-based ones -- shared-IP peers benefit from a legitimate validator's success).
|
|
120
|
+
|
|
121
|
+
**Responder side** (`validator-client/src/validator.ts` + `peer_manager.ts`):
|
|
122
|
+
|
|
123
|
+
| # | Rule | Consequence |
|
|
124
|
+
|---|------|-------------|
|
|
125
|
+
| 1 | Peer must be protected (`shouldTrustWithIdentity` in `peer_manager.ts`) | Returns empty buffer (SUCCESS status + empty payload -> requester gets parse error -> `markAuthHandshakeFailed`) |
|
|
126
|
+
| 2 | Node must have registered validator address | Returns empty buffer (same consequence) |
|
|
127
|
+
|
|
128
|
+
**Unauthenticated peer gossip**: when `p2pAllowOnlyValidators` is true, unauthenticated peers get `appSpecificScore = -Infinity`, completely excluding them from all gossip.
|
|
129
|
+
|
|
130
|
+
### PING Protocol (`/aztec/req/ping/1.0.0`)
|
|
131
|
+
|
|
132
|
+
No validation on either side. Responder returns `Buffer.from('pong')`. Expected response: 1 KB.
|
|
133
|
+
|
|
134
|
+
### GOODBYE Protocol (`/aztec/req/goodbye/1.0.0`)
|
|
135
|
+
|
|
136
|
+
**Responder**: buffer must be 1 byte (defaults to `UNKNOWN` on invalid length). Goodbye reason byte is NOT validated against the enum -- any byte 0-255 accepted. Peer scheduled for disconnect regardless of reason.
|
|
137
|
+
|
|
138
|
+
**Requester**: response errors are never penalized (GOODBYE subprotocol exempt from error categorization).
|
|
139
|
+
|
|
140
|
+
### Periodic Re-validation
|
|
141
|
+
|
|
142
|
+
| Rule | Interval | File |
|
|
143
|
+
|------|----------|------|
|
|
144
|
+
| Authenticated validators re-checked against current validator set | Every heartbeat (`peerCheckIntervalMS`) | `peer_manager.ts` |
|
|
145
|
+
| If validator address no longer registered, auth entry removed | Same | same |
|
|
146
|
+
|
|
147
|
+
Protected peers (private/trusted/preferred) are always considered "authenticated" without AUTH handshake.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Block Data Protocols
|
|
152
|
+
|
|
153
|
+
### BLOCK Protocol (`/aztec/req/block/1.0.0`)
|
|
154
|
+
|
|
155
|
+
**Server side**:
|
|
156
|
+
|
|
157
|
+
| Rule | Consequence | File |
|
|
158
|
+
|------|-------------|------|
|
|
159
|
+
| Request must parse as `Fr` | `BADLY_FORMED_REQUEST` + LowToleranceError | `protocols/block.ts` |
|
|
160
|
+
| Block lookup throws | `INTERNAL_ERROR` status | same |
|
|
161
|
+
| Block not found | SUCCESS + empty buffer (design choice; no `NOT_FOUND` status used) | same |
|
|
162
|
+
|
|
163
|
+
**Requester side** (Snappy limit: 3 MB):
|
|
164
|
+
|
|
165
|
+
| Rule | Consequence | File |
|
|
166
|
+
|------|-------------|------|
|
|
167
|
+
| Response block number must match requested | LowToleranceError; rejected | `libp2p_service.ts` (`validateRequestedBlock`) |
|
|
168
|
+
| Local block must exist for hash verification | Rejected (no penalty) | same |
|
|
169
|
+
| Response block hash must equal local block hash | MidToleranceError; rejected | same |
|
|
170
|
+
|
|
171
|
+
**Limitation**: the local-block requirement means BLOCK req/resp is unusable for initial P2P-only sync (before L1 sync provides local copies for verification). A TODO in the code acknowledges this.
|
|
172
|
+
|
|
173
|
+
### BLOCK_TXS Protocol (`/aztec/req/block_txs/1.0.0`)
|
|
174
|
+
|
|
175
|
+
**Server side**:
|
|
176
|
+
|
|
177
|
+
| Rule | Consequence | File |
|
|
178
|
+
|------|-------------|------|
|
|
179
|
+
| Request must parse as `BlockTxsRequest` (Fr + TxHashArray + BitVector) | `BADLY_FORMED_REQUEST` + LowToleranceError | `protocols/block_txs/block_txs_handler.ts` |
|
|
180
|
+
| BitVector length: non-negative and <= `MAX_TXS_PER_BLOCK` (65536) | Deserialization throws -> `BADLY_FORMED_REQUEST` | `protocols/block_txs/bitvector.ts` |
|
|
181
|
+
| Archive root not found and no explicit txHashes | `NOT_FOUND` status | handler |
|
|
182
|
+
| Internal error during lookup | Unhandled exception -> stream abort (no `INTERNAL_ERROR` status, unlike BLOCK) | handler |
|
|
183
|
+
|
|
184
|
+
Conditional registration: BLOCK_TXS handler only registered when `config.disableTransactions` is false. Otherwise peers get `ERR_UNSUPPORTED_PROTOCOL`.
|
|
185
|
+
|
|
186
|
+
**Requester side via `sendBatchRequest`** (Snappy limit: `max(N, 1) * 512 + 1` KB):
|
|
187
|
+
|
|
188
|
+
| Rule | Consequence | File |
|
|
189
|
+
|------|-------------|------|
|
|
190
|
+
| Archive root must match request | MidToleranceError | `libp2p_service.ts` (`validateRequestedBlockTxs`) |
|
|
191
|
+
| BitVector length must match request | MidToleranceError | same |
|
|
192
|
+
| No duplicate tx hashes | MidToleranceError | same |
|
|
193
|
+
| Tx count within bounds | MidToleranceError | same |
|
|
194
|
+
| Local block proposal must exist for archive root | Rejected (no penalty) | same |
|
|
195
|
+
| All tx hashes must be in proposal's tx list at allowed indices | LowToleranceError | same |
|
|
196
|
+
| Txs in strictly increasing index order | LowToleranceError | same |
|
|
197
|
+
| Each tx passes well-formedness (Metadata [4 fields], Size, Data, Proof) | LowToleranceError | same |
|
|
198
|
+
|
|
199
|
+
**Requester side via `BatchTxRequester`** (separate validation path):
|
|
200
|
+
|
|
201
|
+
| Rule | Consequence | File |
|
|
202
|
+
|------|-------------|------|
|
|
203
|
+
| Non-SUCCESS status: `FAILURE`/`UNKNOWN` | HighToleranceError + "bad peer" tracking | `batch-tx-requester/batch_tx_requester.ts` |
|
|
204
|
+
| `RATE_LIMIT_EXCEEDED` | Peer marked rate-limited (cooldown) | same |
|
|
205
|
+
| `NOT_FOUND` / `BADLY_FORMED_REQUEST` / `INTERNAL_ERROR` | Falls through silently (no penalty) | same |
|
|
206
|
+
| Each tx validated (Metadata + Size + Data + Proof) | LowToleranceError per invalid tx; valid txs from same response still accepted | same |
|
|
207
|
+
| Archive root match + non-empty txIndices | No penalty on mismatch; peer not promoted to "smart" | same |
|
|
208
|
+
|
|
209
|
+
**Double penalty on transport errors**: when `BatchTxRequester` encounters a transport error (e.g., ECONNRESET), both `sendRequestToPeer`'s internal handler and the `BatchTxRequester`'s catch block penalize the peer, resulting in double HighToleranceError.
|
|
210
|
+
|
|
211
|
+
See [BatchTxRequester README](batch-tx-requester/README.md) for the full architecture (peer classification, worker model, wire protocol).
|
|
212
|
+
|
|
213
|
+
### TX Protocol (`/aztec/req/tx/1.0.0`)
|
|
214
|
+
|
|
215
|
+
**Server side**:
|
|
216
|
+
|
|
217
|
+
| Rule | Consequence | File |
|
|
218
|
+
|------|-------------|------|
|
|
219
|
+
| Request must parse as `TxHashArray` | `BADLY_FORMED_REQUEST` + LowToleranceError | `protocols/tx.ts` |
|
|
220
|
+
|
|
221
|
+
**Requester side** (validator registered at startup, not the default noop):
|
|
222
|
+
|
|
223
|
+
| Rule | Consequence | File |
|
|
224
|
+
|------|-------------|------|
|
|
225
|
+
| Each returned tx hash must be in the requested set | MidToleranceError | `libp2p_service.ts` (`validateRequestedTxs`) |
|
|
226
|
+
| Each tx passes well-formedness (Metadata + Size + Data + Proof) | LowToleranceError | same |
|
|
227
|
+
|
|
228
|
+
Snappy limit: `max(N, 1) * 512 + 1` KB.
|
|
229
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
|
|
2
2
|
import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { createTxValidatorForReqResponseReceivedTxs } from '../../../msg_validators/index.js';
|
|
5
5
|
|
|
6
6
|
export interface BatchRequestTxValidatorConfig {
|
|
7
7
|
l1ChainId: number;
|
|
@@ -29,7 +29,7 @@ export class BatchRequestTxValidator implements IBatchRequestTxValidator {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
static createRequestedTxValidator(config: BatchRequestTxValidatorConfig): TxValidator {
|
|
32
|
-
return
|
|
32
|
+
return createTxValidatorForReqResponseReceivedTxs(config.proofVerifier, {
|
|
33
33
|
l1ChainId: config.l1ChainId,
|
|
34
34
|
rollupVersion: config.rollupVersion,
|
|
35
35
|
});
|
|
@@ -97,9 +97,10 @@ export function prettyPrintRateLimitStatus(status: RateLimitStatus) {
|
|
|
97
97
|
* 2. Individual rate limits for each peer.
|
|
98
98
|
*
|
|
99
99
|
* How it works:
|
|
100
|
-
* - When a request comes in, it first checks against the
|
|
101
|
-
* - If the
|
|
102
|
-
* - The request is only allowed if both the
|
|
100
|
+
* - When a request comes in, it first checks against the peer's individual rate limit.
|
|
101
|
+
* - If the peer limit allows, it then checks against the global rate limit.
|
|
102
|
+
* - The request is only allowed if both the peer-specific and global limits allow it.
|
|
103
|
+
* - Checking peer limit first ensures a rate-limited peer cannot exhaust the global quota.
|
|
103
104
|
* - It automatically creates and manages rate limiters for new peers as they make requests.
|
|
104
105
|
* - It periodically cleans up rate limiters for inactive peers to conserve memory.
|
|
105
106
|
*
|
|
@@ -119,10 +120,6 @@ export class SubProtocolRateLimiter {
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
allow(peerId: PeerId): RateLimitStatus {
|
|
122
|
-
if (!this.globalLimiter.allow()) {
|
|
123
|
-
return RateLimitStatus.DeniedGlobal;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
123
|
const peerIdStr = peerId.toString();
|
|
127
124
|
let peerLimiter: PeerRateLimiter | undefined = this.peerLimiters.get(peerIdStr);
|
|
128
125
|
if (!peerLimiter) {
|
|
@@ -135,10 +132,17 @@ export class SubProtocolRateLimiter {
|
|
|
135
132
|
} else {
|
|
136
133
|
peerLimiter.lastAccess = Date.now();
|
|
137
134
|
}
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
|
|
136
|
+
// Check peer limit first: a rate-limited peer must not consume global quota,
|
|
137
|
+
// otherwise one spamming peer can starve all others by exhausting the global bucket.
|
|
138
|
+
if (!peerLimiter.limiter.allow()) {
|
|
140
139
|
return RateLimitStatus.DeniedPeer;
|
|
141
140
|
}
|
|
141
|
+
|
|
142
|
+
if (!this.globalLimiter.allow()) {
|
|
143
|
+
return RateLimitStatus.DeniedGlobal;
|
|
144
|
+
}
|
|
145
|
+
|
|
142
146
|
return RateLimitStatus.Allowed;
|
|
143
147
|
}
|
|
144
148
|
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
IndividualReqRespTimeoutError,
|
|
17
17
|
InvalidResponseError,
|
|
18
18
|
} from '../../errors/reqresp.error.js';
|
|
19
|
-
import { SnappyTransform } from '../encoding.js';
|
|
19
|
+
import { OversizedSnappyResponseError, SnappyTransform } from '../encoding.js';
|
|
20
20
|
import type { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
21
21
|
import {
|
|
22
22
|
DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS,
|
|
@@ -553,16 +553,10 @@ export class ReqResp implements ReqRespInterface {
|
|
|
553
553
|
data: message,
|
|
554
554
|
};
|
|
555
555
|
} catch (e: any) {
|
|
556
|
+
// All errors (invalid status bytes, oversized snappy responses, corrupt data, etc.)
|
|
557
|
+
// are re-thrown so the caller can penalize the peer via handleResponseError.
|
|
556
558
|
this.logger.debug(`Reading message failed: ${e.message}`);
|
|
557
|
-
|
|
558
|
-
let status = ReqRespStatus.UNKNOWN;
|
|
559
|
-
if (e instanceof ReqRespStatusError) {
|
|
560
|
-
status = e.status;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
return {
|
|
564
|
-
status,
|
|
565
|
-
};
|
|
559
|
+
throw e;
|
|
566
560
|
}
|
|
567
561
|
}
|
|
568
562
|
|
|
@@ -778,6 +772,20 @@ export class ReqResp implements ReqRespInterface {
|
|
|
778
772
|
return undefined;
|
|
779
773
|
}
|
|
780
774
|
|
|
775
|
+
// Invalid status byte: the peer sent a status byte that doesn't match any known status code.
|
|
776
|
+
// This is a protocol violation, penalize harshly.
|
|
777
|
+
if (e instanceof ReqRespStatusError) {
|
|
778
|
+
this.logger.warn(`Invalid status byte from peer ${peerId.toString()} in ${subProtocol}: ${e.message}`, logTags);
|
|
779
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// Oversized snappy response: the peer is sending data that exceeds the allowed size.
|
|
783
|
+
// This is a protocol violation that wastes bandwidth, so penalize harshly.
|
|
784
|
+
if (e instanceof OversizedSnappyResponseError) {
|
|
785
|
+
this.logger.warn(`Oversized response from peer ${peerId.toString()} in ${subProtocol}: ${e.message}`, logTags);
|
|
786
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
787
|
+
}
|
|
788
|
+
|
|
781
789
|
return this.categorizeConnectionErrors(e, peerId, subProtocol);
|
|
782
790
|
}
|
|
783
791
|
|
package/src/services/service.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
BlockProposal,
|
|
6
|
+
CheckpointAttestation,
|
|
7
|
+
CheckpointProposalCore,
|
|
8
|
+
Gossipable,
|
|
9
|
+
TopicType,
|
|
10
|
+
} from '@aztec/stdlib/p2p';
|
|
5
11
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
6
12
|
|
|
7
13
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -130,7 +136,10 @@ export interface P2PService {
|
|
|
130
136
|
|
|
131
137
|
getPeers(includePending?: boolean): PeerInfo[];
|
|
132
138
|
|
|
133
|
-
|
|
139
|
+
/** Returns the number of peers in the GossipSub mesh for a given topic type. */
|
|
140
|
+
getGossipMeshPeerCount(topicType: TopicType): number;
|
|
141
|
+
|
|
142
|
+
validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void>;
|
|
134
143
|
|
|
135
144
|
addReqRespSubProtocol(
|
|
136
145
|
subProtocol: ReqRespSubProtocol,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { partitionAsync } from '@aztec/foundation/collection';
|
|
1
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
4
|
import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
|
|
4
|
-
import { Tx, type TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import { Tx, type TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
5
6
|
import {
|
|
6
7
|
type Histogram,
|
|
7
8
|
Metrics,
|
|
@@ -23,6 +24,7 @@ export class FileStoreTxSource implements TxSource {
|
|
|
23
24
|
private readonly fileStore: ReadOnlyFileStore,
|
|
24
25
|
private readonly baseUrl: string,
|
|
25
26
|
private readonly basePath: string,
|
|
27
|
+
private readonly txValidator: TxValidator,
|
|
26
28
|
private readonly log: Logger,
|
|
27
29
|
telemetry: TelemetryClient,
|
|
28
30
|
) {
|
|
@@ -44,6 +46,7 @@ export class FileStoreTxSource implements TxSource {
|
|
|
44
46
|
public static async create(
|
|
45
47
|
url: string,
|
|
46
48
|
basePath: string,
|
|
49
|
+
txValidator: TxValidator,
|
|
47
50
|
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
48
51
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
49
52
|
): Promise<FileStoreTxSource | undefined> {
|
|
@@ -53,7 +56,7 @@ export class FileStoreTxSource implements TxSource {
|
|
|
53
56
|
log.warn(`Failed to create file store for URL: ${url}`);
|
|
54
57
|
return undefined;
|
|
55
58
|
}
|
|
56
|
-
return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
|
|
59
|
+
return new FileStoreTxSource(fileStore, url, basePath, txValidator, log, telemetry);
|
|
57
60
|
} catch (err) {
|
|
58
61
|
log.warn(`Error creating file store for URL: ${url}`, { error: err });
|
|
59
62
|
return undefined;
|
|
@@ -65,35 +68,41 @@ export class FileStoreTxSource implements TxSource {
|
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
|
|
68
|
-
const
|
|
71
|
+
const results = await Promise.all(
|
|
72
|
+
txHashes.map(async txHash => {
|
|
73
|
+
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
74
|
+
const timer = new Timer();
|
|
75
|
+
try {
|
|
76
|
+
const buffer = await this.fileStore.read(path);
|
|
77
|
+
const tx = Tx.fromBuffer(buffer);
|
|
78
|
+
return { tx, downloadDuration: timer.ms(), downloadSize: buffer.length };
|
|
79
|
+
} catch {
|
|
80
|
+
this.downloadsFailed.add(1);
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const txs = results.filter(tx => tx !== undefined);
|
|
87
|
+
const [validTxs, invalidTxs] = await partitionAsync(
|
|
88
|
+
txs,
|
|
89
|
+
async ({ tx, downloadDuration, downloadSize }): Promise<boolean> => {
|
|
90
|
+
const valid = await this.txValidator.validateTx(tx);
|
|
91
|
+
if (valid.result === 'valid') {
|
|
92
|
+
this.downloadsSuccess.add(1);
|
|
93
|
+
this.downloadDuration.record(Math.ceil(downloadDuration));
|
|
94
|
+
this.downloadSize.record(downloadSize);
|
|
95
|
+
return true;
|
|
96
|
+
} else {
|
|
97
|
+
this.downloadsFailed.add(1);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
69
103
|
return {
|
|
70
|
-
validTxs: (
|
|
71
|
-
|
|
72
|
-
txHashes.map(async txHash => {
|
|
73
|
-
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
74
|
-
const timer = new Timer();
|
|
75
|
-
try {
|
|
76
|
-
const buffer = await this.fileStore.read(path);
|
|
77
|
-
const tx = Tx.fromBuffer(buffer);
|
|
78
|
-
if ((await tx.validateTxHash()) && txHash.equals(tx.txHash)) {
|
|
79
|
-
this.downloadsSuccess.add(1);
|
|
80
|
-
this.downloadDuration.record(Math.ceil(timer.ms()));
|
|
81
|
-
this.downloadSize.record(buffer.length);
|
|
82
|
-
return tx;
|
|
83
|
-
} else {
|
|
84
|
-
invalidTxHashes.push(tx.txHash.toString());
|
|
85
|
-
this.downloadsFailed.add(1);
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
} catch {
|
|
89
|
-
// Tx not found or error reading - return undefined
|
|
90
|
-
this.downloadsFailed.add(1);
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
}),
|
|
94
|
-
)
|
|
95
|
-
).filter(tx => tx !== undefined),
|
|
96
|
-
invalidTxHashes: invalidTxHashes,
|
|
104
|
+
validTxs: validTxs.map(({ tx }) => tx),
|
|
105
|
+
invalidTxHashes: invalidTxs.map(({ tx }) => tx.getTxHash().toString()),
|
|
97
106
|
};
|
|
98
107
|
}
|
|
99
108
|
}
|
|
@@ -109,9 +118,12 @@ export class FileStoreTxSource implements TxSource {
|
|
|
109
118
|
export async function createFileStoreTxSources(
|
|
110
119
|
urls: string[],
|
|
111
120
|
basePath: string,
|
|
121
|
+
txValidator: TxValidator,
|
|
112
122
|
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
113
123
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
114
124
|
): Promise<FileStoreTxSource[]> {
|
|
115
|
-
const sources = await Promise.all(
|
|
125
|
+
const sources = await Promise.all(
|
|
126
|
+
urls.map(url => FileStoreTxSource.create(url, basePath, txValidator, log, telemetry)),
|
|
127
|
+
);
|
|
116
128
|
return sources.filter((s): s is FileStoreTxSource => s !== undefined);
|
|
117
129
|
}
|
|
@@ -2,7 +2,7 @@ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
|
2
2
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
3
3
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
4
4
|
import { type AztecNode, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
|
|
5
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
|
|
6
6
|
import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
|
|
7
7
|
import { makeTracedFetch } from '@aztec/telemetry-client';
|
|
8
8
|
|
|
@@ -16,12 +16,13 @@ export interface TxSource {
|
|
|
16
16
|
export class NodeRpcTxSource implements TxSource {
|
|
17
17
|
constructor(
|
|
18
18
|
private readonly client: Pick<AztecNode, 'getTxsByHash'>,
|
|
19
|
+
private readonly txValidator: TxValidator,
|
|
19
20
|
private readonly info: string,
|
|
20
21
|
) {}
|
|
21
22
|
|
|
22
|
-
public static fromUrl(nodeUrl: string, versions: ComponentsVersions): NodeRpcTxSource {
|
|
23
|
+
public static fromUrl(nodeUrl: string, txValidator: TxValidator, versions: ComponentsVersions): NodeRpcTxSource {
|
|
23
24
|
const client = createAztecNodeClient(nodeUrl, versions, makeTracedFetch([1, 2, 3], false));
|
|
24
|
-
return new NodeRpcTxSource(client, nodeUrl);
|
|
25
|
+
return new NodeRpcTxSource(client, txValidator, nodeUrl);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
public getInfo() {
|
|
@@ -38,8 +39,8 @@ export class NodeRpcTxSource implements TxSource {
|
|
|
38
39
|
const invalidTxHashes: string[] = [];
|
|
39
40
|
await Promise.all(
|
|
40
41
|
txs.map(async tx => {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
42
|
+
const validation = await this.txValidator.validateTx(tx);
|
|
43
|
+
if (validation.result === 'valid') {
|
|
43
44
|
validTxs.push(tx);
|
|
44
45
|
} else {
|
|
45
46
|
invalidTxHashes.push(tx.getTxHash().toString());
|
|
@@ -50,7 +51,7 @@ export class NodeRpcTxSource implements TxSource {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
export function createNodeRpcTxSources(urls: string[], chainConfig: ChainConfig) {
|
|
54
|
+
export function createNodeRpcTxSources(urls: string[], txValidator: TxValidator, chainConfig: ChainConfig) {
|
|
54
55
|
const versions = getComponentsVersionsFromConfig(chainConfig, protocolContractsHash, getVKTreeRoot());
|
|
55
|
-
return urls.map(url => NodeRpcTxSource.fromUrl(url, versions));
|
|
56
|
+
return urls.map(url => NodeRpcTxSource.fromUrl(url, txValidator, versions));
|
|
56
57
|
}
|
|
@@ -25,7 +25,7 @@ export class TxProvider implements ITxProvider {
|
|
|
25
25
|
constructor(
|
|
26
26
|
private txCollection: TxCollection,
|
|
27
27
|
private txPool: TxPoolV2,
|
|
28
|
-
private
|
|
28
|
+
private blockProposalTransactionValidator: Pick<P2PClient, 'validateTxsReceivedInBlockProposal'>,
|
|
29
29
|
private log: Logger = createLogger('p2p:tx-collector'),
|
|
30
30
|
client: TelemetryClient = getTelemetryClient(),
|
|
31
31
|
) {
|
|
@@ -227,7 +227,7 @@ export class TxProvider implements ITxProvider {
|
|
|
227
227
|
if (txs.length === 0) {
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
|
-
await this.
|
|
230
|
+
await this.blockProposalTransactionValidator.validateTxsReceivedInBlockProposal(txs);
|
|
231
231
|
await this.txPool.addProtectedTxs(txs, blockHeader);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
@@ -7,7 +7,6 @@ import { sleep } from '@aztec/foundation/sleep';
|
|
|
7
7
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
8
8
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
9
9
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
11
10
|
|
|
12
11
|
import { createP2PClient } from '../client/index.js';
|
|
13
12
|
import type { P2PClient } from '../client/p2p_client.js';
|
|
@@ -98,7 +97,6 @@ export async function makeTestP2PClient(
|
|
|
98
97
|
const kvStore = await openTmpStore('test');
|
|
99
98
|
|
|
100
99
|
const client = await createP2PClient(
|
|
101
|
-
P2PClientType.Full,
|
|
102
100
|
config,
|
|
103
101
|
l2BlockSource,
|
|
104
102
|
proofVerifier,
|
|
@@ -4,7 +4,6 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
|
4
4
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
5
5
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
6
6
|
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
8
7
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
9
8
|
|
|
10
9
|
import type { GossipsubEvents, GossipsubMessage } from '@chainsafe/libp2p-gossipsub';
|
|
@@ -42,11 +41,10 @@ type GossipSubService = PubSubLibp2p['services']['pubsub'];
|
|
|
42
41
|
* Given a mock gossip sub network, returns a factory function that creates an instance LibP2PService connected to it.
|
|
43
42
|
* Designed to be used in tests in P2PClientDeps.p2pServiceFactory.
|
|
44
43
|
*/
|
|
45
|
-
export function getMockPubSubP2PServiceFactory
|
|
44
|
+
export function getMockPubSubP2PServiceFactory(
|
|
46
45
|
network: MockGossipSubNetwork,
|
|
47
|
-
): (...args: Parameters<(typeof LibP2PService
|
|
46
|
+
): (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService> {
|
|
48
47
|
return (
|
|
49
|
-
clientType: P2PClientType,
|
|
50
48
|
config: P2PConfig,
|
|
51
49
|
peerId: PeerId,
|
|
52
50
|
deps: {
|
|
@@ -66,8 +64,7 @@ export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
|
|
|
66
64
|
const peerManager = new DummyPeerManager(peerId, network);
|
|
67
65
|
const reqresp: ReqRespInterface = new MockReqResp(peerId, network);
|
|
68
66
|
const peerDiscoveryService = new DummyPeerDiscoveryService();
|
|
69
|
-
const service = new LibP2PService
|
|
70
|
-
clientType as T,
|
|
67
|
+
const service = new LibP2PService(
|
|
71
68
|
config,
|
|
72
69
|
libp2p,
|
|
73
70
|
peerDiscoveryService,
|
|
@@ -270,6 +267,16 @@ class MockGossipSubService extends TypedEventEmitter<GossipsubEvents> implements
|
|
|
270
267
|
{ msgId, propagationSource, acceptance },
|
|
271
268
|
);
|
|
272
269
|
}
|
|
270
|
+
|
|
271
|
+
getMeshPeers(topic?: TopicStr): PeerIdStr[] {
|
|
272
|
+
if (topic && !this.subscribedTopics.has(topic)) {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
return this.network
|
|
276
|
+
.getPeers()
|
|
277
|
+
.filter(peer => !this.peerId.equals(peer))
|
|
278
|
+
.map(peer => peer.toString());
|
|
279
|
+
}
|
|
273
280
|
}
|
|
274
281
|
|
|
275
282
|
/**
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
IVCProofVerificationResult,
|
|
13
13
|
WorldStateSynchronizer,
|
|
14
14
|
} from '@aztec/stdlib/interfaces/server';
|
|
15
|
-
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
16
15
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
17
16
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
18
17
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -107,8 +106,7 @@ export async function createLibp2pNode(
|
|
|
107
106
|
*
|
|
108
107
|
*
|
|
109
108
|
*/
|
|
110
|
-
export async function createTestLibP2PService
|
|
111
|
-
clientType: T,
|
|
109
|
+
export async function createTestLibP2PService(
|
|
112
110
|
boostrapAddrs: string[] = [],
|
|
113
111
|
archiver: L2BlockSource & ContractDataSource,
|
|
114
112
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
@@ -159,8 +157,7 @@ export async function createTestLibP2PService<T extends P2PClientType>(
|
|
|
159
157
|
p2pNode.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
|
|
160
158
|
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
161
159
|
|
|
162
|
-
return new LibP2PService
|
|
163
|
-
clientType,
|
|
160
|
+
return new LibP2PService(
|
|
164
161
|
config,
|
|
165
162
|
p2pNode as PubSubLibp2p,
|
|
166
163
|
discoveryService,
|
|
@@ -76,7 +76,7 @@ export class InMemoryTxPool extends EventEmitter implements TxPoolV2 {
|
|
|
76
76
|
return Promise.resolve({ accepted, ignored: [], rejected: [] });
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'
|
|
79
|
+
canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'> {
|
|
80
80
|
const key = tx.getTxHash().toString();
|
|
81
81
|
if (this.txsByHash.has(key)) {
|
|
82
82
|
return Promise.resolve('ignored');
|
|
@@ -292,6 +292,7 @@ export function createMockEpochCache(): EpochCacheInterface {
|
|
|
292
292
|
ethereumSlotDuration: 1,
|
|
293
293
|
proofSubmissionEpochs: 1,
|
|
294
294
|
targetCommitteeSize: 48,
|
|
295
|
+
rollupManaLimit: Number.MAX_SAFE_INTEGER,
|
|
295
296
|
}),
|
|
296
297
|
};
|
|
297
298
|
}
|