@aztec/p2p 0.0.1-commit.e3c1de76 → 0.0.1-commit.e558bd1c
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 +3 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +5 -3
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +7 -4
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +22 -7
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -1
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +94 -87
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +411 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- 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 +351 -85
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- package/dest/mem_pools/index.d.ts +2 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +4 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/index.d.ts +2 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +1 -0
- package/dest/services/libp2p/libp2p_service.d.ts +74 -33
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +299 -228
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -4
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +8 -8
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -11
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +15 -10
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +12 -11
- package/dest/services/service.d.ts +18 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +3 -3
- package/dest/services/tx_collection/config.js +3 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -5
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +10 -14
- package/dest/services/tx_collection/index.d.ts +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +12 -12
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -5
- package/dest/services/tx_file_store/config.d.ts +18 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +26 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +149 -0
- package/dest/test-helpers/testbench-utils.d.ts +10 -16
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +32 -30
- package/dest/testbench/p2p_client_testbench_worker.js +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +7 -4
- package/src/client/interface.ts +13 -1
- package/src/client/p2p_client.ts +30 -8
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -1
- package/src/config.ts +8 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +436 -100
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/index.ts +1 -1
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +209 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
- package/src/mem_pools/tx_pool_v2/index.ts +11 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/services/dummy_service.ts +6 -0
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/libp2p_service.ts +304 -230
- package/src/services/reqresp/batch-tx-requester/README.md +7 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +11 -11
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +22 -13
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +21 -15
- package/src/services/service.ts +20 -0
- package/src/services/tx_collection/config.ts +6 -6
- package/src/services/tx_collection/fast_tx_collection.ts +14 -24
- package/src/services/tx_collection/index.ts +1 -1
- package/src/services/tx_collection/proposal_tx_collector.ts +12 -14
- package/src/services/tx_file_store/config.ts +43 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +173 -0
- package/src/test-helpers/testbench-utils.ts +18 -39
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# BatchTxRequester
|
|
2
2
|
|
|
3
|
-
The `BatchTxRequester` is a specialized P2P service that aggressively fetches missing transactions from peers when a node
|
|
3
|
+
The `BatchTxRequester` is a specialized P2P service that aggressively fetches missing transactions from peers when a node lacks some of the referenced transactions. It serves two pathways: (1) block proposals, where validators need all transactions to attest, and (2) block proving, where provers need all transactions to generate proofs.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
When a validator receives a block proposal, they must
|
|
7
|
+
When a validator receives a block proposal or a prover needs to prove a block, they must have all transactions. If some transactions are missing from the local mempool (e.g., due to gossip delays), the `BatchTxRequester` kicks in to fetch them via direct peer-to-peer requests before the deadline.
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
11
|
-
│
|
|
11
|
+
│ Block Proposal or Block Received │
|
|
12
12
|
│ (contains hashes of N transactions) │
|
|
13
13
|
└─────────────────────────────────────────────────────────────────────────────┘
|
|
14
14
|
│
|
|
@@ -230,8 +230,8 @@ Request to peer fails
|
|
|
230
230
|
```typescript
|
|
231
231
|
const requester = new BatchTxRequester(
|
|
232
232
|
missingTxHashes, // TxHash[] - what we need
|
|
233
|
-
|
|
234
|
-
pinnedPeer, // PeerId | undefined -
|
|
233
|
+
blockTxsSource, // BlockTxsSource - the proposal or block we need txs for
|
|
234
|
+
pinnedPeer, // PeerId | undefined - peer expected to have the txs
|
|
235
235
|
timeoutMs, // number - how long to try
|
|
236
236
|
p2pService, // BatchTxRequesterLibP2PService
|
|
237
237
|
);
|
|
@@ -268,14 +268,14 @@ const txs = await BatchTxRequester.collectAllTxs(requester.run());
|
|
|
268
268
|
┌───────────────────────────────────┐ ┌─────────────────────────────────────┐
|
|
269
269
|
│ FastTxCollection │ │ SlowTxCollection │
|
|
270
270
|
│ │ │ │
|
|
271
|
-
│ Time-critical:
|
|
271
|
+
│ Time-critical: proposals/proving │ │ Background: unproven blocks │
|
|
272
272
|
│ │ │ │
|
|
273
273
|
│ 1. Try RPC nodes first (fast) │ │ Periodic polling of RPC nodes │
|
|
274
274
|
│ 2. Fall back to BatchTxRequester │ │ and peers for missing txs │
|
|
275
275
|
│ │ │ │
|
|
276
276
|
└───────────────────┬───────────────┘ └─────────────────────────────────────┘
|
|
277
277
|
│
|
|
278
|
-
│ For 'proposal' requests
|
|
278
|
+
│ For 'proposal' and 'block' requests
|
|
279
279
|
▼
|
|
280
280
|
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
281
281
|
│ BatchTxRequester │
|
|
@@ -4,14 +4,14 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
4
4
|
import { FifoMemoryQueue, type ISemaphore, Semaphore } from '@aztec/foundation/queue';
|
|
5
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
6
|
import { DateProvider, executeTimeout } from '@aztec/foundation/timer';
|
|
7
|
-
import {
|
|
7
|
+
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
8
8
|
import { Tx, TxArray, TxHash } from '@aztec/stdlib/tx';
|
|
9
9
|
|
|
10
10
|
import type { PeerId } from '@libp2p/interface';
|
|
11
11
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
12
12
|
|
|
13
13
|
import { ReqRespSubProtocol } from '.././interface.js';
|
|
14
|
-
import { BlockTxsRequest, BlockTxsResponse } from '.././protocols/index.js';
|
|
14
|
+
import { BlockTxsRequest, BlockTxsResponse, type BlockTxsSource } from '.././protocols/index.js';
|
|
15
15
|
import { ReqRespStatus } from '.././status.js';
|
|
16
16
|
import {
|
|
17
17
|
DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD,
|
|
@@ -42,7 +42,7 @@ import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_val
|
|
|
42
42
|
* - Is the peer which was unable to send us successful response N times in a row
|
|
43
43
|
* */
|
|
44
44
|
export class BatchTxRequester {
|
|
45
|
-
private readonly
|
|
45
|
+
private readonly blockTxsSource: BlockTxsSource;
|
|
46
46
|
private readonly pinnedPeer: PeerId | undefined;
|
|
47
47
|
private readonly timeoutMs: number;
|
|
48
48
|
private readonly p2pService: BatchTxRequesterLibP2PService;
|
|
@@ -61,7 +61,7 @@ export class BatchTxRequester {
|
|
|
61
61
|
|
|
62
62
|
constructor(
|
|
63
63
|
missingTxs: TxHash[],
|
|
64
|
-
|
|
64
|
+
blockTxsSource: BlockTxsSource,
|
|
65
65
|
pinnedPeer: PeerId | undefined,
|
|
66
66
|
timeoutMs: number,
|
|
67
67
|
p2pService: BatchTxRequesterLibP2PService,
|
|
@@ -69,7 +69,7 @@ export class BatchTxRequester {
|
|
|
69
69
|
dateProvider?: DateProvider,
|
|
70
70
|
opts?: BatchTxRequesterOptions,
|
|
71
71
|
) {
|
|
72
|
-
this.
|
|
72
|
+
this.blockTxsSource = blockTxsSource;
|
|
73
73
|
this.pinnedPeer = pinnedPeer;
|
|
74
74
|
this.timeoutMs = timeoutMs;
|
|
75
75
|
this.p2pService = p2pService;
|
|
@@ -205,7 +205,7 @@ export class BatchTxRequester {
|
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
const request = BlockTxsRequest.
|
|
208
|
+
const request = BlockTxsRequest.fromTxsSourceAndMissingTxs(this.blockTxsSource, txs);
|
|
209
209
|
if (!request) {
|
|
210
210
|
return;
|
|
211
211
|
}
|
|
@@ -249,8 +249,8 @@ export class BatchTxRequester {
|
|
|
249
249
|
// If peer is dumb peer, we don't know yet if they received full blockProposal
|
|
250
250
|
// there is solid chance that peer didn't receive proposal yet, thus we must send full hashes
|
|
251
251
|
const includeFullHashesInRequestNotJustIndices = true;
|
|
252
|
-
const blockRequest = BlockTxsRequest.
|
|
253
|
-
this.
|
|
252
|
+
const blockRequest = BlockTxsRequest.fromTxsSourceAndMissingTxs(
|
|
253
|
+
this.blockTxsSource,
|
|
254
254
|
txs,
|
|
255
255
|
includeFullHashesInRequestNotJustIndices,
|
|
256
256
|
);
|
|
@@ -342,7 +342,7 @@ export class BatchTxRequester {
|
|
|
342
342
|
|
|
343
343
|
const makeRequest = (pid: PeerId) => {
|
|
344
344
|
const txs = this.txsMetadata.getTxsToRequestFromThePeer(pid);
|
|
345
|
-
const blockRequest = BlockTxsRequest.
|
|
345
|
+
const blockRequest = BlockTxsRequest.fromTxsSourceAndMissingTxs(this.blockTxsSource, txs);
|
|
346
346
|
if (!blockRequest) {
|
|
347
347
|
return undefined;
|
|
348
348
|
}
|
|
@@ -605,7 +605,7 @@ export class BatchTxRequester {
|
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
private isBlockResponseValid(response: BlockTxsResponse): boolean {
|
|
608
|
-
const archiveRootsMatch = this.
|
|
608
|
+
const archiveRootsMatch = this.blockTxsSource.archive.toString() === response.archiveRoot.toString();
|
|
609
609
|
const peerHasSomeTxsFromProposal = !response.txIndices.isEmpty();
|
|
610
610
|
return archiveRootsMatch && peerHasSomeTxsFromProposal;
|
|
611
611
|
}
|
|
@@ -624,7 +624,7 @@ export class BatchTxRequester {
|
|
|
624
624
|
private extractHashesPeerHasFromResponse(response: BlockTxsResponse): Array<TxHash> {
|
|
625
625
|
const hashes: TxHash[] = [];
|
|
626
626
|
const indicesOfHashesPeerHas = new Set(response.txIndices.getTrueIndices());
|
|
627
|
-
this.
|
|
627
|
+
this.blockTxsSource.txHashes.forEach((hash, idx) => {
|
|
628
628
|
if (indicesOfHashesPeerHas.has(idx)) {
|
|
629
629
|
hashes.push(hash);
|
|
630
630
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
2
3
|
import { TxArray } from '@aztec/stdlib/tx';
|
|
3
4
|
|
|
4
5
|
import type { PeerId } from '@libp2p/interface';
|
|
5
6
|
|
|
6
|
-
import type {
|
|
7
|
+
import type { AttestationPoolApi } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
|
|
7
8
|
import type { TxPool } from '../../../../mem_pools/index.js';
|
|
8
9
|
import type { ReqRespSubProtocolHandler } from '../../interface.js';
|
|
9
10
|
import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
|
|
@@ -13,10 +14,15 @@ import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
|
|
|
13
14
|
/**
|
|
14
15
|
* Handler for block txs requests
|
|
15
16
|
* @param attestationPool - the attestation pool to check for block proposals
|
|
16
|
-
* @param
|
|
17
|
+
* @param archiver - the archiver to look up blocks by archive root
|
|
18
|
+
* @param txPool - the tx pool to fetch transactions from
|
|
17
19
|
* @returns the BlockTxs request handler
|
|
18
20
|
*/
|
|
19
|
-
export function reqRespBlockTxsHandler(
|
|
21
|
+
export function reqRespBlockTxsHandler(
|
|
22
|
+
attestationPool: AttestationPoolApi,
|
|
23
|
+
archiver: L2BlockSource,
|
|
24
|
+
txPool: TxPool,
|
|
25
|
+
): ReqRespSubProtocolHandler {
|
|
20
26
|
/**
|
|
21
27
|
* Handler for block txs requests
|
|
22
28
|
* @param msg - the block txs request message
|
|
@@ -30,34 +36,37 @@ export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool:
|
|
|
30
36
|
} catch (err: any) {
|
|
31
37
|
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
32
38
|
}
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
// First try attestation pool, then fall back to archiver
|
|
40
|
+
let txHashes = (await attestationPool.getBlockProposal(request.archiveRoot.toString()))?.txHashes;
|
|
41
|
+
if (!txHashes) {
|
|
42
|
+
txHashes = (await archiver.getL2BlockByArchive(request.archiveRoot))?.body.txEffects.map(effect => effect.txHash);
|
|
43
|
+
}
|
|
35
44
|
|
|
36
45
|
let requestedTxsHashes;
|
|
37
46
|
if (request.txHashes.length > 0) {
|
|
38
47
|
requestedTxsHashes = request.txHashes;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
// This is scenario in which we don't have this block
|
|
50
|
+
// This is scenario in which we don't have this block the peer is requesting from us
|
|
42
51
|
// But peer has sent requested tx hashes, so we can send them the transactions
|
|
43
|
-
if (!
|
|
52
|
+
if (!txHashes && requestedTxsHashes !== undefined) {
|
|
44
53
|
const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
|
|
45
54
|
const response = new BlockTxsResponse(Fr.zero(), new TxArray(...responseTxs), BitVector.init(0, []));
|
|
46
55
|
return response.toBuffer();
|
|
47
56
|
}
|
|
48
57
|
|
|
49
|
-
// If don't have this block
|
|
50
|
-
if (!
|
|
58
|
+
// If we don't have this block and peer has not sent requested tx hashes
|
|
59
|
+
if (!txHashes) {
|
|
51
60
|
throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
|
|
52
61
|
}
|
|
53
62
|
|
|
54
|
-
const txsAvailableInPool = await txPool.hasTxs(
|
|
55
|
-
//Map txs in the pool to their indices in the block
|
|
63
|
+
const txsAvailableInPool = await txPool.hasTxs(txHashes);
|
|
64
|
+
// Map txs in the pool to their indices in the block
|
|
56
65
|
const availableIndices = txsAvailableInPool.map((hasTx, idx) => (hasTx ? idx : -1)).filter(idx => idx !== -1);
|
|
57
|
-
const responseBitVector = BitVector.init(
|
|
66
|
+
const responseBitVector = BitVector.init(txHashes.length, availableIndices);
|
|
58
67
|
|
|
59
68
|
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
60
|
-
requestedTxsHashes =
|
|
69
|
+
requestedTxsHashes = txHashes.filter((_, idx) => requestedIndices.has(idx));
|
|
61
70
|
|
|
62
71
|
const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
|
|
63
72
|
const response = new BlockTxsResponse(request.archiveRoot, new TxArray(...responseTxs), responseBitVector);
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import type
|
|
4
|
-
import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
3
|
+
import { TxArray, type TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
5
4
|
|
|
6
5
|
import { BitVector } from './bitvector.js';
|
|
7
6
|
|
|
7
|
+
/** Minimal interface for a block source that provides tx hashes and an archive root. */
|
|
8
|
+
export interface BlockTxsSource {
|
|
9
|
+
txHashes: TxHash[];
|
|
10
|
+
archive: Fr;
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* Request message for requesting specific transactions from a block
|
|
10
15
|
*/
|
|
@@ -22,16 +27,17 @@ export class BlockTxsRequest {
|
|
|
22
27
|
) {}
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
|
-
* Creates new BlockTxsRequest given
|
|
30
|
+
* Creates new BlockTxsRequest given a block txs source and missing tx hashes.
|
|
26
31
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
32
|
+
* @param blockTxsSource - The block or proposal for which we are making the request
|
|
33
|
+
* @param missingTxHashes - Tx hashes from the source we are missing
|
|
34
|
+
* @param includeFullTxHashes - Whether to include full list of missing tx hashes in the request or just Bitvector indices
|
|
30
35
|
*
|
|
31
|
-
* @returns undefined if there were no missingTxHashes matching
|
|
32
|
-
* returns new BlockTxsRequest
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
* @returns undefined if there were no missingTxHashes matching the source hashes, otherwise
|
|
37
|
+
* returns new BlockTxsRequest
|
|
38
|
+
*/
|
|
39
|
+
static fromTxsSourceAndMissingTxs(
|
|
40
|
+
blockTxsSource: BlockTxsSource,
|
|
35
41
|
missingTxHashes: TxHash[],
|
|
36
42
|
includeFullTxHashes = false,
|
|
37
43
|
): BlockTxsRequest | undefined {
|
|
@@ -41,19 +47,19 @@ export class BlockTxsRequest {
|
|
|
41
47
|
|
|
42
48
|
const missingHashesSet = new Set(missingTxHashes.map(t => t.toString()));
|
|
43
49
|
|
|
44
|
-
// We cannot request txs that are not part of the block
|
|
45
|
-
if (!missingHashesSet.isSubsetOf(new Set(
|
|
50
|
+
// We cannot request txs that are not part of the block
|
|
51
|
+
if (!missingHashesSet.isSubsetOf(new Set(blockTxsSource.txHashes.map(t => t.toString())))) {
|
|
46
52
|
return undefined;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
const missingIndices =
|
|
55
|
+
const missingIndices = blockTxsSource.txHashes
|
|
50
56
|
.map((hash, idx) => (missingHashesSet.has(hash.toString()) ? idx : -1))
|
|
51
57
|
.filter(i => i != -1);
|
|
52
58
|
|
|
53
|
-
const requestBitVector = BitVector.init(
|
|
59
|
+
const requestBitVector = BitVector.init(blockTxsSource.txHashes.length, missingIndices);
|
|
54
60
|
const hashes = includeFullTxHashes ? new TxHashArray(...missingTxHashes) : new TxHashArray();
|
|
55
61
|
|
|
56
|
-
return new BlockTxsRequest(
|
|
62
|
+
return new BlockTxsRequest(blockTxsSource.archive, hashes, requestBitVector);
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
/**
|
package/src/services/service.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
3
4
|
import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore, Gossipable } from '@aztec/stdlib/p2p';
|
|
@@ -43,6 +44,19 @@ export type P2PCheckpointReceivedCallback = (
|
|
|
43
44
|
|
|
44
45
|
export type AuthReceivedCallback = (peerId: PeerId, authRequest: AuthRequest) => Promise<AuthResponse | undefined>;
|
|
45
46
|
|
|
47
|
+
/** Minimal info passed to the duplicate proposal callback. */
|
|
48
|
+
export type DuplicateProposalInfo = {
|
|
49
|
+
slot: SlotNumber;
|
|
50
|
+
proposer: EthAddress;
|
|
51
|
+
type: 'checkpoint' | 'block';
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Callback for when a duplicate proposal is detected (equivocation).
|
|
56
|
+
* Invoked on the first duplicate (when count goes from 1 to 2).
|
|
57
|
+
*/
|
|
58
|
+
export type P2PDuplicateProposalCallback = (info: DuplicateProposalInfo) => void;
|
|
59
|
+
|
|
46
60
|
/**
|
|
47
61
|
* The interface for a P2P service implementation.
|
|
48
62
|
*/
|
|
@@ -86,6 +100,12 @@ export interface P2PService {
|
|
|
86
100
|
|
|
87
101
|
registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback): void;
|
|
88
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Registers a callback invoked when a duplicate proposal is detected (equivocation).
|
|
105
|
+
* The callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
106
|
+
*/
|
|
107
|
+
registerDuplicateProposalCallback(callback: P2PDuplicateProposalCallback): void;
|
|
108
|
+
|
|
89
109
|
getEnr(): ENR | undefined;
|
|
90
110
|
|
|
91
111
|
getPeers(includePending?: boolean): PeerInfo[];
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from '@aztec/foundation/config';
|
|
7
7
|
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/api-limit';
|
|
8
8
|
|
|
9
|
-
export type
|
|
9
|
+
export type MissingTxsCollectorType = 'new' | 'old';
|
|
10
10
|
|
|
11
11
|
export type TxCollectionConfig = {
|
|
12
12
|
/** How long to wait before starting reqresp for fast collection */
|
|
@@ -29,8 +29,8 @@ export type TxCollectionConfig = {
|
|
|
29
29
|
txCollectionFastMaxParallelRequestsPerNode: number;
|
|
30
30
|
/** Maximum number of transactions to request from a node in a single batch */
|
|
31
31
|
txCollectionNodeRpcMaxBatchSize: number;
|
|
32
|
-
/** Which collector implementation to use for
|
|
33
|
-
|
|
32
|
+
/** Which collector implementation to use for missing txs collection */
|
|
33
|
+
txCollectionMissingTxsCollectorType: MissingTxsCollectorType;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig> = {
|
|
@@ -90,9 +90,9 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
|
|
|
90
90
|
description: 'Maximum number of transactions to request from a node in a single batch',
|
|
91
91
|
...numberConfigHelper(MAX_RPC_TXS_LEN),
|
|
92
92
|
},
|
|
93
|
-
|
|
94
|
-
env: '
|
|
95
|
-
description: 'Which collector implementation to use for
|
|
93
|
+
txCollectionMissingTxsCollectorType: {
|
|
94
|
+
env: 'TX_COLLECTION_MISSING_TXS_COLLECTOR_TYPE',
|
|
95
|
+
description: 'Which collector implementation to use for missing txs collection (new or old)',
|
|
96
96
|
...enumConfigHelper(['new', 'old'] as const, 'new'),
|
|
97
97
|
},
|
|
98
98
|
};
|
|
@@ -2,7 +2,6 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { times } from '@aztec/foundation/collection';
|
|
3
3
|
import { AbortError, TimeoutError } from '@aztec/foundation/error';
|
|
4
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { boundInclusive } from '@aztec/foundation/number';
|
|
6
5
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
7
6
|
import { sleep } from '@aztec/foundation/sleep';
|
|
8
7
|
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
@@ -14,12 +13,10 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
14
13
|
|
|
15
14
|
import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
|
|
16
15
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
17
|
-
import { ReqRespSubProtocol } from '../reqresp/interface.js';
|
|
18
|
-
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
19
16
|
import type { TxCollectionConfig } from './config.js';
|
|
20
17
|
import {
|
|
21
18
|
BatchTxRequesterCollector,
|
|
22
|
-
type
|
|
19
|
+
type MissingTxsCollector,
|
|
23
20
|
SendBatchRequestCollector,
|
|
24
21
|
} from './proposal_tx_collector.js';
|
|
25
22
|
import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
|
|
@@ -29,22 +26,22 @@ import type { TxSource } from './tx_source.js';
|
|
|
29
26
|
export class FastTxCollection {
|
|
30
27
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
31
28
|
protected requests: Set<FastCollectionRequest> = new Set();
|
|
32
|
-
private
|
|
29
|
+
private missingTxsCollector: MissingTxsCollector;
|
|
33
30
|
|
|
34
31
|
constructor(
|
|
35
|
-
|
|
32
|
+
p2pService: BatchTxRequesterLibP2PService,
|
|
36
33
|
private nodes: TxSource[],
|
|
37
34
|
private txCollectionSink: TxCollectionSink,
|
|
38
35
|
private config: TxCollectionConfig,
|
|
39
36
|
private dateProvider: DateProvider = new DateProvider(),
|
|
40
37
|
private log: Logger = createLogger('p2p:tx_collection_service'),
|
|
41
|
-
|
|
38
|
+
missingTxsCollector?: MissingTxsCollector,
|
|
42
39
|
) {
|
|
43
40
|
const batchTxRequesterConfig = this.config as Partial<BatchTxRequesterConfig>;
|
|
44
|
-
const
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
(
|
|
41
|
+
const missingTxsCollectorType = this.config.txCollectionMissingTxsCollectorType;
|
|
42
|
+
this.missingTxsCollector =
|
|
43
|
+
missingTxsCollector ??
|
|
44
|
+
(missingTxsCollectorType === 'old'
|
|
48
45
|
? new SendBatchRequestCollector(p2pService)
|
|
49
46
|
: new BatchTxRequesterCollector(p2pService, log, dateProvider, undefined, batchTxRequesterConfig));
|
|
50
47
|
}
|
|
@@ -258,8 +255,6 @@ export class FastTxCollection {
|
|
|
258
255
|
private async collectFastViaReqResp(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
|
|
259
256
|
const timeoutMs = +request.deadline - this.dateProvider.now();
|
|
260
257
|
const pinnedPeer = opts.pinnedPeer;
|
|
261
|
-
const maxPeers = boundInclusive(Math.ceil(request.missingTxHashes.size / 2), 8, 32);
|
|
262
|
-
const maxRetryAttempts = 5;
|
|
263
258
|
const blockInfo = request.blockInfo;
|
|
264
259
|
const slotNumber = blockInfo.slotNumber;
|
|
265
260
|
if (timeoutMs < 100) {
|
|
@@ -279,18 +274,13 @@ export class FastTxCollection {
|
|
|
279
274
|
await this.txCollectionSink.collect(
|
|
280
275
|
async txHashes => {
|
|
281
276
|
if (request.type === 'proposal') {
|
|
282
|
-
return await this.
|
|
277
|
+
return await this.missingTxsCollector.collectTxs(txHashes, request.blockProposal, pinnedPeer, timeoutMs);
|
|
283
278
|
} else if (request.type === 'block') {
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
maxPeers,
|
|
290
|
-
maxRetryAttempts,
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
return txs.flat();
|
|
279
|
+
const blockTxsSource = {
|
|
280
|
+
txHashes: request.block.body.txEffects.map(e => e.txHash),
|
|
281
|
+
archive: request.block.archive.root,
|
|
282
|
+
};
|
|
283
|
+
return await this.missingTxsCollector.collectTxs(txHashes, blockTxsSource, pinnedPeer, timeoutMs);
|
|
294
284
|
} else {
|
|
295
285
|
throw new Error(`Unknown request type: ${(request as any).type}`);
|
|
296
286
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { TxCollection, type FastCollectionRequestInput } from './tx_collection.js';
|
|
2
2
|
export { type TxSource, createNodeRpcTxSources, NodeRpcTxSource } from './tx_source.js';
|
|
3
3
|
export {
|
|
4
|
-
type
|
|
4
|
+
type MissingTxsCollector,
|
|
5
5
|
BatchTxRequesterCollector,
|
|
6
6
|
SendBatchRequestCollector,
|
|
7
7
|
} from './proposal_tx_collector.js';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
-
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
4
3
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
4
|
|
|
6
5
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -9,25 +8,24 @@ import { BatchTxRequester } from '../reqresp/batch-tx-requester/batch_tx_request
|
|
|
9
8
|
import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
|
|
10
9
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
11
10
|
import type { IBatchRequestTxValidator } from '../reqresp/batch-tx-requester/tx_validator.js';
|
|
12
|
-
import { ReqRespSubProtocol } from '../reqresp/
|
|
13
|
-
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
11
|
+
import { type BlockTxsSource, ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
|
-
* Strategy interface for collecting transactions for block
|
|
14
|
+
* Strategy interface for collecting missing transactions for a block or proposal.
|
|
17
15
|
* Allows swapping between different tx collection implementations for benchmarking.
|
|
18
16
|
*/
|
|
19
|
-
export interface
|
|
17
|
+
export interface MissingTxsCollector {
|
|
20
18
|
/**
|
|
21
|
-
* Collect transactions for a block proposal.
|
|
19
|
+
* Collect missing transactions for a block or proposal.
|
|
22
20
|
* @param txHashes - The transaction hashes to collect
|
|
23
|
-
* @param
|
|
24
|
-
* @param pinnedPeer - Optional peer
|
|
21
|
+
* @param blockTxsSource - The block or proposal containing the transactions
|
|
22
|
+
* @param pinnedPeer - Optional peer expected to have the transactions
|
|
25
23
|
* @param timeoutMs - Timeout in milliseconds
|
|
26
24
|
* @returns The collected transactions
|
|
27
25
|
*/
|
|
28
26
|
collectTxs(
|
|
29
27
|
txHashes: TxHash[],
|
|
30
|
-
|
|
28
|
+
blockTxsSource: BlockTxsSource,
|
|
31
29
|
pinnedPeer: PeerId | undefined,
|
|
32
30
|
timeoutMs: number,
|
|
33
31
|
): Promise<Tx[]>;
|
|
@@ -37,7 +35,7 @@ export interface ProposalTxCollector {
|
|
|
37
35
|
* Collects transactions using the BatchTxRequester implementation.
|
|
38
36
|
* This uses a smart/dumb peer strategy with parallel workers.
|
|
39
37
|
*/
|
|
40
|
-
export class BatchTxRequesterCollector implements
|
|
38
|
+
export class BatchTxRequesterCollector implements MissingTxsCollector {
|
|
41
39
|
constructor(
|
|
42
40
|
private p2pService: BatchTxRequesterLibP2PService,
|
|
43
41
|
private log: Logger,
|
|
@@ -48,7 +46,7 @@ export class BatchTxRequesterCollector implements ProposalTxCollector {
|
|
|
48
46
|
|
|
49
47
|
async collectTxs(
|
|
50
48
|
txHashes: TxHash[],
|
|
51
|
-
|
|
49
|
+
blockTxsSource: BlockTxsSource,
|
|
52
50
|
pinnedPeer: PeerId | undefined,
|
|
53
51
|
timeoutMs: number,
|
|
54
52
|
): Promise<Tx[]> {
|
|
@@ -61,7 +59,7 @@ export class BatchTxRequesterCollector implements ProposalTxCollector {
|
|
|
61
59
|
|
|
62
60
|
const batchRequester = new BatchTxRequester(
|
|
63
61
|
txHashes,
|
|
64
|
-
|
|
62
|
+
blockTxsSource,
|
|
65
63
|
pinnedPeer,
|
|
66
64
|
timeoutMs,
|
|
67
65
|
this.p2pService,
|
|
@@ -87,7 +85,7 @@ const DEFAULT_MAX_RETRY_ATTEMPTS = 3;
|
|
|
87
85
|
* Collects transactions using the sendBatchRequest implementation from ReqResp.
|
|
88
86
|
* This is the original implementation that balances requests across peers.
|
|
89
87
|
*/
|
|
90
|
-
export class SendBatchRequestCollector implements
|
|
88
|
+
export class SendBatchRequestCollector implements MissingTxsCollector {
|
|
91
89
|
constructor(
|
|
92
90
|
private p2pService: BatchTxRequesterLibP2PService,
|
|
93
91
|
private maxPeers: number = DEFAULT_MAX_PEERS,
|
|
@@ -96,7 +94,7 @@ export class SendBatchRequestCollector implements ProposalTxCollector {
|
|
|
96
94
|
|
|
97
95
|
async collectTxs(
|
|
98
96
|
txHashes: TxHash[],
|
|
99
|
-
|
|
97
|
+
_blockTxsSource: BlockTxsSource,
|
|
100
98
|
pinnedPeer: PeerId | undefined,
|
|
101
99
|
timeoutMs: number,
|
|
102
100
|
): Promise<Tx[]> {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the TxFileStore service.
|
|
5
|
+
*/
|
|
6
|
+
export type TxFileStoreConfig = {
|
|
7
|
+
/** URL for uploading txs to file storage (s3://, gs://, file://) */
|
|
8
|
+
txFileStoreUrl?: string;
|
|
9
|
+
/** URL for downloading txs from file storage */
|
|
10
|
+
txFileStoreDownloadUrl?: string;
|
|
11
|
+
/** Max concurrent uploads */
|
|
12
|
+
txFileStoreUploadConcurrency: number;
|
|
13
|
+
/** Max queue size to prevent unbounded memory growth */
|
|
14
|
+
txFileStoreMaxQueueSize: number;
|
|
15
|
+
/** Enable tx file store upload */
|
|
16
|
+
txFileStoreEnabled: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const txFileStoreConfigMappings: ConfigMappingsType<TxFileStoreConfig> = {
|
|
20
|
+
txFileStoreUrl: {
|
|
21
|
+
env: 'TX_FILE_STORE_URL',
|
|
22
|
+
description: 'URL for uploading txs to file storage (s3://, gs://, file://)',
|
|
23
|
+
},
|
|
24
|
+
txFileStoreDownloadUrl: {
|
|
25
|
+
env: 'TX_FILE_STORE_DOWNLOAD_URL',
|
|
26
|
+
description: 'URL for downloading txs from file storage',
|
|
27
|
+
},
|
|
28
|
+
txFileStoreUploadConcurrency: {
|
|
29
|
+
env: 'TX_FILE_STORE_UPLOAD_CONCURRENCY',
|
|
30
|
+
description: 'Maximum number of concurrent tx uploads',
|
|
31
|
+
...numberConfigHelper(10),
|
|
32
|
+
},
|
|
33
|
+
txFileStoreMaxQueueSize: {
|
|
34
|
+
env: 'TX_FILE_STORE_MAX_QUEUE_SIZE',
|
|
35
|
+
description: 'Maximum queue size for pending uploads (oldest dropped when exceeded)',
|
|
36
|
+
...numberConfigHelper(1000),
|
|
37
|
+
},
|
|
38
|
+
txFileStoreEnabled: {
|
|
39
|
+
env: 'TX_FILE_STORE_ENABLED',
|
|
40
|
+
description: 'Enable uploading transactions to file storage',
|
|
41
|
+
...booleanConfigHelper(false),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Gauge, type Histogram, Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
|
|
2
|
+
|
|
3
|
+
/** Instrumentation for the TxFileStore service. */
|
|
4
|
+
export class TxFileStoreInstrumentation {
|
|
5
|
+
private uploadsSuccess: UpDownCounter;
|
|
6
|
+
private uploadsFailed: UpDownCounter;
|
|
7
|
+
private uploadsSkipped: UpDownCounter;
|
|
8
|
+
private uploadDuration: Histogram;
|
|
9
|
+
private queueSize: Gauge;
|
|
10
|
+
|
|
11
|
+
constructor(client: TelemetryClient, name: string) {
|
|
12
|
+
const meter = client.getMeter(name);
|
|
13
|
+
this.uploadsSuccess = meter.createUpDownCounter(Metrics.TX_FILE_STORE_UPLOADS_SUCCESS);
|
|
14
|
+
this.uploadsFailed = meter.createUpDownCounter(Metrics.TX_FILE_STORE_UPLOADS_FAILED);
|
|
15
|
+
this.uploadsSkipped = meter.createUpDownCounter(Metrics.TX_FILE_STORE_UPLOADS_SKIPPED);
|
|
16
|
+
this.uploadDuration = meter.createHistogram(Metrics.TX_FILE_STORE_UPLOAD_DURATION);
|
|
17
|
+
this.queueSize = meter.createGauge(Metrics.TX_FILE_STORE_QUEUE_SIZE);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
recordUploadSuccess(durationMs: number) {
|
|
21
|
+
this.uploadsSuccess.add(1);
|
|
22
|
+
this.uploadDuration.record(durationMs);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
recordUploadFailed() {
|
|
26
|
+
this.uploadsFailed.add(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
recordUploadSkipped() {
|
|
30
|
+
this.uploadsSkipped.add(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
recordQueueSize(size: number) {
|
|
34
|
+
this.queueSize.record(size);
|
|
35
|
+
}
|
|
36
|
+
}
|