@aztec/p2p 0.70.0 → 0.71.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/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +6 -5
- package/dest/client/p2p_client.d.ts +16 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +17 -7
- package/dest/config.d.ts +3 -0
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +6 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +3 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +3 -2
- package/dest/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.d.ts +1 -1
- package/dest/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.d.ts.map +1 -1
- package/dest/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.js +3 -2
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +20 -5
- 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 +72 -9
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +2 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +6 -2
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +6 -0
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mocks/index.d.ts.map +1 -1
- package/dest/mocks/index.js +4 -4
- package/dest/services/discv5/discV5_service.d.ts +1 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +3 -3
- package/package.json +7 -7
- package/src/client/factory.ts +5 -13
- package/src/client/p2p_client.ts +27 -6
- package/src/config.ts +9 -0
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +2 -2
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +2 -2
- package/src/mem_pools/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts +2 -2
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +93 -7
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +6 -2
- package/src/mem_pools/tx_pool/tx_pool.ts +7 -0
- package/src/mocks/index.ts +3 -4
- package/src/services/discv5/discV5_service.ts +2 -2
|
@@ -2,7 +2,7 @@ import { BlockAttestation } from '@aztec/circuit-types';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { type AztecKVStore, type AztecMapWithSize, type AztecMultiMap } from '@aztec/kv-store';
|
|
5
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
5
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
6
6
|
|
|
7
7
|
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
8
8
|
import { type AttestationPool } from './attestation_pool.js';
|
|
@@ -15,7 +15,7 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
17
|
private store: AztecKVStore,
|
|
18
|
-
telemetry: TelemetryClient,
|
|
18
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
19
19
|
private log = createLogger('aztec:attestation_pool'),
|
|
20
20
|
) {
|
|
21
21
|
this.attestations = store.openMultiMap('attestations');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type BlockAttestation } from '@aztec/circuit-types';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
3
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
5
|
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
6
6
|
import { type AttestationPool } from './attestation_pool.js';
|
|
@@ -10,7 +10,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
10
10
|
|
|
11
11
|
private attestations: Map</*slot=*/ bigint, Map</*proposalId*/ string, Map</*address=*/ string, BlockAttestation>>>;
|
|
12
12
|
|
|
13
|
-
constructor(telemetry: TelemetryClient, private log = createLogger('p2p:attestation_pool')) {
|
|
13
|
+
constructor(telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('p2p:attestation_pool')) {
|
|
14
14
|
this.attestations = new Map();
|
|
15
15
|
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL);
|
|
16
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type EpochProofQuote } from '@aztec/circuit-types';
|
|
2
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
2
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
3
3
|
|
|
4
4
|
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
5
5
|
import { type EpochProofQuotePool } from './epoch_proof_quote_pool.js';
|
|
@@ -8,7 +8,7 @@ export class MemoryEpochProofQuotePool implements EpochProofQuotePool {
|
|
|
8
8
|
private quotes: Map<bigint, EpochProofQuote[]>;
|
|
9
9
|
private metrics: PoolInstrumentation<EpochProofQuote>;
|
|
10
10
|
|
|
11
|
-
constructor(telemetry: TelemetryClient) {
|
|
11
|
+
constructor(telemetry: TelemetryClient = getTelemetryClient()) {
|
|
12
12
|
this.quotes = new Map();
|
|
13
13
|
this.metrics = new PoolInstrumentation(telemetry, PoolName.EPOCH_PROOF_QUOTE_POOL);
|
|
14
14
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Tx, TxHash } from '@aztec/circuit-types';
|
|
2
2
|
import { type TxAddedToPoolStats } from '@aztec/circuit-types/stats';
|
|
3
|
+
import { ClientIvcProof } from '@aztec/circuits.js';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { type AztecKVStore, type AztecMap, type AztecMultiMap } from '@aztec/kv-store';
|
|
5
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
6
7
|
|
|
7
8
|
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
8
9
|
import { getPendingTxPriority } from './priority.js';
|
|
9
10
|
import { type TxPool } from './tx_pool.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
* KV implementation of the Transaction Pool.
|
|
13
14
|
*/
|
|
14
15
|
export class AztecKVTxPool implements TxPool {
|
|
15
16
|
#store: AztecKVStore;
|
|
@@ -23,21 +24,47 @@ export class AztecKVTxPool implements TxPool {
|
|
|
23
24
|
/** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */
|
|
24
25
|
#pendingTxPriorityToHash: AztecMultiMap<string, string>;
|
|
25
26
|
|
|
27
|
+
/** KV store for archived txs. */
|
|
28
|
+
#archive: AztecKVStore;
|
|
29
|
+
|
|
30
|
+
/** Archived txs map for future lookup. */
|
|
31
|
+
#archivedTxs: AztecMap<string, Buffer>;
|
|
32
|
+
|
|
33
|
+
/** Indexes of the archived txs by insertion order. */
|
|
34
|
+
#archivedTxIndices: AztecMap<number, string>;
|
|
35
|
+
|
|
36
|
+
/** Number of txs to archive. */
|
|
37
|
+
#archivedTxLimit: number;
|
|
38
|
+
|
|
26
39
|
#log: Logger;
|
|
27
40
|
|
|
28
41
|
#metrics: PoolInstrumentation<Tx>;
|
|
29
42
|
|
|
30
43
|
/**
|
|
31
|
-
* Class constructor for
|
|
32
|
-
* @param store - A KV store.
|
|
44
|
+
* Class constructor for KV TxPool. Initiates our transaction pool as an AztecMap.
|
|
45
|
+
* @param store - A KV store for live txs in the pool.
|
|
46
|
+
* @param archive - A KV store for archived txs.
|
|
47
|
+
* @param telemetry - A telemetry client.
|
|
48
|
+
* @param archivedTxLimit - The number of txs to archive.
|
|
33
49
|
* @param log - A logger.
|
|
34
50
|
*/
|
|
35
|
-
constructor(
|
|
51
|
+
constructor(
|
|
52
|
+
store: AztecKVStore,
|
|
53
|
+
archive: AztecKVStore,
|
|
54
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
55
|
+
archivedTxLimit: number = 0,
|
|
56
|
+
log = createLogger('p2p:tx_pool'),
|
|
57
|
+
) {
|
|
36
58
|
this.#txs = store.openMap('txs');
|
|
37
59
|
this.#minedTxHashToBlock = store.openMap('txHashToBlockMined');
|
|
38
60
|
this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash');
|
|
39
61
|
|
|
62
|
+
this.#archivedTxs = archive.openMap('archivedTxs');
|
|
63
|
+
this.#archivedTxIndices = archive.openMap('archivedTxIndices');
|
|
64
|
+
this.#archivedTxLimit = archivedTxLimit;
|
|
65
|
+
|
|
40
66
|
this.#store = store;
|
|
67
|
+
this.#archive = archive;
|
|
41
68
|
this.#log = log;
|
|
42
69
|
this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, () => store.estimateSize());
|
|
43
70
|
}
|
|
@@ -125,6 +152,21 @@ export class AztecKVTxPool implements TxPool {
|
|
|
125
152
|
return undefined;
|
|
126
153
|
}
|
|
127
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Checks if an archived tx exists and returns it.
|
|
157
|
+
* @param txHash - The tx hash.
|
|
158
|
+
* @returns The transaction metadata, if found, 'undefined' otherwise.
|
|
159
|
+
*/
|
|
160
|
+
public getArchivedTxByHash(txHash: TxHash): Tx | undefined {
|
|
161
|
+
const buffer = this.#archivedTxs.get(txHash.toString());
|
|
162
|
+
if (buffer) {
|
|
163
|
+
const tx = Tx.fromBuffer(buffer);
|
|
164
|
+
tx.setTxHash(txHash);
|
|
165
|
+
return tx;
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
128
170
|
/**
|
|
129
171
|
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
130
172
|
* @param txs - An array of txs to be added to the pool.
|
|
@@ -158,13 +200,14 @@ export class AztecKVTxPool implements TxPool {
|
|
|
158
200
|
/**
|
|
159
201
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
160
202
|
* @param txHashes - An array of tx hashes to be removed from the tx pool.
|
|
161
|
-
* @returns
|
|
203
|
+
* @returns Empty promise.
|
|
162
204
|
*/
|
|
163
205
|
public deleteTxs(txHashes: TxHash[]): Promise<void> {
|
|
164
206
|
let pendingDeleted = 0;
|
|
165
207
|
let minedDeleted = 0;
|
|
166
208
|
|
|
167
|
-
|
|
209
|
+
const deletedTxs: Tx[] = [];
|
|
210
|
+
const poolDbTx = this.#store.transaction(() => {
|
|
168
211
|
for (const hash of txHashes) {
|
|
169
212
|
const key = hash.toString();
|
|
170
213
|
const tx = this.getTxByHash(hash);
|
|
@@ -180,6 +223,10 @@ export class AztecKVTxPool implements TxPool {
|
|
|
180
223
|
pendingDeleted++;
|
|
181
224
|
}
|
|
182
225
|
|
|
226
|
+
if (this.#archivedTxLimit) {
|
|
227
|
+
deletedTxs.push(tx);
|
|
228
|
+
}
|
|
229
|
+
|
|
183
230
|
void this.#txs.delete(key);
|
|
184
231
|
void this.#minedTxHashToBlock.delete(key);
|
|
185
232
|
}
|
|
@@ -188,6 +235,8 @@ export class AztecKVTxPool implements TxPool {
|
|
|
188
235
|
this.#metrics.recordRemovedObjects(pendingDeleted, 'pending');
|
|
189
236
|
this.#metrics.recordRemovedObjects(minedDeleted, 'mined');
|
|
190
237
|
});
|
|
238
|
+
|
|
239
|
+
return this.#archivedTxLimit ? poolDbTx.then(() => this.archiveTxs(deletedTxs)) : poolDbTx;
|
|
191
240
|
}
|
|
192
241
|
|
|
193
242
|
/**
|
|
@@ -209,4 +258,41 @@ export class AztecKVTxPool implements TxPool {
|
|
|
209
258
|
public getAllTxHashes(): TxHash[] {
|
|
210
259
|
return Array.from(this.#txs.keys()).map(x => TxHash.fromString(x));
|
|
211
260
|
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
|
|
264
|
+
* @param txs - The list of transactions to archive.
|
|
265
|
+
* @returns Empty promise.
|
|
266
|
+
*/
|
|
267
|
+
private archiveTxs(txs: Tx[]): Promise<void> {
|
|
268
|
+
return this.#archive.transaction(() => {
|
|
269
|
+
// calcualte the head and tail indices of the archived txs by insertion order.
|
|
270
|
+
let headIdx = (this.#archivedTxIndices.entries({ limit: 1, reverse: true }).next().value?.[0] ?? -1) + 1;
|
|
271
|
+
let tailIdx = this.#archivedTxIndices.entries({ limit: 1 }).next().value?.[0] ?? 0;
|
|
272
|
+
|
|
273
|
+
for (const tx of txs) {
|
|
274
|
+
while (headIdx - tailIdx >= this.#archivedTxLimit) {
|
|
275
|
+
const txHash = this.#archivedTxIndices.get(tailIdx);
|
|
276
|
+
if (txHash) {
|
|
277
|
+
void this.#archivedTxs.delete(txHash);
|
|
278
|
+
void this.#archivedTxIndices.delete(tailIdx);
|
|
279
|
+
}
|
|
280
|
+
tailIdx++;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const archivedTx: Tx = new Tx(
|
|
284
|
+
tx.data,
|
|
285
|
+
ClientIvcProof.empty(),
|
|
286
|
+
tx.unencryptedLogs,
|
|
287
|
+
tx.contractClassLogs,
|
|
288
|
+
tx.enqueuedPublicFunctionCalls,
|
|
289
|
+
tx.publicTeardownFunctionCall,
|
|
290
|
+
);
|
|
291
|
+
const txHash = tx.getTxHash().toString();
|
|
292
|
+
void this.#archivedTxs.set(txHash, archivedTx.toBuffer());
|
|
293
|
+
void this.#archivedTxIndices.set(headIdx, txHash);
|
|
294
|
+
headIdx++;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
212
298
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tx, TxHash } from '@aztec/circuit-types';
|
|
2
2
|
import { type TxAddedToPoolStats } from '@aztec/circuit-types/stats';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
5
5
|
|
|
6
6
|
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
7
7
|
import { getPendingTxPriority } from './priority.js';
|
|
@@ -24,7 +24,7 @@ export class InMemoryTxPool implements TxPool {
|
|
|
24
24
|
* Class constructor for in-memory TxPool. Initiates our transaction pool as a JS Map.
|
|
25
25
|
* @param log - A logger.
|
|
26
26
|
*/
|
|
27
|
-
constructor(telemetry: TelemetryClient, private log = createLogger('p2p:tx_pool')) {
|
|
27
|
+
constructor(telemetry: TelemetryClient = getTelemetryClient(), private log = createLogger('p2p:tx_pool')) {
|
|
28
28
|
this.txs = new Map<bigint, Tx>();
|
|
29
29
|
this.minedTxs = new Map();
|
|
30
30
|
this.pendingTxs = new Set();
|
|
@@ -100,6 +100,10 @@ export class InMemoryTxPool implements TxPool {
|
|
|
100
100
|
return result === undefined ? undefined : Tx.clone(result);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
public getArchivedTxByHash(): Tx | undefined {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
103
107
|
/**
|
|
104
108
|
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
105
109
|
* @param txs - An array of txs to be added to the pool.
|
|
@@ -17,6 +17,13 @@ export interface TxPool {
|
|
|
17
17
|
*/
|
|
18
18
|
getTxByHash(txHash: TxHash): Tx | undefined;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Checks if an archived transaction exists in the pool and returns it.
|
|
22
|
+
* @param txHash - The hash of the transaction, used as an ID.
|
|
23
|
+
* @returns The transaction, if found, 'undefined' otherwise.
|
|
24
|
+
*/
|
|
25
|
+
getArchivedTxByHash(txHash: TxHash): Tx | undefined;
|
|
26
|
+
|
|
20
27
|
/**
|
|
21
28
|
* Marks the set of txs as mined, as opposed to pending.
|
|
22
29
|
* @param txHashes - Hashes of the txs to flag as mined.
|
package/src/mocks/index.ts
CHANGED
|
@@ -8,8 +8,7 @@ import {
|
|
|
8
8
|
import { type EpochCache } from '@aztec/epoch-cache';
|
|
9
9
|
import { type DataStoreConfig } from '@aztec/kv-store/config';
|
|
10
10
|
import { openTmpStore } from '@aztec/kv-store/lmdb';
|
|
11
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
12
|
-
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
11
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
12
|
|
|
14
13
|
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
15
14
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
@@ -247,7 +246,7 @@ export function createBootstrapNodeConfig(privateKey: string, port: number): Boo
|
|
|
247
246
|
export function createBootstrapNodeFromPrivateKey(
|
|
248
247
|
privateKey: string,
|
|
249
248
|
port: number,
|
|
250
|
-
telemetry: TelemetryClient =
|
|
249
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
251
250
|
): Promise<BootstrapNode> {
|
|
252
251
|
const config = createBootstrapNodeConfig(privateKey, port);
|
|
253
252
|
return startBootstrapNode(config, telemetry);
|
|
@@ -255,7 +254,7 @@ export function createBootstrapNodeFromPrivateKey(
|
|
|
255
254
|
|
|
256
255
|
export async function createBootstrapNode(
|
|
257
256
|
port: number,
|
|
258
|
-
telemetry: TelemetryClient =
|
|
257
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
259
258
|
): Promise<BootstrapNode> {
|
|
260
259
|
const peerId = await createSecp256k1PeerId();
|
|
261
260
|
const config = createBootstrapNodeConfig(Buffer.from(peerId.privateKey!).toString('hex'), port);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { sleep } from '@aztec/foundation/sleep';
|
|
3
|
-
import { OtelMetricsAdapter, type TelemetryClient } from '@aztec/telemetry-client';
|
|
3
|
+
import { OtelMetricsAdapter, type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
5
|
import { Discv5, type Discv5EventEmitter } from '@chainsafe/discv5';
|
|
6
6
|
import { ENR, SignableENR } from '@chainsafe/enr';
|
|
@@ -38,7 +38,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
38
38
|
constructor(
|
|
39
39
|
private peerId: PeerId,
|
|
40
40
|
config: P2PConfig,
|
|
41
|
-
telemetry: TelemetryClient,
|
|
41
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
42
42
|
private logger = createLogger('p2p:discv5_service'),
|
|
43
43
|
) {
|
|
44
44
|
super();
|