@aztec/p2p 0.0.1-commit.9b94fc1 → 0.0.1-commit.c7c42ec
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 +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +2 -3
- package/dest/client/p2p_client.d.ts +7 -7
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +30 -28
- package/dest/config.d.ts +4 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +8 -11
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +2 -2
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts +3 -3
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +1 -1
- package/dest/mem_pools/instrumentation.d.ts +7 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +29 -2
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +30 -25
- 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 +262 -324
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +56 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +5 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +76 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -6
- 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 +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 +30 -24
- package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/services/encoding.js +1 -1
- package/dest/services/libp2p/libp2p_service.d.ts +4 -4
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +14 -19
- package/dest/services/peer-manager/metrics.d.ts +6 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +17 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +4 -2
- package/dest/services/reqresp/interface.d.ts +2 -2
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +1 -1
- package/dest/services/reqresp/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +2 -2
- 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 +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +5 -4
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -3
- package/dest/services/reqresp/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -5
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +11 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +6 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +11 -2
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +14 -1
- package/dest/test-helpers/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +1 -0
- package/package.json +16 -16
- package/src/client/factory.ts +5 -10
- package/src/client/p2p_client.ts +52 -55
- package/src/config.ts +10 -16
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +2 -2
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +1 -1
- package/src/mem_pools/attestation_pool/mocks.ts +2 -2
- package/src/mem_pools/instrumentation.ts +33 -0
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +255 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +314 -373
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +91 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
- package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +1 -1
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +1 -1
- package/src/msg_validators/tx_validator/factory.ts +3 -2
- package/src/msg_validators/tx_validator/metadata_validator.ts +1 -1
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +2 -1
- package/src/services/encoding.ts +1 -1
- package/src/services/libp2p/libp2p_service.ts +23 -28
- package/src/services/peer-manager/metrics.ts +22 -0
- package/src/services/peer-manager/peer_manager.ts +4 -2
- package/src/services/reqresp/interface.ts +1 -1
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +9 -8
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/tx_collection/config.ts +1 -1
- package/src/services/tx_collection/fast_tx_collection.ts +3 -2
- package/src/services/tx_collection/slow_tx_collection.ts +5 -5
- package/src/services/tx_collection/tx_collection.ts +10 -9
- package/src/services/tx_provider.ts +21 -5
- package/src/services/tx_provider_instrumentation.ts +19 -2
- package/src/test-helpers/mock-pubsub.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +2 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { unfreeze } from '@aztec/foundation/types';
|
|
2
3
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
3
4
|
import { mockTx } from '@aztec/stdlib/testing';
|
|
@@ -13,7 +14,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
13
14
|
let pool: TxPool;
|
|
14
15
|
|
|
15
16
|
const minedBlockHeader = BlockHeader.empty({
|
|
16
|
-
globalVariables: GlobalVariables.empty({ blockNumber: 1, timestamp: 0n }),
|
|
17
|
+
globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(1), timestamp: 0n }),
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
beforeEach(() => {
|
|
@@ -25,7 +26,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
it('adds txs to the pool as pending', async () => {
|
|
28
|
-
const tx1 = await mockTx();
|
|
29
|
+
const tx1 = await mockTx(1);
|
|
29
30
|
|
|
30
31
|
await pool.addTxs([tx1]);
|
|
31
32
|
const poolTx = await pool.getTxByHash(tx1.getTxHash());
|
|
@@ -36,9 +37,9 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
it('emits txs-added event with new txs', async () => {
|
|
39
|
-
const tx1 = await mockTx(); // existing and pending
|
|
40
|
-
const tx2 = await mockTx(); // mined but not known
|
|
41
|
-
const tx3 = await mockTx(); // brand new
|
|
40
|
+
const tx1 = await mockTx(1); // existing and pending
|
|
41
|
+
const tx2 = await mockTx(2); // mined but not known
|
|
42
|
+
const tx3 = await mockTx(3); // brand new
|
|
42
43
|
|
|
43
44
|
await pool.addTxs([tx1]);
|
|
44
45
|
await pool.markAsMined([tx2.getTxHash()], minedBlockHeader);
|
|
@@ -51,10 +52,11 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
51
52
|
await pool.addTxs([tx1, tx2, tx3]);
|
|
52
53
|
expect(txsFromEvent).toBeDefined();
|
|
53
54
|
expect(txsFromEvent).toHaveLength(2);
|
|
54
|
-
|
|
55
|
+
const eventHashes = txsFromEvent!.map(tx => tx.getTxHash());
|
|
56
|
+
expect(eventHashes).toEqual(expect.arrayContaining([tx2.getTxHash(), tx3.getTxHash()]));
|
|
55
57
|
});
|
|
56
58
|
|
|
57
|
-
it('
|
|
59
|
+
it('removes txs from the pool', async () => {
|
|
58
60
|
const pendingTx = await mockTx(1);
|
|
59
61
|
const minedTx = await mockTx(2);
|
|
60
62
|
|
|
@@ -82,7 +84,8 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
82
84
|
await pool.addTxs([tx1, tx2]);
|
|
83
85
|
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
84
86
|
|
|
85
|
-
await
|
|
87
|
+
const retrievedTx = await pool.getTxByHash(tx1.getTxHash());
|
|
88
|
+
expect(retrievedTx?.getTxHash()).toEqual(tx1.getTxHash());
|
|
86
89
|
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('mined');
|
|
87
90
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([[tx1.getTxHash(), 1]]);
|
|
88
91
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx2.getTxHash()]);
|
|
@@ -96,7 +99,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
96
99
|
await pool.addTxs([tx1, tx2]);
|
|
97
100
|
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
98
101
|
|
|
99
|
-
await pool.markMinedAsPending([tx1.getTxHash()]);
|
|
102
|
+
await pool.markMinedAsPending([tx1.getTxHash()], BlockNumber(1));
|
|
100
103
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
101
104
|
const pending = await pool.getPendingTxHashes();
|
|
102
105
|
expect(pending).toHaveLength(2);
|
|
@@ -120,7 +123,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
120
123
|
);
|
|
121
124
|
|
|
122
125
|
// reorg: both txs should now become available again
|
|
123
|
-
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee]);
|
|
126
|
+
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], BlockNumber(1));
|
|
124
127
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
125
128
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]); // tx2 is not in the pool
|
|
126
129
|
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
@@ -135,7 +138,8 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
135
138
|
|
|
136
139
|
const poolTxs = await pool.getAllTxs();
|
|
137
140
|
expect(poolTxs).toHaveLength(3);
|
|
138
|
-
|
|
141
|
+
const poolHashes = poolTxs.map(tx => tx.getTxHash());
|
|
142
|
+
expect(poolHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash(), tx3.getTxHash()]));
|
|
139
143
|
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
140
144
|
});
|
|
141
145
|
|
|
@@ -162,17 +166,19 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
162
166
|
|
|
163
167
|
const requestedTxs = await pool.getTxsByHash([tx1.getTxHash(), tx3.getTxHash()]);
|
|
164
168
|
expect(requestedTxs).toHaveLength(2);
|
|
165
|
-
|
|
169
|
+
const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
|
|
170
|
+
expect(requestedHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx3.getTxHash()]));
|
|
166
171
|
});
|
|
167
172
|
|
|
168
173
|
it('returns a large number of transactions by their hash', async () => {
|
|
169
|
-
const numTxs =
|
|
174
|
+
const numTxs = 1_000;
|
|
170
175
|
const txs = await Promise.all(Array.from({ length: numTxs }, (_, i) => mockTx(i)));
|
|
171
176
|
const hashes = txs.map(tx => tx.getTxHash());
|
|
172
177
|
await pool.addTxs(txs);
|
|
173
178
|
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
174
179
|
expect(requestedTxs).toHaveLength(numTxs);
|
|
175
|
-
|
|
180
|
+
const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
|
|
181
|
+
expect(requestedHashes).toEqual(expect.arrayContaining(hashes));
|
|
176
182
|
});
|
|
177
183
|
|
|
178
184
|
it('returns whether or not txs exist', async () => {
|
|
@@ -261,7 +267,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
261
267
|
await pool.deleteTxs([txs[0].getTxHash(), txs[1].getTxHash()]);
|
|
262
268
|
|
|
263
269
|
// Clean up deleted mined txs from block 1 and earlier
|
|
264
|
-
const deletedCount = await pool.cleanupDeletedMinedTxs(1);
|
|
270
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
265
271
|
|
|
266
272
|
// Verify old transactions are permanently deleted
|
|
267
273
|
expect(deletedCount).toBe(2);
|
|
@@ -276,7 +282,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
276
282
|
|
|
277
283
|
// Mark as mined in block 2
|
|
278
284
|
const laterBlockHeader = BlockHeader.empty({
|
|
279
|
-
globalVariables: GlobalVariables.empty({ blockNumber: 2, timestamp: 0n }),
|
|
285
|
+
globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(2), timestamp: 0n }),
|
|
280
286
|
});
|
|
281
287
|
await pool.markAsMined([txs[0].getTxHash()], laterBlockHeader);
|
|
282
288
|
|
|
@@ -284,7 +290,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
284
290
|
await pool.deleteTxs([txs[0].getTxHash()]);
|
|
285
291
|
|
|
286
292
|
// Try to clean up with block 1 (before the mined block)
|
|
287
|
-
const deletedCount = await pool.cleanupDeletedMinedTxs(1);
|
|
293
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
288
294
|
|
|
289
295
|
// Verify no transactions were cleaned up
|
|
290
296
|
expect(deletedCount).toBe(0);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { NoCommitteeError } from '@aztec/ethereum';
|
|
2
|
+
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { type BlockAttestation, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { NoCommitteeError } from '@aztec/ethereum';
|
|
2
|
+
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { type BlockProposal, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { ArchiveSource } from '@aztec/p2p';
|
|
3
3
|
import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
4
4
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { type AnyTx, TX_ERROR_BLOCK_HEADER, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
3
4
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
5
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
@@ -33,7 +34,7 @@ export interface MessageValidator {
|
|
|
33
34
|
|
|
34
35
|
export function createTxMessageValidators(
|
|
35
36
|
timestamp: UInt64,
|
|
36
|
-
blockNumber:
|
|
37
|
+
blockNumber: BlockNumber,
|
|
37
38
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
38
39
|
gasFees: GasFees,
|
|
39
40
|
l1ChainId: number,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { HashedValues, type Tx } from '@aztec/stdlib/tx';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import {
|
|
3
4
|
type AnyTx,
|
|
@@ -17,7 +18,7 @@ export class TimestampTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
17
18
|
// being built.
|
|
18
19
|
timestamp: UInt64;
|
|
19
20
|
// Block number in which the tx is considered to be included.
|
|
20
|
-
blockNumber:
|
|
21
|
+
blockNumber: BlockNumber;
|
|
21
22
|
},
|
|
22
23
|
) {}
|
|
23
24
|
|
package/src/services/encoding.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Taken from lodestar: https://github.com/ChainSafe/lodestar
|
|
2
|
-
import { sha256 } from '@aztec/foundation/crypto';
|
|
2
|
+
import { sha256 } from '@aztec/foundation/crypto/sha256';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { TopicType, getTopicFromString } from '@aztec/stdlib/p2p';
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { randomInt } from '@aztec/foundation/crypto';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
7
|
import { Timer } from '@aztec/foundation/timer';
|
|
@@ -131,7 +131,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
131
131
|
private protocolVersion = '';
|
|
132
132
|
private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
|
|
133
133
|
|
|
134
|
-
private feesCache: { blockNumber:
|
|
134
|
+
private feesCache: { blockNumber: BlockNumber; gasFees: GasFees } | undefined;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* Callback for when a block is received from a peer.
|
|
@@ -153,7 +153,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
153
153
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
154
154
|
private reqresp: ReqRespInterface,
|
|
155
155
|
private peerManager: PeerManagerInterface,
|
|
156
|
-
protected mempools: MemPools
|
|
156
|
+
protected mempools: MemPools,
|
|
157
157
|
private archiver: L2BlockSource & ContractDataSource,
|
|
158
158
|
private epochCache: EpochCacheInterface,
|
|
159
159
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
@@ -185,7 +185,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
185
185
|
|
|
186
186
|
// Use FishermanAttestationValidator in fisherman mode to validate attestation payloads against proposals
|
|
187
187
|
this.attestationValidator = config.fishermanMode
|
|
188
|
-
? new FishermanAttestationValidator(epochCache, mempools.attestationPool
|
|
188
|
+
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
189
189
|
: new AttestationValidator(epochCache);
|
|
190
190
|
this.blockProposalValidator = new BlockProposalValidator(epochCache, { txsPermitted: !config.disableTransactions });
|
|
191
191
|
|
|
@@ -215,7 +215,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
215
215
|
config: P2PConfig,
|
|
216
216
|
peerId: PeerId,
|
|
217
217
|
deps: {
|
|
218
|
-
mempools: MemPools
|
|
218
|
+
mempools: MemPools;
|
|
219
219
|
l2BlockSource: L2BlockSource & ContractDataSource;
|
|
220
220
|
epochCache: EpochCacheInterface;
|
|
221
221
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
@@ -486,8 +486,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
486
486
|
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
487
487
|
};
|
|
488
488
|
|
|
489
|
-
|
|
490
|
-
if (this.mempools.attestationPool && !this.config.disableTransactions) {
|
|
489
|
+
if (!this.config.disableTransactions) {
|
|
491
490
|
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
|
|
492
491
|
requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
|
|
493
492
|
}
|
|
@@ -809,7 +808,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
809
808
|
private async processAttestationFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
810
809
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockAttestation>> = async () => {
|
|
811
810
|
const attestation = BlockAttestation.fromBuffer(payloadData);
|
|
812
|
-
const pool = this.mempools.attestationPool
|
|
811
|
+
const pool = this.mempools.attestationPool;
|
|
813
812
|
const isValid = await this.validateAttestation(source, attestation);
|
|
814
813
|
const exists = isValid && (await pool.hasAttestation(attestation));
|
|
815
814
|
|
|
@@ -866,7 +865,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
866
865
|
},
|
|
867
866
|
);
|
|
868
867
|
|
|
869
|
-
await this.mempools.attestationPool
|
|
868
|
+
await this.mempools.attestationPool.addAttestations([attestation]);
|
|
870
869
|
}
|
|
871
870
|
|
|
872
871
|
private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
@@ -875,10 +874,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
875
874
|
const isValid = await this.validateBlockProposal(source, block);
|
|
876
875
|
const pool = this.mempools.attestationPool;
|
|
877
876
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
const exists = isValid && (await pool?.hasBlockProposal(block));
|
|
881
|
-
const canAdd = isValid && (await pool?.canAddProposal(block));
|
|
877
|
+
const exists = isValid && (await pool.hasBlockProposal(block));
|
|
878
|
+
const canAdd = isValid && (await pool.canAddProposal(block));
|
|
882
879
|
|
|
883
880
|
this.logger.trace(`Validate propagated block proposal`, {
|
|
884
881
|
isValid,
|
|
@@ -934,14 +931,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
934
931
|
archive: block.archive.toString(),
|
|
935
932
|
source: sender.toString(),
|
|
936
933
|
});
|
|
937
|
-
const attestationsForPreviousSlot = await this.mempools.attestationPool
|
|
938
|
-
|
|
939
|
-
this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
|
|
940
|
-
}
|
|
934
|
+
const attestationsForPreviousSlot = await this.mempools.attestationPool.getAttestationsForSlot(previousSlot);
|
|
935
|
+
this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
|
|
941
936
|
|
|
942
937
|
// Attempt to add proposal, then mark the txs in this proposal as non-evictable
|
|
943
938
|
try {
|
|
944
|
-
await this.mempools.attestationPool
|
|
939
|
+
await this.mempools.attestationPool.addBlockProposal(block);
|
|
945
940
|
} catch (err: unknown) {
|
|
946
941
|
// Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
|
|
947
942
|
if (err instanceof ProposalSlotCapExceededError) {
|
|
@@ -1047,7 +1042,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1047
1042
|
}
|
|
1048
1043
|
|
|
1049
1044
|
// Given proposal (should have locally), ensure returned txs are valid subset and match request indices
|
|
1050
|
-
const proposal = await this.mempools.attestationPool
|
|
1045
|
+
const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
|
|
1051
1046
|
if (proposal) {
|
|
1052
1047
|
// Build intersected indices
|
|
1053
1048
|
const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
|
|
@@ -1148,7 +1143,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1148
1143
|
return false;
|
|
1149
1144
|
}
|
|
1150
1145
|
|
|
1151
|
-
const local = await this.archiver.getBlock(reqNum);
|
|
1146
|
+
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1152
1147
|
if (!local) {
|
|
1153
1148
|
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1154
1149
|
// TODO: Consider extending this validator to accept an expected hash or
|
|
@@ -1223,7 +1218,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1223
1218
|
|
|
1224
1219
|
// Double spend validator has a special case handler
|
|
1225
1220
|
if (name === 'doubleSpendValidator') {
|
|
1226
|
-
const txBlockNumber = currentBlockNumber + 1; // tx is expected to be in the next block
|
|
1221
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
|
|
1227
1222
|
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1228
1223
|
}
|
|
1229
1224
|
|
|
@@ -1233,7 +1228,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1233
1228
|
return true;
|
|
1234
1229
|
}
|
|
1235
1230
|
|
|
1236
|
-
private async getGasFees(blockNumber:
|
|
1231
|
+
private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
|
|
1237
1232
|
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1238
1233
|
return this.feesCache.gasFees;
|
|
1239
1234
|
}
|
|
@@ -1274,13 +1269,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1274
1269
|
* @returns The message validators.
|
|
1275
1270
|
*/
|
|
1276
1271
|
private async createMessageValidators(
|
|
1277
|
-
currentBlockNumber:
|
|
1272
|
+
currentBlockNumber: BlockNumber,
|
|
1278
1273
|
nextSlotTimestamp: UInt64,
|
|
1279
1274
|
): Promise<Record<string, MessageValidator>[]> {
|
|
1280
1275
|
const gasFees = await this.getGasFees(currentBlockNumber);
|
|
1281
1276
|
const allowedInSetup = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
1282
1277
|
|
|
1283
|
-
const blockNumberInWhichTheTxIsConsideredToBeIncluded = currentBlockNumber + 1;
|
|
1278
|
+
const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
|
|
1284
1279
|
|
|
1285
1280
|
return createTxMessageValidators(
|
|
1286
1281
|
nextSlotTimestamp,
|
|
@@ -1342,7 +1337,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1342
1337
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1343
1338
|
* @returns Severity
|
|
1344
1339
|
*/
|
|
1345
|
-
private async handleDoubleSpendFailure(tx: Tx, blockNumber:
|
|
1340
|
+
private async handleDoubleSpendFailure(tx: Tx, blockNumber: BlockNumber): Promise<PeerErrorSeverity> {
|
|
1346
1341
|
if (blockNumber <= this.config.doubleSpendSeverePeerPenaltyWindow) {
|
|
1347
1342
|
return PeerErrorSeverity.HighToleranceError;
|
|
1348
1343
|
}
|
|
@@ -1350,7 +1345,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1350
1345
|
const snapshotValidator = new DoubleSpendTxValidator({
|
|
1351
1346
|
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
1352
1347
|
const merkleTree = this.worldStateSynchronizer.getSnapshot(
|
|
1353
|
-
blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow,
|
|
1348
|
+
BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow),
|
|
1354
1349
|
);
|
|
1355
1350
|
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
1356
1351
|
return indices.map(index => index !== undefined);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Attributes,
|
|
3
3
|
type Gauge,
|
|
4
|
+
type Histogram,
|
|
4
5
|
Metrics,
|
|
5
6
|
type TelemetryClient,
|
|
6
7
|
type Tracer,
|
|
@@ -9,6 +10,8 @@ import {
|
|
|
9
10
|
getTelemetryClient,
|
|
10
11
|
} from '@aztec/telemetry-client';
|
|
11
12
|
|
|
13
|
+
import type { PeerId } from '@libp2p/interface';
|
|
14
|
+
|
|
12
15
|
import { type GoodByeReason, prettyGoodbyeReason } from '../reqresp/protocols/index.js';
|
|
13
16
|
|
|
14
17
|
export class PeerManagerMetrics {
|
|
@@ -16,6 +19,9 @@ export class PeerManagerMetrics {
|
|
|
16
19
|
private receivedGoodbyes: UpDownCounter;
|
|
17
20
|
private peerCount: Gauge;
|
|
18
21
|
private lowScoreDisconnects: UpDownCounter;
|
|
22
|
+
private peerConnectionDuration: Histogram;
|
|
23
|
+
|
|
24
|
+
private peerConnectedAt: Map<string, number> = new Map<string, number>();
|
|
19
25
|
|
|
20
26
|
public readonly tracer: Tracer;
|
|
21
27
|
|
|
@@ -46,6 +52,11 @@ export class PeerManagerMetrics {
|
|
|
46
52
|
unit: 'peers',
|
|
47
53
|
valueType: ValueType.INT,
|
|
48
54
|
});
|
|
55
|
+
this.peerConnectionDuration = meter.createHistogram(Metrics.PEER_MANAGER_PEER_CONNECTION_DURATION, {
|
|
56
|
+
description: 'Time duration between peer connection and disconnection',
|
|
57
|
+
unit: 'ms',
|
|
58
|
+
valueType: ValueType.INT,
|
|
59
|
+
});
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
public recordGoodbyeSent(reason: GoodByeReason) {
|
|
@@ -63,4 +74,15 @@ export class PeerManagerMetrics {
|
|
|
63
74
|
public recordLowScoreDisconnect(scoreState: 'Banned' | 'Disconnect') {
|
|
64
75
|
this.lowScoreDisconnects.add(1, { [Attributes.P2P_PEER_SCORE_STATE]: scoreState });
|
|
65
76
|
}
|
|
77
|
+
|
|
78
|
+
public peerConnected(id: PeerId) {
|
|
79
|
+
this.peerConnectedAt.set(id.toString(), Date.now());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public peerDisconnected(id: PeerId) {
|
|
83
|
+
const connectedAt = this.peerConnectedAt.get(id.toString());
|
|
84
|
+
if (connectedAt) {
|
|
85
|
+
this.peerConnectionDuration.record(Date.now() - connectedAt);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
66
88
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { makeEthSignDigest, tryRecoverAddress } from '@aztec/foundation/crypto';
|
|
2
|
+
import { makeEthSignDigest, tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
7
7
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -278,6 +278,7 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
278
278
|
private handleConnectedPeerEvent(e: CustomEvent<PeerId>) {
|
|
279
279
|
const peerId = e.detail;
|
|
280
280
|
this.logger.verbose(`Connected to peer ${peerId.toString()}`);
|
|
281
|
+
this.metrics.peerConnected(peerId);
|
|
281
282
|
if (this.config.p2pDisableStatusHandshake) {
|
|
282
283
|
return;
|
|
283
284
|
}
|
|
@@ -303,6 +304,7 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
303
304
|
*/
|
|
304
305
|
private handleDisconnectedPeerEvent(e: CustomEvent<PeerId>) {
|
|
305
306
|
const peerId = e.detail;
|
|
307
|
+
this.metrics.peerDisconnected(peerId);
|
|
306
308
|
this.logger.verbose(`Disconnected from peer ${peerId.toString()}`);
|
|
307
309
|
const validatorAddress = this.authenticatedPeerIdToValidatorAddress.get(peerId.toString());
|
|
308
310
|
if (validatorAddress !== undefined) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { keccak256 } from '@aztec/foundation/crypto';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
6
6
|
|
|
7
7
|
import { StatusMessage } from './status.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
3
4
|
|
|
4
5
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -27,7 +28,7 @@ export function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubPro
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
try {
|
|
30
|
-
const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
|
|
31
|
+
const foundBlock = await l2BlockSource.getBlock(BlockNumber(Number(blockNumber)));
|
|
31
32
|
return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
|
|
32
33
|
} catch (err: any) {
|
|
33
34
|
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
@@ -15,9 +16,9 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
15
16
|
export class StatusMessage {
|
|
16
17
|
constructor(
|
|
17
18
|
readonly compressedComponentsVersion: string,
|
|
18
|
-
readonly latestBlockNumber:
|
|
19
|
+
readonly latestBlockNumber: BlockNumber,
|
|
19
20
|
readonly latestBlockHash: string,
|
|
20
|
-
readonly finalizedBlockNumber:
|
|
21
|
+
readonly finalizedBlockNumber: BlockNumber,
|
|
21
22
|
//TODO: add finalizedBlockHash
|
|
22
23
|
//readonly finalizedBlockHash: string,
|
|
23
24
|
) {}
|
|
@@ -31,9 +32,9 @@ export class StatusMessage {
|
|
|
31
32
|
const reader = BufferReader.asReader(buffer);
|
|
32
33
|
return new StatusMessage(
|
|
33
34
|
reader.readString(), // compressedComponentsVersion
|
|
34
|
-
reader.readNumber(), // latestBlockNumber
|
|
35
|
+
BlockNumber(reader.readNumber()), // latestBlockNumber
|
|
35
36
|
reader.readString(), // latestBlockHash
|
|
36
|
-
reader.readNumber(), // finalizedBlockNumber
|
|
37
|
+
BlockNumber(reader.readNumber()), // finalizedBlockNumber
|
|
37
38
|
//TODO: add finalizedBlockHash
|
|
38
39
|
//reader.readString(), // finalizedBlockHash
|
|
39
40
|
);
|
|
@@ -63,9 +64,9 @@ export class StatusMessage {
|
|
|
63
64
|
static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage {
|
|
64
65
|
return new StatusMessage(
|
|
65
66
|
version,
|
|
66
|
-
syncStatus.latestBlockNumber,
|
|
67
|
+
BlockNumber(syncStatus.latestBlockNumber),
|
|
67
68
|
syncStatus.latestBlockHash,
|
|
68
|
-
syncStatus.finalizedBlockNumber,
|
|
69
|
+
BlockNumber(syncStatus.finalizedBlockNumber),
|
|
69
70
|
//TODO: add finalizedBlockHash
|
|
70
71
|
);
|
|
71
72
|
}
|
|
@@ -73,9 +74,9 @@ export class StatusMessage {
|
|
|
73
74
|
static random(): StatusMessage {
|
|
74
75
|
return new StatusMessage(
|
|
75
76
|
'1.0.0',
|
|
76
|
-
Math.floor(Math.random() * 100),
|
|
77
|
+
BlockNumber(Math.floor(Math.random() * 100)),
|
|
77
78
|
Buffer32.random().toString(),
|
|
78
|
-
Math.floor(Math.random() * 100),
|
|
79
|
+
BlockNumber(Math.floor(Math.random() * 100)),
|
|
79
80
|
//TODO: add finalizedBlockHash
|
|
80
81
|
);
|
|
81
82
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { chunk } from '@aztec/foundation/collection';
|
|
2
|
-
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
3
2
|
import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
4
3
|
|
|
5
4
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -16,7 +15,7 @@ import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
|
16
15
|
* @param mempools - the mempools
|
|
17
16
|
* @returns the Tx request handler
|
|
18
17
|
*/
|
|
19
|
-
export function reqRespTxHandler
|
|
18
|
+
export function reqRespTxHandler(mempools: MemPools): ReqRespSubProtocolHandler {
|
|
20
19
|
/**
|
|
21
20
|
* Handler for tx requests
|
|
22
21
|
* @param msg - the tx request message
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
-
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/
|
|
2
|
+
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/api-limit';
|
|
3
3
|
|
|
4
4
|
export type TxCollectionConfig = {
|
|
5
5
|
/** How long to wait before starting reqresp for fast collection */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { times } from '@aztec/foundation/collection';
|
|
2
3
|
import { AbortError, TimeoutError } from '@aztec/foundation/error';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
@@ -316,7 +317,7 @@ export class FastTxCollection {
|
|
|
316
317
|
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
317
318
|
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
318
319
|
*/
|
|
319
|
-
public stopCollectingForBlocksUpTo(blockNumber:
|
|
320
|
+
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
320
321
|
for (const request of this.requests) {
|
|
321
322
|
if (request.blockInfo.blockNumber <= blockNumber) {
|
|
322
323
|
request.promise.reject(new AbortError(`Stopped collecting txs up to block ${blockNumber}`));
|
|
@@ -329,7 +330,7 @@ export class FastTxCollection {
|
|
|
329
330
|
* Stop collecting all txs for blocks greater than the block number specified.
|
|
330
331
|
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
331
332
|
*/
|
|
332
|
-
public stopCollectingForBlocksAfter(blockNumber:
|
|
333
|
+
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
333
334
|
for (const request of this.requests) {
|
|
334
335
|
if (request.blockInfo.blockNumber > blockNumber) {
|
|
335
336
|
request.promise.reject(new AbortError(`Stopped collecting txs after block ${blockNumber}`));
|